Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Chiang thinkerbot

  • Denver, CO
View GitHub Profile
@thinkerbot
thinkerbot / profile_load_time.rb
Created Aug 16, 2008
A load time profiler script
View profile_load_time.rb
# = 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.
#
View a basic webrick cgi server and script
#!/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 Nov 17, 2008
ubiquity command: redirect-http
View redirect_http.js
//////////////////////////////////////////////////////////////////////////////
//
// 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 Dec 2, 2008
Calculation of Mascot Peptide Mass
View mascot_mass_calc.rb
# 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 Dec 7, 2008
YAML dump/load for simple hashes
View simple_yaml.rb
# = 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 Jan 29, 2009
MiniTest: A curious case of include (1.8 vs 1.9)
View manual_includes.rb
require 'rubygems'
require 'minitest/spec'
module A
module B
end
end
class DirectInclude
include A
@thinkerbot
thinkerbot / http_echo_server.rb
Created Mar 7, 2009
Server to echo HTTP requests.
View http_echo_server.rb
# 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 Mar 8, 2009
ubiquity commands to run a tap server
View tap-ubiquity.js
//////////////////////////////////////////////////////////////////////////////
//
// 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
View io_duplicate_danger.rb
# 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:
View Trying to best YAML - fail
# 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
#