Skip to content

Instantly share code, notes, and snippets.

Justin McNally j-mcnally

Block or report user

Report or block j-mcnally

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@j-mcnally
j-mcnally / justinUtils.js
Created Aug 10, 2011
Node module with some useful utils i will ammend over time. Depends on underscore
View justinUtils.js
module.exports = function() {
var justin = {
removeKeys: function(keys, obj) {
var newObj = {};
for (var i = 0; i < _.keys(obj).length; i++) {
var key = _.keys(obj)[i];
if (_.keys(obj).indexOf(key) == -1) {
newObj[key] = obj[key];
}
@j-mcnally
j-mcnally / preflightApi.js
Created Aug 10, 2011
Express Middleware for CORS access.
View preflightApi.js
module.exports = function preflightApi(){
return function preflightApi(req, res, next){
//this is where the magic happens
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'User-Agent, Accept-Language, Accept-Encoding, Accept-Charset, Connection, Content-Length, Origin, Pragma, Accept-Charset, Cache-Control, Accept, Content-Type, Sessionid');
res.header('Access-Control-Max-Age', '1000');
@j-mcnally
j-mcnally / hooker.js
Created Aug 16, 2011
Beanstalk Deployment Hook Server
View hooker.js
var http = require('http');
var sys = require('sys')
var exec = require('child_process').exec;
http.createServer(function (req, res) {
var header=req.headers['authorization']||'', // get the header
token=header.split(/\s+/).pop()||'', // and the encoded auth token
auth=new Buffer(token, 'base64').toString(), // convert from base64
parts=auth.split(/:/), // split on colon
username=parts[0],
password=parts[1];
@j-mcnally
j-mcnally / Readme
Created Aug 17, 2011
Nginx for API and Webapp
View Readme
So you want to build a HTML Webapp and then query your JSON Api. To avoid cross domain calls use NGINX to proxy only certain requests to the API. In my case I use the Accept: header from the HTTP request to specify return data format. If that format is application/json send it to the api, otherwise try to serve the static html.
@j-mcnally
j-mcnally / pg.php
Created Aug 18, 2011
CodeIgniter Permalink Routing
View pg.php
<?php
//would be controllers/pg.php
class pg extends Controller {
var $pgItem;
var $parentPage;
function pg() {
//do some constructor related stuff here
}
function permalink($segments) {
@j-mcnally
j-mcnally / Readme
Created Aug 18, 2011
Express: Switch cookie sessions to a header session fore Node Apps built as APIs
View Readme
The two files attached are Express Middleware
Srvformat sets the format based on the accept header
to switch it to api mode.
ApiSession uses the req.format set by this to decide
which kinds of sessions to use.
@j-mcnally
j-mcnally / Express-resources.js
Created Aug 18, 2011
Express-resources with middleware
View Express-resources.js
/*!
* Express - Resource
* Copyright(c) 2010-2011 TJ Holowaychuk <tj@vision-media.ca>
* Copyright(c) 2011 Daniel Gasienica <daniel@gasienica.ch>
* MIT Licensed
*/
/**
* Module dependencies.
View gist:1163428
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.ajax("http://revolve.amazon/session/create", {
type: "POST",
dataType: "json",
processData: false,
headers: {
"Accept": "application/json",
@j-mcnally
j-mcnally / jsonForm.js
Created Oct 5, 2011
Expanded Serializer
View jsonForm.js
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
var oldName = this.name;
this.name = this.name.replace(/\[\]/g, '');
if (this.name.indexOf('[') >= 0) {
var innerName = this.name.match(/.*\[(.*)\]/)[1];
@j-mcnally
j-mcnally / stop.sh
Created Nov 9, 2011
Kill a proccess you don't know the pid of
View stop.sh
#!/bin/sh
pid=`ps aux | grep -i "/path/to/app/as/started" | grep -v "grep" | awk '{print $2}'`
kill $pid
You can’t perform that action at this time.