Skip to content

Instantly share code, notes, and snippets.

View saranrapjs's full-sized avatar

Jeff Sisson saranrapjs

View GitHub Profile
@mattd
mattd / gist:1006398
Created June 3, 2011 14:12
nginx try_files with a proxy_pass
server {
root /var/www/example.com/static;
server_name example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
try_files /maintenance.html @proxy;
location @proxy {
proxy_pass http://127.0.0.1:10001;
@ecentinela
ecentinela / imagick
Created October 19, 2011 18:14
install imagick on mamp 2 - lion
# install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
# install imagemagick
brew install imagemagick
# install imagick
brew install imagick
# if giving errors on the installation, comment the content on ~/.bash_profile or ~/.profile, open a new terminal and retry
@tcr
tcr / code.js
Created October 23, 2011 07:22
How can you make the Github API accept Unicode characters in JSON?
function JSON_stringify(s, emit_unicode)
{
var json = JSON.stringify(s);
return emit_unicode ? json : json.replace(/[\u007f-\uffff]/g,
function(c) {
return '\\u'+('0000'+c.charCodeAt(0).toString(16)).slice(-4);
}
);
}
@bradland
bradland / gencert.sh
Created January 27, 2012 20:39
Generate a self-signed SSL cert
#!/bin/bash
# Bash shell script for generating self-signed certs. Run this in a folder, as it
# generates a few files. Large portions of this script were taken from the
# following artcile:
#
# http://usrportage.de/archives/919-Batch-generating-SSL-certificates.html
#
# Additional alterations by: Brad Landers
# Date: 2012-01-27
@cuppster
cuppster / node-express-cors-middleware.js
Created April 9, 2012 16:02
express.js middleware to support CORS pre-flight requests
app.use(express.methodOverride());
// ## CORS middleware
//
// see: http://stackoverflow.com/questions/7067966/how-to-allow-cors-in-express-nodejs
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"

These instructions work for the Raspberry Pi running Raspbian (hard float) and create a hardware optimized version of NodeJS for the Raspberry PI, (and include a working install and NPM!!!):

  1. Install Raspbian - http://www.raspberrypi.org/downloads

  2. Install the necessary dependecies:

sudo apt-get install git-core build-essential

(If you just installed git then you need to administer your git identity first, else adding the patches below will fail!!!)

@fitnr
fitnr / apportion.py
Last active August 4, 2016 16:33
Apportionment algorithm for the US House of Representatives
# Uses method of least proportions to apportion House members among states.
# http://en.wikipedia.org/wiki/United_States_congressional_apportionment#The_Method_of_Equal_Proportions
# use like this:
# python apportion.py --built-in 2010
# python apportion.py --file file.csv --key <column name>
# python apportion.py --file file.csv --key <column name> --reps 444
# python apportion.py --file file.csv --key <column name> --distsize 500000
from __future__ import division, print_function
import sys
import csv
@constantology
constantology / __proto__.js
Last active October 14, 2015 01:28
An explanation of `__proto__` using an example and a `__proto__` "polyfill" for MSIE 9 & 10.
function Collection() {
this.push.apply( this, arguments );
}
Collection.prototype = [];
Collection.prototype.push = function( item ) { // we need to wrap this.push in a function or we'll get a recursion error from
if ( arguments.length > 1 ) { // the arguments.length always being > 1 since the Array index is passed to the iterator
this.slice.call( arguments ).map( function( val ) { this.push( val ); }, this );
return this.length;
@leifg
leifg / Vagrantfile
Last active November 12, 2023 08:31
Add a second disk to system using vagrant
file_to_disk = './tmp/large_disk.vdi'
Vagrant::Config.run do |config|
config.vm.box = 'base'
config.vm.customize ['createhd', '--filename', file_to_disk, '--size', 500 * 1024]
config.vm.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
end