Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / ffi_example.rb
Created November 24, 2009 18:52
A Simple FFI example on OS X
#"" An FFI example on Mac 10.5.8
#
# % gcc --version
# i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)
#
# Setup a source file
#
require 'fileutils'
@thinkerbot
thinkerbot / clips_jni.rb
Created November 24, 2009 20:23
CLIPSJNI via JRuby
# 1) Install JRuby
# http://jruby.org/
# 2) Download CLIPSJNI 6.30
# http://sourceforge.net/projects/clipsrules/files/CLIPS/
# 3) Put this file in the CLIPSJNI folder, then:
#
# % cd [CLIPSJNI folder]
# % jruby clips.rb
#
@thinkerbot
thinkerbot / howto.txt
Created January 3, 2010 22:27
outdated howtos
h2. Use an older version of Tap (or any gem)
Rubygems makes it very easy to use an older version of tap:
<notextile><pre><code>% tap _version_ ...</pre></code></notextile>
As you can see, all you have to do is specify the version in the first argument. This trick can also be useful for fixing the version of tap used if it gets called from another process.
<notextile><pre><code>% tap _0.10.3_
usage: tap <command> {options} [args]
@thinkerbot
thinkerbot / Gemfile
Created January 14, 2010 17:58
A bundler+gemspec setup for managing dependencies
#############################################################################
# Dependencies in this Gemfile are managed through the gemspec. Add/remove
# depenencies there, rather than editing this file ex:
#
# Gem::Specification.new do |s|
# ...
# s.add_dependency("sinatra")
# s.add_development_dependency("rack-test")
# end
#
@thinkerbot
thinkerbot / example.rb
Created February 23, 2010 18:16
A file upload example
require 'rubygems'
require 'sinatra'
get '/' do
erb :form, :locals => {:file => nil}
end
post '/' do
erb :form, :locals => {:file => request['file']}
end
@thinkerbot
thinkerbot / string_escapes.rb
Created March 3, 2010 23:00
examples of escaped strings in ruby
# String escapes:
#
# \a Bell/alert (0x07)
# \b Backspace (0x08)
# \e Escape (0x1b)
# \f Formfeed (0x0c)
# \n Newline (0x0a)
# \r Return (0x0d)
# \s Space (0x20)
# \t Tab (0x09)
@thinkerbot
thinkerbot / example_rack.rb
Created March 3, 2010 23:05
rack app + middleware example
require 'rubygems'
require 'rack'
require 'mongrel'
app = lambda do |env|
[200, {}, "#{env['middleware.message']} world"]
end
class Middleware
attr_reader :app
s="s=%p;puts s%%s";puts s%s
@thinkerbot
thinkerbot / screentest.html
Created March 19, 2010 16:36
a test of html5 canvas element
<html>
<body>
<!-- Test how supportive a browser is of several rendering techniques. -->
<p id="text">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
@thinkerbot
thinkerbot / basics.js
Created March 19, 2010 23:13
personal intro to javascript
describe 'String'
describe '.split'
it 'should split by separator'
'a,b c, d'.split(',').should.eql ['a', 'b c', ' d']
end
it 'should split characters if separator is empty'
'abc'.split('').should.eql ['a', 'b', 'c']
end
end