Skip to content

Instantly share code, notes, and snippets.

View jmgunn87's full-sized avatar

James Marshall-Gunn jmgunn87

View GitHub Profile
@jmgunn87
jmgunn87 / gist:2720240
Created May 17, 2012 17:06
replace array_key_exists with isset
echo "array_key_exists(\"key\", \$array)" | sed 's/array_key_exists\s*(\s*\(["].*["]\)\s*,\s*\($[A-Za-z].*\)\s*)/isset(\2[\1])/'
<?php
/**
* simple ab tester
* @author James Marshall-Gunn <[email protected]>
*/
/**
*
* Parse the basic colon delimited stuff here.
* All results in milliseconds.
@jmgunn87
jmgunn87 / gist:2775347
Created May 23, 2012 13:53
nginx + php-fpm. apache killer
sudo -s
nginx=stable
add-apt-repository ppa:nginx/$nginx
apt-get update
apt-get install nginx
sudo apt-get install php5 php5-dev php5-suhosin
sudo apt-get install php-pear php5-cgi php5-cli php5-curl
sudo apt-get install php5-gd php5-imagick php5-mcrypt
sudo apt-get install php5-fpm php-apc php5-memcache php5-mysql
sudo service php5-fpm start
@jmgunn87
jmgunn87 / gist:2788946
Created May 25, 2012 16:02
npm install mongoose director
var http = require('http');
var url = require('url');
var director = require('director');
var router = new director.http.Router();
var db = require('mongoose');
db.connect('mongodb://localhost/ecomm_database');
router.get('/:eventId', function (eventId){
this.res.end(eventId);
});
@jmgunn87
jmgunn87 / gist:2821919
Created May 29, 2012 00:44
sbcl compile
(sb-ext:save-lisp-and-die "my_binary" :executable t :toplevel 'main-program-function)
/* lisp.c: high-speed LISP interpreter */
/*
The storage required by this interpreter is 8 * 4 = 32 bytes times
the symbolic constant SIZE, which is 32 * 1,000,000 =
32 megabytes. To run this interpreter in small machines,
reduce the #define SIZE 1000000 below.
To compile, type
cc -O -olisp lisp.c
@jmgunn87
jmgunn87 / gist:2836080
Created May 30, 2012 12:48
shopping list
lisp,
xml,
json,
curl,
sha256,
gzip,
0mq,
neural networks,
decision tree,
sqlite
>>>>>>> php
urlencode ($html);
>>>>>>> javascript
document.write (unescape (''))
@jmgunn87
jmgunn87 / tmpl.js
Created August 16, 2012 21:57
logicless templating
function renderTemplate (template, args) {
return template.replace (/({{[^{}]*}})/g,
function (match) {
return args [match.substr(2, match.length-4)];
});
}
renderTemplate('<h1>{{name}}:{{total_coins}}</h1>', {
fbid: '3g23403j4999',
name: 'barry',
total_coins: 500
@jmgunn87
jmgunn87 / memento.js
Created August 26, 2012 15:57
js memento(undo redo)
function Memento(originalState) {
this.state = originalState;
this.stack = new Array(this.state);
this.stackIndex = 0;
}
Memento.prototype.undo = function () {
return this.stackIndex > 0 ?
this.state = this.stack[--this.stackIndex]: this.state;
};
Memento.prototype.save = function (state) {