Skip to content

Instantly share code, notes, and snippets.

View robi42's full-sized avatar

Robert Thurnher robi42

View GitHub Profile

Keybase proof

I hereby claim:

  • I am robi42 on github.
  • I am robi42 (https://keybase.io/robi42) on keybase.
  • I have a public key ASCuBTF2Vf86jtTHHPaGy7KAlORSqX0Zeq-KCCY1F8o5zgo

To claim this, I am signing this object:

$ ringo
>> list = new ScriptableList(new java.util.HashSet(["foo", "bar", "bar"]))
[java.util.ArrayList [foo, bar]]
>> list[0]
'foo'
>> list.pop()
'bar'
>> map = new ScriptableMap(new java.util.HashMap({foo: 'bar'}))
{ foo: 'bar' }
>> map.foo
@robi42
robi42 / gist:1256833
Created October 1, 2011 23:56
Ringo: Java -> JS collection conversions
$ ringo
>> list = java.util.Arrays.asList("foo", "bar", "baz")
[java.util.Arrays$ArrayList [foo, bar, baz]]
>> array = [_ for (_ in Iterator(list))]
[ 'foo', 'bar', 'baz' ]
@robi42
robi42 / rest.scala
Created September 23, 2011 15:55
Basic RESTful service with Finagle
class Respond extends Service[Request, Response] with Logger {
def apply(request: Request) = {
try {
request.method -> Path(request.path) match {
case GET -> Root / "todos" => Future.value {
val data = Todos.allAsJson
debug("data: %s" format data)
Responses.json(data, acceptsGzip(request))
}
case GET -> Root / "todos" / id => Future.value {
var {Application} = require('stick');
var response = require('ringo/jsgi/response');
var app = exports.app = Application();
app.configure('notfound', 'error', 'params', 'route');
app.get('/', function (req) {
return response.json(req.params);
});
@robi42
robi42 / gist:1171239
Created August 25, 2011 17:36
CoffeeScript compiler fun on Ringo
$ wget --no-check-certificate https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js
$ ringo --optlevel -1
>> fs = require('fs')
>> coffee = fs.read('./coffee-script.js').replace(/this\.CoffeeScript/, 'exports.CoffeeScript')
>> fs.write('./coffee-script.js', coffee)
>> var {CoffeeScript} = require('./coffee-script')
>> code = CoffeeScript.compile("do -> 'Hello, Ringo world!'", {bare: true})
'(function() {
return \'Hello, Ringo world!\';
})();'
{JFrame, JButton} = javax.swing
main = ->
frame = new JFrame('Hello World!')
button = new JButton('Bye bye')
button.addActionListener (e) ->
system.exit(); return
frame.add 'Center', button
frame.setSize 300, 300
frame.visible = true
exports.app = (req) ->
status: 200
headers:
'Content-Type': 'text/plain'
body: ['Hello World!']
if require.main is module
require('ringo/httpserver').main module.id
@robi42
robi42 / gist:1078959
Created July 12, 2011 20:52
Conveniently iterate over a java.util.HashSet in Ringo
$ ringo
>> set = new java.util.HashSet(['foo', 'bar'])
[java.util.HashSet [foo, bar]]
>> for each (var element in Iterator(set)) print(element)
foo
bar
>>
(function (win) {
win.$mp = win.$mp || {};
win.$mp.makeMvcPipe = function () {
var _loadStyleSheet = function (path, media, fn, scope) {
var sheet, cssRules;
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');