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
@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];
@noonat
noonat / machine.js
Created May 7, 2010
JavaScript state machine
View machine.js
// Javascript state machine. Allows you to specify a number of routes
// and set a target state, and it will call through the routes to
// get there.
function Machine(defaultState, routes) {
this.target = undefined;
this.transition = undefined;
this.routes = typeof routes === 'function' ? routes() : routes;
// Set the state last, so the route will be triggered.
@noonat
noonat / jquery.replaceClasses.js
Created May 12, 2010
jQuery replace classes
View jquery.replaceClasses.js
// Removes all classes beginning with prefix, and replaces them
// with a prefix+suffix class. For example:
// $('#blah').addClass('foobaz');
// $('#blah').replaceClasses('foo', 'baz');
jQuery.fn.replaceClasses = function(prefix, suffix) {
var re = new RegExp('^' + prefix);
return this.each(function() {
var classes = this.className.split(/\s+/);
var newClasses = [];
var i = classes.length;
@noonat
noonat / build.patch
Created Jun 3, 2010
SpiderMonkey on iPhone
View build.patch
--- config/autoconf.mk.in 2010-06-05 19:06:36.000000000 -0700
+++ config/autoconf.mk.in 2010-06-05 19:06:59.000000000 -0700
@@ -97,7 +97,6 @@
NS_TRACE_MALLOC = @NS_TRACE_MALLOC@
INCREMENTAL_LINKER = @INCREMENTAL_LINKER@
-MACOSX_DEPLOYMENT_TARGET = @MACOSX_DEPLOYMENT_TARGET@
BUILD_STATIC_LIBS = @BUILD_STATIC_LIBS@
ENABLE_TESTS = @ENABLE_TESTS@
View PhuceContext.h
#import <UIKit/UIKit.h>
namespace PhuceContext {
// state (4.8.11.1.1)
bool save();
bool restore();
// transformations (4.8.11.1.2)
View proxy_object.js
// ECMAScript 5 object proxy as JS
(function(exports) {
function getPropertyDescriptor(obj, propertyName) {
print("getPropertyDescriptor", obj, propertyName);
var desc = Object.getOwnPropertyDescriptor(obj, propertyName);
if (desc !== undefined) {
return desc;
} else {
View triangle.html
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="480" height="480"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.strokeStyle = '#fff';
context.fillStyle = '#000';
You can’t perform that action at this time.