Skip to content

Instantly share code, notes, and snippets.

View rjungemann's full-sized avatar

Roger Jungemann rjungemann

View GitHub Profile
@rjungemann
rjungemann / udp-thing.js
Created June 19, 2010 07:43 — forked from pquerna/udp-thing.js
UDP client and server in Node.js
log = require('sys').log
dgram = require('./lib/dgram')
var Buffer = require('buffer').Buffer;
var endat = 10;
var count = 0;
socket = dgram.createSocket();
socket.addListener('message', function (msg, rinfo) {
log('got message from '+ rinfo.address +' port: '+ rinfo.port);
log('data len: '+ rinfo.size + " data: "+ msg.toString('ascii', 0, rinfo.size));
@rjungemann
rjungemann / diff.rb
Created June 3, 2010 19:03
Using the diff-lcs gem
# an example of using the diff-lcs gem
# a mirror of the gem is hosted at http://github.com/defunkt/diff-lcs
# or `gem install diff-lcs`
require 'diff/lcs'
first, second = "hello, world!", "Hello, world!"
diff = Diff::LCS.diff(first, second)
patched = Diff::LCS.patch!(first, diff)
@rjungemann
rjungemann / 1. restful_service.rb
Created June 2, 2010 01:51 — forked from headius/1. restful_service.rb
Sinatra-like example in JRuby with Jersey
require 'java'
java_import 'javax.ws.rs.Path'
java_import 'javax.ws.rs.GET'
java_import 'javax.ws.rs.Produces'
java_package 'com.headius.demo.jersey'
java_annotation 'Path("/helloworld")'
class HelloWorld
java_annotation 'GET'
java_annotation 'Produces("text/plain")'
@rjungemann
rjungemann / client.rb
Created May 29, 2010 18:09 — forked from tobi/client.rb
Simplistic Ruby message queue
STDOUT.sync = true
require 'queue'
start_time = Time.now.to_i
msg = 0
queue = Queue.new("testing")
queue.subscribe do |obj|
msg += 1
@rjungemann
rjungemann / gist.rb
Created May 28, 2010 05:29
A modified version of the gist command-line util
#!/usr/bin/env ruby
require 'open-uri'
require 'net/http'
require 'uri'
require 'pp'
require 'json'
# This is my modified version of defunkt's gist.rb
# http://github.com/defunkt/gist/blob/master/gist.rb
# more scripts that harness the Github Gist API can be found at
@rjungemann
rjungemann / redis_pubsub.rb
Created May 24, 2010 22:04
A Redis pubsub example for Ruby
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
# http://gist.github.com/348262
# Incomplete evented Redis implementation specifically made for
# the new PubSub features in Redis.
# Modifications by Roger Jungemann
require 'stringio'
@rjungemann
rjungemann / models.rb
Created May 20, 2010 21:50
The "videostar" project model
class Comment
include DataMapper::Resource
belongs_to :user
belongs_to :video
property :id, Serial
property :uuid, String
property :content, Text
property :created_on, DateTime
@rjungemann
rjungemann / Rakefile
Created May 18, 2010 18:53
Rake task for building daemontools
desc "build daemontools from source"
task :install do
sh "curl -O curl -O http://cr.yp.to/daemontools/daemontools-0.76.tar.gz"
sh "tar zxf daemontools-*.tar.gz && rm daemontools-*.tar.gz"
sh "mv admin/daemontools-* ../daemontools && rm -rf admin"
sh "cd daemontools && package/compile"
puts "You can now run commands that exist in the daemontools/command dir."
end
@rjungemann
rjungemann / bakerie.rb
Created May 11, 2010 22:49
Observes a folder and checks files into git every time they're changed
# recursively observes a folder and periodically checks new or updated files
# into a git repository.
#
# usage:
# ruby bakerie.rb path repo_path
#
# if repo_path doesn't exist or isn't a git repository, bakerie will create
# the folder and make it into a repository. It is unwise to have path and
# repo_path be the same.
#
@rjungemann
rjungemann / config.ru
Created April 29, 2010 23:34
Example of using Sinatra with JSONP
# http://snippets.aktagon.com/snippets/445-How-to-create-a-JSONP-cross-domain-webservice-with-Sinatra-and-Ruby
require 'sinatra/base'
require 'json/pure'
module JSONPatra
class App < Sinatra::Base
get "/" do
callback = params['callback']
json = { :hello => "world!" }.to_json