Skip to content

Instantly share code, notes, and snippets.

@noonat
noonat / cube.go
Created September 15, 2015 14:24
package main
import (
"fmt"
"math"
"github.com/go-gl/mathgl/mgl32"
"github.com/gopherjs/gopherjs/js"
"github.com/gopherjs/webgl"
)
#import <UIKit/UIKit.h>
namespace PhuceContext {
// state (4.8.11.1.1)
bool save();
bool restore();
// transformations (4.8.11.1.2)
@noonat
noonat / build.patch
Created June 3, 2010 17:24
SpiderMonkey on iPhone
--- 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@
@noonat
noonat / jquery.replaceClasses.js
Created May 12, 2010 18:49
jQuery replace classes
// 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 / events.js
Created April 16, 2010 05:27
Rhino event loop
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 / build-rhino.sh
Created April 7, 2010 17:57
Checkout and build Rhino
#!/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 / jspec.junit.js
Created November 14, 2009 18:45 — forked from tj/jspec.junit.js
JUnit XML output for JSpec
/*
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 / rhino_ast.rb
Created November 14, 2009 18:30
Parse a JS file using JRuby and Rhino and print the AST
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

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:

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;
}