Skip to content

Instantly share code, notes, and snippets.

@tilgovi
tilgovi / case.js
Created December 2, 2011 03:12 — forked from jhs/case.js
A better case statement?
// Prettier case statement, but can also return a value since it is an expression.
//
first_condition
? first_action()
: second_condition
? second_action()
: third_condition && can && (be || compound)
? (
can(),
@tilgovi
tilgovi / gist:1342375
Created November 6, 2011 02:30
Function building with templates and overloading
#include <iostream>
template <typename Ret, typename Arg>
class Prod {
private:
Ret (*left)(Arg);
Ret (*right)(Arg);
public:
Prod(Ret (*l)(Arg), Ret (*r)(Arg)) {
this->left = l;
@tilgovi
tilgovi / gist:1227319
Created September 19, 2011 19:20
Node.js call/cc function with fibers
/* This is the call-with-current-continuation found in Scheme and other
* Lisps. It captures the current call context and passes a callback to
* resume it as an argument to the function. Here, I've modified it to fit
* JavaScript and node.js paradigms by making it a method on Function
* objects and using function (err, result) style callbacks.
*/
Function.prototype.callcc = function(context /* args... */) {
var that = this,
caller = Fiber.current,
fiber = Fiber(function () {
chunkify(InList, BaseChunkSize) ->
%%io:format("length of list is ~p and chunk size is ~p ~n",[length(InList),BaseChunkSize]),
case byte_size(term_to_binary(InList)) of
Size when Size > BaseChunkSize ->
NumberOfChunksLikely = ((Size div BaseChunkSize) + 1),
ChunkThreshold = Size div NumberOfChunksLikely,
chunkify(InList, ChunkThreshold, [], 0, []);
_Else ->
[InList]
end.
@tilgovi
tilgovi / gist:990451
Created May 25, 2011 06:22
Senators with Twitter Handles
[["R", "TN", "Lamar Alexander", "SenAlexander"], ["R", "NH", "Kelly Ayotte", "SenatorAyotte"], ["R", "WY", "John Barrasso", "SenJohnBarrasso"], ["D", "AK", "Mark Begich", "SenatorBegich"], ["R", "MO", "Roy Blunt", "RoyBlunt"], ["R", "AR", "John Boozman", "JohnBoozman"], ["D", "CA", "Barbara Boxer", "SenatorBoxer"], ["D", "OH", "Sherrod Brown", "SenSherrodBrown"], ["R", "NC", "Richard Burr", "SenatorBurr"], ["D", "WA", "Maria Cantwell", "US_Sen_Cantwell"], ["R", "IN", "Daniel Coats", "SenDanCoats"], ["R", "TN", "Bob Corker", "SenBobCorker"], ["R", "TX", "John Cornyn", "JohnCornyn"], ["R", "SC", "Jim DeMint", "JimDeMint"], ["R", "SC", "Lindsey Graham", "GrahamBlog"], ["R", "NV", "Dean Heller", "DeanHeller"], ["R", "NE", "Mike Johanns", "Mike_Johanns"], ["R", "WI", "Ron Johnson", "SenRonJohnson"], ["D", "SD", "Tim Johnson", "SenJohnsonSD"], ["R", "IL", "Mark Kirk", "markkirk"], ["R", "AZ", "Jon Kyl", "SenJonKyl"], ["R", "AZ", "John McCain", "SenJohnMcCain"], ["D", "MO", "Claire McCaskill", "clairecmc"], ["D", "N
@tilgovi
tilgovi / gist:990375
Created May 25, 2011 05:02
Congress People Twitter Handles
[["D", "CO", "Mark Udall", "MarkUdall"], ["R", "NM", "Stevan Pearce", "RepStevePearce"], ["R", "KY", "Rand Paul", "SenRandPaul"], ["R", "OH", "Jim Renacci", "RepJimRenacci"], ["R", "VA", "Scott Rigell", "RepScottRigell"], ["R", "FL", "David Rivera", "RepRivera"], ["R", "FL", "Dennis Ross", "RepDennisRoss"], ["R", "PA", "Joseph Pitts", "RepJoePitts"], ["R", "TX", "Ronald Paul", "RepRonPaul"], ["R", "IN", "Mike Pence", "RepMikePence"], ["R", "KS", "Pat Roberts", "SenPatRoberts"], ["R", "FL", "Ileana Ros-Lehtinen", "RosLehtinen"], ["R", "CA", "Edward Royce", "RepEdRoyce"], ["R", "NY", "Thomas Reed", "TomReedCongress"], ["R", "AL", "Martha Roby", "MarthaRoby"], ["R", "IN", "Todd Rokita", "ToddRokita"], ["D", "NH", "Jeanne Shaheen", "JeanneShaheen"], ["R", "AZ", "David Schweikert", "RepDavid"], ["R", "CO", "Scott Tipton", "RepTipton"], ["D", "NY", "Gary Ackerman", "RepGaryAckerman"], ["R", "AL", "Robert Aderholt", "Robert_Aderholt"], ["R", "MO", "W. Todd Akin", "ToddAkin"], ["R", "TN", "Lamar Alexander", "SenAlexa
@tilgovi
tilgovi / gist:978159
Created May 18, 2011 07:48
deterministic revs for IDBCouch
diff --git a/couch.js b/couch.js
index 26fb69e..21a6e82 100644
--- a/couch.js
+++ b/couch.js
@@ -97,6 +97,198 @@ Dual licensed under the MIT and GPL licenses.
// END Math.uuid.js
+/**
+*
@tilgovi
tilgovi / gist:969619
Created May 12, 2011 22:38
gunicorn logging reload on USR1
diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py
index 6062117..a681420 100644
--- a/gunicorn/app/base.py
+++ b/gunicorn/app/base.py
@@ -38,6 +38,7 @@ class Application(object):
self.callable = None
self.logger = None
self.do_load_config()
+ self.__handlers = None
@tilgovi
tilgovi / couchdb-custom-header-attachments.txt
Created May 7, 2011 00:57 — forked from max-mapper/couchdb-custom-header-attachments.txt
spec for specifying custom headers on attachments in couchdb
INLINE ATTACHMENT
{
_attachments: {
"awesome.jpeg": {
content_type: "image/jpeg",
data: "base64 data goes here",
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
@tilgovi
tilgovi / gist:841902
Created February 24, 2011 07:59
v8 Array.isArray()
> Array.isArray(Object.create(Array.prototype)) != Array.isArray(new Array())
true