Tuesday, May 29, 2018

Read the data from server using Backbone js collection fetch data




<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Tag List</div>
<div id="tagTab">
<input type="text" name="name" id="name" />
<button id="addTag"> Add</button>
<ul id="tagList">
</ul>
</div>
<script type="text/template" id="tag-name-template">
<li>
<%= title %>
</li>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.0/underscore-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js"></script>
<script>
var app = {};
var tagModel = Backbone.Model.extend({
defaults: {
title: 'mak',
status: false
},
initialize: function() {
}
});
var tagCollection = Backbone.Collection.extend({
model: tagModel,
initialize: function() {
// console.log("collection added creation");
// this.fetch();
},
url: 'https://jsonplaceholder.typicode.com/posts',
parse: function(response) {
return response;
}
});
var tagNameView = Backbone.View.extend({
template: _.template($('#tag-name-template').html()),
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this;
// return this.template(this.mode);
}
});
var tagTabView = Backbone.View.extend({
el: $('#tagTab'),
model: new tagCollection(),
initialize: function() {
this.render();
this.model.on('add', this.render, this);
this.model.fetch();
},
render: function() {
this.$('#tagList').html(''); // clean the todo list
// console.log(this.model);
for (var i = 0; i < this.model.length; ++i) {
// console.log(this.model.at(i));
this.$('#tagList').append(new tagNameView({
model: this.model.at(i)
}).el);
}
},
events: {
'click #addTag': 'add'
},
//To add the item to collections
add: function() {
// this.model.add(new tagModel({title:$("#name").val()}));
this.model.add({
title: $("#name").val()
});
$("#name").val("");
}
});
app.view = new tagTabView();
</script>
</body>
</html>
view raw postList.html hosted with ❤ by GitHub



Linux-Shell Script to Move to specific folder using "cd" command




Shell scripts are run inside a subshell, and each subshell has its own concept of what the current directory is. The cd succeeds, but as soon as the subshell exits, you're back in the interactive shell and nothing ever changed there.

To Resolve that we use bash command. 




#!/bin/sh
#!/bin/bash

cd "/opt/azw/webapp/src/";
bash



Thursday, January 4, 2018

To pull specific directory with git


To pull specific folder from git repository or git repo

mkdir directoryName
cd directoryName
git init
git remote add origin -f <>
git config core.sparsecheckout true
echo / >> .git/info/sparse-checkout
git pull origin master




Monday, October 16, 2017

Python Cheat Sheet

Python Cheat Sheet





Friday, October 6, 2017

Connect to Microsoft SQL Server Using PHP

Connect to Microsoft SQL Server Using PHP


Below Code will connect to the Microsoft Sql Server using php script.

<?php
$serverName = "*****.*****.****.**";//Host Name
$uid = "mtcdb";//User Name
$pwd = "******";//Password
$databaseName = "Mobile_Dev";//Database Name
$connectionInfo = array("UID" => $uid,
"PWD" => $pwd,
"Database" => $databaseName);
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn )
{
echo "Connected";
}
else
{
echo "<pre>";
die( print_r( sqlsrv_errors(), true));
}
//var_dump($conn);exit;
$tsql = "SELECT * FROM users";
/* Execute the query. */
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt) {
echo "Statement executed.<br>\n";
} else {
echo "Error in statement execution.\n";
die(print_r(sqlsrv_errors(), true));
}
/* Iterate through the result set printing a row of data upon each iteration. */
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
// print_r($row);exit;
echo "Col1: " . $row[0] . "\n";
echo "Col2: " . $row[1] . "\n";
echo "Col3: " . $row[2] . "<br>\n";
echo "-----------------<br>\n";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
view raw mssqlserver.php hosted with ❤ by GitHub

Thursday, September 21, 2017

Authenticating with OAuth 2.0 For LinkedIn Api Access using PHP

Authenticating with OAuth 2.0 For LinkedIn Api Access using PHP


LinkedIn Oauth 2.0 PHP Access


Follow these steps to enable your application to make
authenticated API calls to LinkedIn using OAuth 2.0:


Step 1: Configuring your LinkedIn application.

Create application in linkedin Developers Panel Link.

After Clicking on Create App. Fill the form information.


Once you save your configuration, your application will be assigned a unique "Client ID"   and "Client Secret" value.


Step2: Using the below PHP code to get the LinkedIn access Token to access there apis


<?php
error_reporting(-1);
echo " testing";
/**
*
*The below is the url to get the Authorization code using our LinkedIn App Details
*/
$url="https://www.linkedin.com/".
'oauth/v2/authorization?response_type=code&client_id=81vfvatntv3k0&'
. 'redirect_uri=http://localhost/servers/link.php&state=DCEeFWf45A53sdfKef424';
$code=$_GET['code'];
if(isset($code)){
$myUrl = "https://www.linkedin.com/oauth/v2/accessToken";
$myData = array(
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => '********',//Redirect Url
'client_id'=>'CLINETId',//Linkedin App Client Id
'client_secret'=>'******'//Linkedin App Secret Key
);
$myHeaders = array(
'Content-type: application/x-www-form-urlencoded'
);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $myUrl);
curl_setopt($handle, CURLOPT_HTTPHEADER, $myHeaders);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_POST, true);
//curl_setopt($handle, CURLOPT_POSTFIELDS, $myData);
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($myData));
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
print "return code = $code <br/>";
print "response = <br/> $response <br/><br/>";
$myRespArr = json_decode($response, true);
print "<pre>";
print_r($myRespArr['access_token']);
print "</pre>";
exit;
}
?>
<html>
<head>
<title>Linkedin Api </title>
</head>
<body>
<a href="<?php echo $url?>">Click Link
</a>
</body>
</html>





Friday, September 8, 2017

Reading Excel Spreadsheets with Python

Excel & Python

Reading an Excel Spreadsheet

In this section, we will look at a function that demonstrates reads the Excel sheet data and convert that data into XML file.

We Used the following libraries to do the above functionality


  • Openpyxl : Openpyxl is a Python library for reading and writing Excel 2010 xlsx/xlsm/xltx/xltm files.
  • xml.etree.ElementTree: To create the xml tree elements
  • datetime: to conver the date time column values to specified format 
from openpyxl import load_workbook
import datetime
import xml.etree.cElementTree as ET
wb = load_workbook(filename = 'Sku Assignment 8.24 Furniture Content.xlsx')
sheet = wb.get_sheet_by_name('Output Sheet')#sheet name
root = ET.Element("skuProducts")
i=0
for rowOfCellObjects in sheet.rows:
doc = ET.SubElement(root, "skuProduct"+str(i))
j=0
for cellObj in rowOfCellObjects:
print(cellObj.coordinate, cellObj.value)
print type(cellObj.value)
datatype = type(cellObj.value)
if( datatype is unicode):
ET.SubElement(doc, cellObj.coordinate).text = cellObj.value
elif( datatype is long):
print int(cellObj.value)
ET.SubElement(doc, cellObj.coordinate).text = str(int(cellObj.value))
elif isinstance(cellObj.value, datetime.date):
#print cellObj.value.strftime('%m/%d/%Y')
#pass
ET.SubElement(doc, cellObj.coordinate).text = str(cellObj.value.strftime('%m/%d/%Y'))
else:
print "pass"
pass
j=j+1
i=i+1
print('--- END OF ROW ---')
tree = ET.ElementTree(root)
tree.write("filename.xml")
view raw convert.py hosted with ❤ by GitHub