Skip to content

Instantly share code, notes, and snippets.

View m0wfo's full-sized avatar

Chris Mowforth m0wfo

  • Planet Earth
View GitHub Profile
alias serve="ruby -rwebrick -e\"s = WEBrick::HTTPServer.new(:Port => 8080, :DocumentRoot => Dir.pwd); trap('INT') {\
s.shutdown }; s.start\""
@m0wfo
m0wfo / gist:4511963
Created January 11, 2013 16:23
My emacs init.el
(require 'package)
(add-to-list 'package-archives
'("elpa" . "http://tromey.com/elpa/"))
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
@m0wfo
m0wfo / server.js
Created December 19, 2012 22:43
Simple reactor + echo server.
/*
A simple reactor built on Java's channels, using JavaScript
to cut down on syntactic noise.
From the command line, just run: sprintstack server.js
To connect, use something like: nc localhost 8080
This is purely for illustrative purposes: it does no error checking,
has inefficient bytebuffer / string / collection manipulation and many
other naughty things in the name of simplicity.
#include <dispatch/dispatch.h>
#include <stdio.h>
int main() {
dispatch_queue_t queue = dispatch_queue_create(NULL, NULL);
dispatch_async(queue, ^{
printf("Hello, world from a dispatch queue!\n");
});
require 'foxbat'
require 'em-websocket'
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 3333,
:secure => true, :keystore => '/path/to/keystore') do |ws|
ws.onopen {
puts "WebSocket connection open"
# publish message to the client
ws.send "Hello Client"
}
var f = new future(function() {
return {"foo" : 1};
});
var x = new actor(function(msg) {
console.log('Foo!');
});
x.send('something'); // => 'Foo!'
x.upgrade(function(msg) {
console.log('Bar!');
});
// Shamelessly pulled from the Rubinius example
// at http://rubini.us/doc/en/systems/concurrency/
var ping = new actor(function(msg) {
if (msg === 1000) {
console.log(msg);
} else {
pong.send(msg++);
}
});
package com.mowforth.rhinode;
public class MyClassLoader extends java.lang.ClassLoader {
public Class defineClass(byte[] b) {
return defineClass(null, b, 0, b.length);
}
}
Exception in thread "main" java.lang.ClassCastException: org.mozilla.javascript.NativeClassyObject cannot be cast to org.mozilla.javascript.ScriptableObject
at org.mozilla.javascript.commonjs.module.Require.executeModuleScript(Require.java:314)
at org.mozilla.javascript.commonjs.module.Require.getExportedModuleInterface(Require.java:283)
at org.mozilla.javascript.commonjs.module.Require.call(Require.java:213)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:98)
at org.mozilla.javascript.gen._stdin__1.call_script(Unknown Source)
at org.mozilla.javascript.gen._stdin__1.call(Unknown Source)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:422)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen._stdin__1.call(Unknown Source)