Skip to content

Instantly share code, notes, and snippets.

@ligfx
ligfx / gist:1366208
Created November 15, 2011 05:05 — forked from miyagawa/gist:1227494
monkeypatch socket.io to work with nginx with buffering on (e.g. dotcloud)
var monkeypatch = function(io) {
io.configure(function(){
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
io.handleRequest = _.wrap(io.handleRequest, function(next, req, res) {
res.writeHead = _.wrap(res.writeHead, function(next, status, headers) {
if (headers) { delete headers.Connection; }
return next.call(this, status, headers);
});
@ligfx
ligfx / gist:1591733
Created January 10, 2012 22:58
Jison EBNF->BNF JSON translater
var EBNF = (function(){
var grammar = {
"lex": {
"rules": [
["\\s+", "/* skip whitespace */"],
["[A-Za-z_]+", "return 'symbol';"],
["'[^']*'", "return 'symbol';"],
["\\\\.", "return 'symbol';"],
["bar", "return 'bar';"],
["\\(", "return '(';"],
@ligfx
ligfx / _hidden.html.erb
Created February 15, 2012 03:58
Espresso
<% filter.opts.each do |(k, v)| %>
<input type="hidden" name="<%= k %>" value="<%= v %>" />
<% end %>
{
"data": {
"filename" : filename, // String. File name to upload
"md5" : md5, // String. MD5 hash of the file
"size" : size, // Integer. File size in KB
"path" : identifier // String. Custom identifier (if needed)
}
}
{
"meta": {
"version": 2,
"code": 200
},
"data": {
"id": "4fbaf4a21f92e4448c000003",
"source_url": "http://chute.com:8000/media/6onqswj",
"upload_info": {
"signature" : "AWS AKIAJHAREFXBAH6SBLPA:LC7MOI4gIdTs7uH2o0alJRiYdvg=",
{
"data": "http://avatars.io/4fb6de143d242d44da000001/haha"
}
Vagrant::Config.run do |config|
config.vm.box = "precise64"
end
@ligfx
ligfx / EXAMPLE
Created August 8, 2012 06:16
VirtualBox multi-attach
>>> time ( up vm1; up vm2; )
Virtual machine 'vm1' is created and registered.
UUID: 66e775d6-8c91-4cf1-8c20-742687f22399
Settings file: '/Users/michaelmaltese/VirtualBox VMs/vm1/vm1.vbox'
Waiting for VM "vm1" to power on...
VM "vm1" has been successfully started.
Virtual machine 'vm2' is created and registered.
UUID: 8e073076-94ef-42b4-b64f-56f1ac836d6c
Settings file: '/Users/michaelmaltese/VirtualBox VMs/vm2/vm2.vbox'
Waiting for VM "vm2" to power on...
@ligfx
ligfx / gist:6236474
Last active December 21, 2015 02:39
OLS map-reduce w/ multiprocessing
import multiprocessing as mp
import numpy as np
import Queue as queue
class NullQueue:
def put(self, *args): pass
def get(self, *args): raise queue.Empty
def empty(self): return True
def mapper_factory(Func):
# LDAP Auth
# coding=utf-8
# pip install python-ldap
import ldap
from sys import stdin, stdout
stdout.write("Username: ")
USERNAME = stdin.readline().strip()