Skip to content

Instantly share code, notes, and snippets.

View janewang's full-sized avatar

Jane Wang janewang

  • Washington, DC
View GitHub Profile
@janewang
janewang / gist:3422915
Created August 22, 2012 06:28
Bash - For close inspection
# @jehiah
# in place file regex replacement
perl -pi -e 's/this/that/g' filename_pattern
# print the last column of a file ($NF stands for 'Number of Fields' or more commonly Last Field).
tail -F access.log | awk '{print $NF}'
# auto re-tail when file is replaced (useful for daemontools/multilog)
tail -F file.log
@janewang
janewang / gist:3410267
Created August 21, 2012 01:20 — forked from alexclare/gist:3410169
Hacky IRCCloud ping script
import json, pycurl, subprocess
class ChatStream(object):
def __init__(self, sessid, handler):
self.handler = handler
self.buffer = ''
self.curl = pycurl.Curl()
self.curl.setopt(pycurl.URL, 'https://irccloud.com/chat/stream')
self.curl.setopt(pycurl.COOKIE, 'session=' + sessid)
self.curl.setopt(pycurl.WRITEFUNCTION, self.chunk)
@janewang
janewang / gist:3317595
Created August 10, 2012 20:27
Rebar Setup
mkdir testing_rebar
cd testing_rebar
rebar create-app
console output:
==> testing_rebar (create-app)
Writing src/myapp.app.src
Writing src/myapp_app.erl
Writing src/myapp_sup.erl
# src directory is created
@janewang
janewang / gist:3310559
Created August 10, 2012 02:49 — forked from nicholasbs/gist:3259846
Implementing the "new" operator in JavaScript
// New is a function that takes a function F
function New (F) {
var o = {}; // and creates a new object o
o.__proto__ = F.prototype // and sets o.__proto__ to be F's prototype
// New returns a function that...
return function () {
F.apply(o, arguments); // runs F with o as "this", passing along any arguments
return o; // and returns o, the new object we created
}
@janewang
janewang / gist:3308203
Created August 9, 2012 21:28 — forked from aphyr/gist:3200829
Node.js message passing test
var cluster = require('cluster');
var m = 10000000;
function bounce(msg, out) {
if (msg < m) {
out.send(msg + 1);
return null;
} else {
console.log("Finished with", msg);
@janewang
janewang / gist:3308201
Created August 9, 2012 21:28 — forked from aphyr/gist:3200862
Clojure message passing test
(ns messagepassing.core)
(import [java.util.concurrent LinkedTransferQueue])
(def m 10000000)
(defn queue-test []
(defn bounce [in out m]
(let [value (.take in)]
(if (< value m)
(do
@janewang
janewang / gist:3259869
Created August 4, 2012 20:55 — forked from arjans/gist:3259868
Recursive and Memoized Y-Combinator Fibonnaci Functions
// timer
// console.time('fib');
// console.timeEnd('fib');
//Recursive fibonnaci
var fib_recur = function (n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fib_recur(n-1) + fib_recur(n-2);
};
@janewang
janewang / gist:3259724
Created August 4, 2012 20:22
Read this later
http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/
http://matt.might.net/articles/js-church/
https://en.wikipedia.org/wiki/Fixed-point_combinator
http://www.cs.brown.edu/courses/cs173/2002/Lectures/2002-10-28-lc.pdf
http://www.dsi.uniroma1.it/~labella/absMcAdam.ps
http://www.cs.utexas.edu/users/wcook/Drafts/2009/sblp09-memo-mixins.pdf
@janewang
janewang / gist:3259652
Created August 4, 2012 20:07
Y Combinator (standard and recursive) vs. U Combinator vs. Typical Recursion
// Y combinator
var Y = function (f) {
return (
(function (x) {
return f(function (v) { return x(x)(v); }); })
(function (x) {
return f(function (v) { return x(x)(v); }); })
);
}
@janewang
janewang / gist:3258841
Created August 4, 2012 17:21
YCombinator List Inversion in Erlang
Eshell V5.9.1 (abort with ^G)
% The Y combinator allows recursion to be defined as a set of rewrite rules without requiring
% native recursion support in the language.
c(y_comb). % takes 2 params
{ok,y_comb}
(y_comb:y2(
fun (R) ->
fun