Skip to content

Instantly share code, notes, and snippets.

View muthuspark's full-sized avatar

Muthukrishnan muthuspark

View GitHub Profile
@muthuspark
muthuspark / gist:a2be62f9c1ee63202bd708a9ccbb383f
Last active July 25, 2017 05:35
Using node.js as a simple web server
Install connect and serve-static with NPM
$ npm install connect serve-static
Create server.js file with this content:
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(8080, function(){
console.log('Server running on 8080...');
@muthuspark
muthuspark / restify
Last active March 23, 2017 10:49
Basic Rest using Restify
var restify = require('restify');
var server = restify.createServer();
server.use(restify.bodyParser());
function corsHandler(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'Origin, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Response-Time, X-PINGOTHER, X-CSRF-Token,Authorization');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Expose-Headers', 'X-Api-Version, X-Request-Id, X-Response-Time');
if (window.location.search) {
var qs = window.location.search.split('+').join(' ');
var params = {},
tokens,
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
@muthuspark
muthuspark / flask-upload
Created January 21, 2017 11:10 — forked from dAnjou/flask-upload
Flask upload example
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess www user=max group=max threads=5
WSGIScriptAlias / /home/max/Projekte/flask-upload/flask-upload.wsgi
<Directory /home/max/Projekte/flask-upload>
WSGIProcessGroup www
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
@muthuspark
muthuspark / find-best-time-to-leave-office
Created January 3, 2017 02:20
To Find the best time to leave my office. The coordinates are the routes from my office to home. The code runs and collects time to reach at regular intervals of 7 mins and stores. I will analyze the data later
var request = require('request');
var schedule = require('node-schedule');
var firebase = require('firebase');
var app = firebase.initializeApp({
apiKey: "AIzaSyB1mr1VzndsFlKzNLHLlVtMKmOTXaUAM94",
authDomain: "squirreltask.firebaseapp.com",
databaseURL: "https://squirreltask.firebaseio.com",
storageBucket: "squirreltask.appspot.com",
messagingSenderId: "302372771732"
});
@muthuspark
muthuspark / gist:dde82808871897df5b2319546fb8d0f5
Created December 2, 2016 07:39
Install specific version of nodejs in ubuntu
sudo apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash -
sudo apt-get install nodejs
@muthuspark
muthuspark / gist:444c5f16c8b7c8da20913ca93b64161c
Created November 23, 2016 07:21
Copy files from remote machine to local using SCP
scp -i admin.pem admins@10.0.1.192:/opt/dbbackup/11_22_2016_11_10_53_alldbs_..tar.gz /opt/
@muthuspark
muthuspark / gist:1715243ddb4eb56d6e0730ddebf304a5
Created November 23, 2016 05:16
API Response Caching System
/**
* API Response Caching System
* This module creates a global variable called 'apicache' and makes it available throughout.
*/
(function() {
/**
*
* Variables to store our XMLHttpRequest object methods
*/
@muthuspark
muthuspark / gist:60dba6afba5f6cefd8a8bc9417179028
Created November 23, 2016 05:15
Content Editable using only DIV directive
function ContentEditable() {
String.prototype.sanitizeHTML = function(white, black) {
if (!white) white = "b|i|p|br|div"; //allowed tags
if (!black) black = "script|object|embed"; //complete remove tags
var e = new RegExp("(<(" + black + ")[^>]*>.*</\\2>|(?!<[/]?(" + white + ")(\\s[^<]*>|[/]>|>))<[^<>]*>|(?!<[^<>\\s]+)\\s[^</>]+(?=[/>]))", "gi");
return this.replace(e, "");
}
return {
<div style="padding:0;width:100%!important;margin:0" marginheight="0" marginwidth="0">
<center>
<table cellpadding="8" cellspacing="0" style="padding:0;width:100%!important;background:#ffffff;margin:0;background-color:#ffffff" border="0">
<tbody>
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0" style="border-radius:4px;border:1px #dceaf5 solid" border="0" align="center">
<tbody>
<tr>
<td colspan="3" height="6"></td>