This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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%"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #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; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |