Skip to content

Instantly share code, notes, and snippets.

@nikmartin
nikmartin / A: Secure Sessions Howto
Last active April 28, 2024 05:17
Secure sessions with Node.js, Express.js, and NginX as an SSL Proxy
Secure sessions are easy, but not very well documented.
Here's a recipe for secure sessions in Node.js when NginX is used as an SSL proxy:
The desired configuration for using NginX as an SSL proxy is to offload SSL processing
and to put a hardened web server in front of your Node.js application, like:
[NODE.JS APP] <- HTTP -> [NginX] <- HTTPS -> [PUBLIC INTERNET] <-> [CLIENT]
Edit for express 4.X and >: Express no longer uses Connect as its middleware framework, it implements its own now.
@mheadd
mheadd / monitor.sh
Created May 13, 2013 20:00
Simple bash script to check whether MySQL is running.
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
echo "MySQL is down.";
sudo service mysql start
else
echo "All is well.";
fi
@robertklep
robertklep / app.js
Created April 3, 2013 12:36
Express vhosting
var express = require('express');
var app = express();
var app2 = express();
app.use(express.vhost('app1.example.com', require('./app1').app));
app.use(express.vhost('app2.example.com', app2));
app2.get('/', function(req, res) {
res.send('app 2');
@mbemowski
mbemowski / ngGrid.js
Created September 17, 2012 13:49 — forked from dalcib/ngGrid.js
Angular Grid
/**
* Grid directive for angularJS, based on dalcib's Angular Grid https://gist.github.com/2630138
* It's events are more angular-style and it operates on special object NavigationVector. It allows
* to select a row and to add custom rows at the bottom (for example to notify, that there are no rows found)
* When creating NavigationVector object you should pass the scope in which it will be declared in order
* to properly bind $watch expressions. Thanks to this you will be able to update index, selected or even
* items properties and other properties will be updated to match the change you made.
*
* Example:
<table ng-grid="" width="100%">
@ekoneil
ekoneil / gist:3178821
Created July 25, 2012 21:30
Calling Facebook APIs with the 3.0 SDK
// #1: Graph API: /me
- (void)requestMe {
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *me,
NSError *error) {
if(error) {
[self printError:@"Error requesting /me" error:error];
return;
}
@musubu
musubu / gist:2202583
Created March 26, 2012 03:01
escape and unescape in node.js
var querystring = require('querystring');
var original = 'http://example.com/product/abcde.html';
var escaped = querystring.escape(original);
console.log(escaped);
// http%3A%2F%2Fexample.com%2Fproduct%2Fabcde.html
var unescaped = querystring.unescape(escaped);
console.log(unescaped);
@tamitutor
tamitutor / Helper code
Created January 17, 2012 22:33
Handlebars Date Helper - ASP.NET Date to JavaScript Date
var offset = new Date().getTimezoneOffset() * 60 * 1000;
function parseAspNetUTCDateToJSDate(jsonDate) {
var parsedDate = new Date(parseInt(jsonDate.substr(6)) + offset);
return parsedDate;
}
Handlebars.registerHelper('date', function (date, block) {
return parseAspNetUTCDateToJSDate(date).toDateString(); //Return a shortened version of the date
});
@NicolasZanotti
NicolasZanotti / main.js
Created January 10, 2012 16:41
Render HTML content to a PDF file with wkhtmltopdf and Node.js
var http = require('http');
var sys = require('sys');
var exec = require('child_process').exec;
var util = require('util');
var fs = require('fs');
http.createServer(function(request, response) {
var dummyContent = '<!doctype html><html><head><title>Test</title><meta charset="utf-8"></head><body><p>Hello world!</p></body></html>';
var htmlFileName = "page.html", pdfFileName = "page.pdf";
@renajohn
renajohn / dateFormatter.js
Created October 26, 2011 07:11
Handlebar date formatter helper
/**
* Date formatting helper.
*
* Date helper takes a SC.DateTime and return a formatted string based on the format
* parameter. If no format is given, it uses %c as default.
*
* @param format a format string
*/
Handlebars.registerHelper('date', function(path, block) {
if (path) {
@shazron
shazron / sim-run.sh
Created October 25, 2011 21:53
Run Xcode Simulator project from the command line
#!/bin/bash
#
# Build and iPhone Simulator Helper Script
# Shazron Abdullah 2011
#
# WARN: - if your .xcodeproj name is not the same as your .app name,
# this won't work without modifications
# - you must run this script in where your .xcodeproj file is
PROJECTNAME=$1