Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Ostgard noonat

View GitHub Profile
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 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 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 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 ruby-accessors.mkdn

Understanding Accessor Methods in Ruby

Accessing properties of an object in Ruby are a bit different than they are in JavaScript. In JavaScript, if you defined an object constructor like so:

function Foo() {
  this.x = 1;
  this.y = 2;
}
View keybase.md

Keybase proof

I hereby claim:

  • I am noonat on github.
  • I am noonat (https://keybase.io/noonat) on keybase.
  • I have a public key whose fingerprint is 280C D0D7 B06E ACF3 FD86 058A 0905 62AD 94AC 5A83

To claim this, I am signing this object:

@noonat
noonat / rhino_ast.rb
Created Nov 14, 2009
Parse a JS file using JRuby and Rhino and print the AST
View rhino_ast.rb
require 'js-1_7r3.jar'
import Java::OrgMozillaJavascript::Context
import Java::OrgMozillaJavascript::CompilerEnvirons
import Java::OrgMozillaJavascript::Parser
import Java::OrgMozillaJavascript::Token
class Visitor
include Java::OrgMozillaJavascriptAst::NodeVisitor
@noonat
noonat / jspec.junit.js
Created Nov 14, 2009 — forked from tj/jspec.junit.js
JUnit XML output for JSpec
View jspec.junit.js
/*
Output:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="core.events" tests="2" assertions="2" failures="0" specs="2">
<testcase name="should be an instance of QueuedEventPool" assertions="1"/>
<testcase name="should have the correct name" assertions="1"/>
</testsuite>
...
</testsuites>
@noonat
noonat / build-rhino.sh
Created Apr 7, 2010
Checkout and build Rhino
View build-rhino.sh
#!/bin/bash
# I hope I never have to remember how to do this ever again
MOZILLA_CVS=':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'
RHINO_PATH='mozilla/js/rhino'
if ! [ -d mozilla ]; then
cvs -d $MOZILLA_CVS co $RHINO_PATH
else
@noonat
noonat / events.js
Created Apr 16, 2010
Rhino event loop
View events.js
function EventEmitter() {
this._listeners = {};
}
exports.EventEmitter = EventEmitter;
EventEmitter.prototype.listeners = function(event) {
if (!this._listeners[event]) {
this._listeners[event] = [];
}
return this._listeners[event];