Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / profile_load_time.rb
Created August 16, 2008 17:16
A load time profiler script
# = Description
# A load time profiler script, useful for identifying requires
# that slow down the loading of a script.
#
# Oftentimes we use but don't always need what we require in
# scripts. This can dramatically slow load times, which can be
# annoying. Use this script to identify slow-loading parts of
# a script and then consider using autoloading to defer
# the require until you really need it.
#
#!/usr/bin/env ruby
################################################################
# A basic cgi script. To run, set up the following:
#
# /dir
# |- cgi-bin
# | `- this_script.cgi
# `- the_webrick_script.rb
#
@thinkerbot
thinkerbot / redirect_http.js
Created November 17, 2008 22:18
ubiquity command: redirect-http
//////////////////////////////////////////////////////////////////////////////
//
// RedirectHttp
//
// Note Ubiquity makes these objects available (the list is incomplete, but
// contains the objects that are used in this script):
//
// - Application:: the FUEL[http://developer.mozilla.org/en/FUEL] Application object
// - CmdUtils:: Ubiquity command utilities
//
@thinkerbot
thinkerbot / mascot_mass_calc.rb
Created December 2, 2008 19:37
Calculation of Mascot Peptide Mass
# These are a number of tasks to calculate peptide masses
# using a variety of algorithms. The intent is to find
# the algorithm used by Mascot to calculate peptide mass.
#
# Correct algorithm: unknown
# Dependencies: tap, molecules
#
require 'rubygems'
require 'tap'
@thinkerbot
thinkerbot / simple_yaml.rb
Created December 7, 2008 21:23
YAML dump/load for simple hashes
# = Description
#
# SimpleYaml provides methods to dump and load simple configurations.
# Support is limited strings, symbols, booleans, nil, and numbers.
# Values may include non-nested arrays. Nested hashes are not
# supported anywhere.
#
# include SimpleYaml
# hash = {
# :sym => 'str',
@thinkerbot
thinkerbot / manual_includes.rb
Created January 29, 2009 15:27
MiniTest: A curious case of include (1.8 vs 1.9)
require 'rubygems'
require 'minitest/spec'
module A
module B
end
end
class DirectInclude
include A
@thinkerbot
thinkerbot / http_echo_server.rb
Created March 7, 2009 23:45
Server to echo HTTP requests.
# usage: ruby echo_server.rb
#
# Launches a WEBRick server that echos http requests back. This can be
# useful when debugging HTTP requests.
#
require 'webrick'
# Setup server configuration
logger = WEBrick::Log.new
@thinkerbot
thinkerbot / tap-ubiquity.js
Created March 8, 2009 01:39
ubiquity commands to run a tap server
//////////////////////////////////////////////////////////////////////////////
//
// Tap
//
// Note Ubiquity makes these objects available (the list is incomplete, but
// contains the objects that are used in this script):
//
// - Application:: the FUEL[http://developer.mozilla.org/en/FUEL] Application object
// - jQuery:: http://docs.jquery.com/Main_Page
// - Utils:: Ubiquity utilities
@thinkerbot
thinkerbot / io_duplicate_danger.rb
Created April 1, 2009 18:02
Danger of IO duplicate
# This illustrates how IO duplicates flush separately.
# The danger is that this can result in disordered
# output. Run this from the command line:
#
# % ruby io_duplicate_danger.rb
# 1
# 2
# 3
#
# You get what you expect. Now try with redirection:
@thinkerbot
thinkerbot / Trying to best YAML - fail
Created April 30, 2009 13:03
An attempt at YAML options
# Setting options for to_yaml doesn't work.
# * http://www.arkanis-development.de/weblog/2007/6/20/options-for-rubys-@to_yaml@-method
# * http://groups.google.com/group/ruby-talk-google/browse_thread/thread/b9bd01242f7d67ae/7186dd14f9e1e3ff#7186dd14f9e1e3ff
#
# This is an attempt to workaround by directly setting a flag in the
# emitter. Fail. If I recall right, trying to set/modify the @options
# hash also does not work.
#
# :UseHeader => false
#