Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile

Summary

Many types of functions produce data amenable for charting in the xy dimensions. These functions are defined as f(x[n]) = y. To transform this function into an f(x) = y function, provide a projection that takes a set of (x[n], y) values and picks a single (x,y) pair. In practice the set (x[n], y) values must be limited to fit within memory/runtime bounds... ergo for a given x there must be a limited number of x[n-1].

In summary a projection can produce xy data from x[n]y data provided:

  • there is one value y for each (x[n])
  • the number of x[n-1] is limited for a given x

Many types of data end up satisfying these conditions, in particular measurement data. Measurement data can be modeled as ty. If measurement data can be overridden then add a dimension to track when the data was recieved, ie tty.

x, y = 0, 0
xmin, xmax, ymin, ymax = 0, 0, 0, 0
e = Enumerator.new do |yy|
loop do
while x > xmin
yy << [x, y]
x -= 1
end
xmin -= 1
while y < ymax
@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