Skip to content

Instantly share code, notes, and snippets.

View rjungemann's full-sized avatar

Roger Jungemann rjungemann

View GitHub Profile
@rjungemann
rjungemann / spork_socket.rb
Created January 15, 2010 01:06
Use Spork to create an HTTP server in Ruby with a socket component
# use "git clone git://github.com/deadprogrammer/spork.git" to install
# spork into your directory
require 'rubygems'
require 'eventmachine'
require 'rocket-amf/lib/rocketamf'
require 'spork'
module SocketSampleServer
def post_init
@rjungemann
rjungemann / script_path.rb
Created January 18, 2010 02:34
Get the running script's absolute path
# The current "best way" to get the absolute path of the current script in Ruby,
# as far as I know....
require 'pathname'
$prefix = Pathname.new(File.dirname(__FILE__)).realpath
@rjungemann
rjungemann / card.rb
Created January 19, 2010 02:57
Maoiste, a library which plays/mediates the card game, Mao
# the names that are generated for cards are designed to correlate
# with the naming system used for this SVG-formatted deck of cards
# http://david.bellot.free.fr/svg-cards/
class Object
def blank?
self.nil? || (self.respond_to?(:empty?) && self.empty?)
end
end
@rjungemann
rjungemann / gist.rb
Created January 27, 2010 23:32 — forked from schacon/example_gist_create.rb
Forked from defunkt's gist.rb
#!/usr/bin/env ruby
require 'open-uri'
require 'net/http'
require 'uri'
require 'pp'
require 'rubygems'
require 'json'
# This is my modified version of defunkt's gist.rb
# http://github.com/defunkt/gist/blob/master/gist.rb
@rjungemann
rjungemann / config.ru
Created January 27, 2010 23:43
The Parabox, WebDAV-powered app editing
# This exposes the root folder of your app through WebDAV, for remote editing.
# * I still need to implement http basic auth http://www.gittr.com/index.php/archive/sinatra-basic-authentication-selectively-applied/
# * I want to find a DAV-powered way to restart the app once changes have been made....
require 'rubygems'
require "rack_dav"
use Rack::CommonLogger
run RackDAV::Handler.new(:root => File.dirname(__FILE__))
@rjungemann
rjungemann / playlist.rb
Created January 28, 2010 07:01
script for making audio or video playlists which play in the browser, but which also work as playlists on the iPhone.
# script for making audio or video playlists which play in the browser
# but which also work as playlists on the iPhone.
#
# example:
# playlist %w[one.mp3 two.mp3 three.mp3]
#
# sources:
# http://stackoverflow.com/questions/87290/how-to-embed-audio-video-on-html-page-that-plays-on-iphone-browser-over-gprs
# http://broadcast.oreilly.com/2009/04/iphone-web-audio-playlistshtml.html
# http://jchrisa.net/drl/_design/sofa/_show/post/web_audio_for_the_iphone
@rjungemann
rjungemann / thin_cocoa.rb
Created January 30, 2010 04:19
Run a thin server from a RubyCocoa app
# Start a thin server on the side, which can serve UI to the user in a
# WebView. That way you can make RubyCocoa UI with HTML, thanks to Sinatra.
require 'osx/cocoa'
OSX.require_framework 'WebKit'
class ThinDesktopController < OSX::NSObject
include OSX
ib_outlets :webView
ib_action :quitApp
@rjungemann
rjungemann / filename_from_url.rb
Created January 30, 2010 22:13
Retrieve a filename from a URL
# retrieve a filename from a URL
require 'uri'
url = "http://threeve.org/blog/2008/01/run-ruby-script-automator-action.html"
uri = Uri.parse(url)
basename = File.basename(uri.path)
@rjungemann
rjungemann / tmpl-node.js
Created January 31, 2010 00:59
Fork of John Resig's Simple JS Templating
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
// modified by Roger Jungemann - MIT License
// this version is designed to work under node.js
var cache = {};
String.tmpl = function(str, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
@rjungemann
rjungemann / uuid.js
Created January 31, 2010 01:48
A uuid generator for JS
/* randomUUID.js - Version 1.0
*
* Copyright 2008, Robert Kieffer
*
* This software is made available under the terms of the Open Software License
* v3.0 (available here: http://www.opensource.org/licenses/osl-3.0.php )
*
* The latest version of this file can be found at:
* http://www.broofa.com/Tools/randomUUID.js
*