Skip to content

Instantly share code, notes, and snippets.

Nathan Ostgard noonat

Block or report user

Report or block noonat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ruby-blocks.mkdn

Understanding Blocks in Ruby

This is a quick, visual explanation of how blocks work in Ruby.

Let's define a function foo that accepts an optional block callback, and calls it if it was passed:

def foo
  puts 'foo 1'
View greenlet_trace.py
import gevent
import greenlet
import logging
import time
import traceback
_last_switch_time = None
_min_elapsed_time = 0.1
def trace(event, (origin, target)):
View phantom-main.js.diff
diff --git a/phantom-main.js b/phantom-main.js
index 0b6d1a1..a6e2e0a 100644
--- a/phantom-main.js
+++ b/phantom-main.js
@@ -21,6 +21,8 @@ var options = JSON.parse(phantom.args[2] || {});
// Default options.
if (!options.timeout) { options.timeout = 5000; }
+if (!options.uploadDir) { options.uploadDir = fs.workingDirectory; }
+options.uploadDir = fs.absolute(options.uploadDir).replace(/[\/\\]*$/, '') + fs.separator;
View http.c
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "http.h"
int http_response_init(http_response_t * const response)
{
View concat-reduce-1.js
// really slow: ~50s
try {
return ret.concat.apply([], ret);
} catch (e) {
if (e instanceof RangeError && ret.reduce) {
return ret.reduce(function(a, b) {
return a.concat(b);
}, [])
} else {
throw e;
View get_subs.py
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
import requests
import sys
import zlib
from pythonopensubtitles import opensubtitles, utils
@noonat
noonat / level1.py
Created Jan 24, 2013
Some code to solve the Colossal Cue puzzles at http://adventure.cueup.com/
View level1.py
m = 4294967296
a = 69069
c = 1
seed = 6
for i in range(4):
seed = (a * seed + c) % m
print "%i" % (seed % 36)
View sha1.js
window.sha1 = (function() {
/*
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
* in FIPS 180-1
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for details.
*/
View gzip_postfix_man_files.sh
FILES=$(echo "man1/mailq.1
man1/newaliases.1
man1/postalias.1.gz
man1/postcat.1.gz
man1/postconf.1.gz
man1/postdrop.1.gz
man1/postfix.1.gz
man1/postkick.1.gz
man1/postlock.1.gz
man1/postlog.1.gz
View powerset.coffee
powerSet = (set) ->
p = [[]]
for val in set
for i in [0...p.length]
p[p.length] = p[i].concat([val])
p
You can’t perform that action at this time.