Skip to content

Instantly share code, notes, and snippets.

View manjeshpv's full-sized avatar
🇮🇳
in India

Manjesh V manjeshpv

🇮🇳
in India
  • LEADSchool.in
  • Bangalore
View GitHub Profile
@manjeshpv
manjeshpv / passport.js
Last active February 29, 2024 15:11
Passport.js using MySQL for Authentication with Express
// config/passport.js
// load all the things we need
var LocalStrategy = require('passport-local').Strategy;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
@manjeshpv
manjeshpv / Phonegap Cordova File Upload and Download
Last active August 29, 2015 14:03
Phonegap Cordova File Upload and Download
<!DOCTYPE html>
<html>
<!-- phonegap plugin add org.apache.cordova.camera
phonegap plugin add org.apache.cordova.file-transfer
Copy JS Files from
-->
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
@manjeshpv
manjeshpv / HTML5 SQLite getting column names, Promises
Last active August 29, 2015 14:05
HTML5 SQLite getting column names, Promises
// jQuery Required
// Creating / Opening DB
var db = window.openDatabase("techm", "1.0", "TechM Employees", 100000)
function createTable(table, fields,cb) {
db.transaction(function (tx) {
tx.executeSql('create table ' + table + fields, [], function () {
return cb("Table Created : " + table)
}, function () {
return cb("SQL Error")
@manjeshpv
manjeshpv / PHP: Apple APNS Push Notification for IOS Phonegap
Last active August 29, 2015 14:06
PHP: Apple APNS Push Notification for IOS Phonegap
<?php
// To Generate PEM file follow : http://stackoverflow.com/questions/21250510/generate-pem-file-used-to-setup-apple-push-notification
$deviceToken = '29954cd9ace7a7c29f66918e62e8a18522619c5cabae08972da6cd4273fe874c';
$passphrase = 'apns';
$message = 'test';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
@manjeshpv
manjeshpv / Soap Request AJAX jQuery.js
Last active November 1, 2023 11:53
Soap Request AJAX jQuery
var soapAction = " http://server.test.nam/RequestHandler/reverseYourName "
var soapRequestBody = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.test.nam"> <soapenv:Header/> <soapenv:Body> <ser:reverseYourName> <ser:name>test</ser:name> </ser:reverseYourName> </soapenv:Body> </soapenv:Envelope>'
$.ajax({
url: "http://10.23.249.55:8282/WebServiceForServer/services/RequestHandler",
type: "POST",
data: soapRequestBody,
beforeSend: function(xhr) {
xhr.setRequestHeader("SOAPAction", soapAction)
},
@manjeshpv
manjeshpv / webSQL Demo.js
Last active August 29, 2015 14:07
webSQL Demo
db = window.openDatabase("Demo", "1.0", "BusinessApp", 200000);
insertIndex = 0;
var insertCounter = 0;
insertBatch = function(array, arrayLength, tableName, fieldQuestions, cb) {
console.log("Inserting Record :" + insertCounter);
if (insertIndex < arrayLength) {
db.transaction(function(tx) {
var sql = 'INSERT OR IGNORE INTO ' + tableName + ' VALUES ' + fieldQuestions;
console.log("sql: " + sql);
@manjeshpv
manjeshpv / WebSQL Multiple Insertion.js
Last active August 29, 2015 14:07
WebSQL Multiple Insertion
// Multiples INSERTs : 2500ms
// Using BEGIN and COMMIT : 90ms
// Using SELECT and UNION : 40ms
var newQuery = true, query = '';
for (i=0; i<locations_length; i++) {
if (newQuery) {
query = 'INSERT INTO myTable (id, name, code)';
newQuery = false;
}
@manjeshpv
manjeshpv / Apple Push Notification APNS PHP Snippet.php
Last active May 24, 2023 22:56
Apple Push Notification APNS PHP Snippet - Server Side Implementation
<?php
$deviceToken = '6e1326c0e4758b54332fab3b3cb2f9ed92e2cd332e9ba8182f49027054b64d29'; // iPad 5s Gold prod
$passphrase = '';
$message = 'Hello Push Notification';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert.pem'); // Pem file to generated // openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts // .p12 private key generated from Apple Developer Account
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); // production
// $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); // developement
@manjeshpv
manjeshpv / Linear Equation.js
Created October 22, 2014 06:51
Solve Linear Equation
function evaluate(x) {
xp = x.split(";")
console.log(xp)
xp.forEach(function (item, index) {
console.log(index)
if (index != 0) {
eval(item)
}
if (index == (xp.length - 1)) {
var ss = (("(" + xp[0]).replace(/(\+|-)/g, ")+(") + ")").replace(/([0-9]+)([a-z]{1})/g, "$1*$2")
@manjeshpv
manjeshpv / post-receive
Last active August 29, 2015 14:10
Git Production Automation
#!/bin/bash
echo "Starting copy from repository to work tree..."
git --work-tree=/d/push-to-deploy/production checkout -f master
echo "Finished."
exit 0