Skip to content

Instantly share code, notes, and snippets.

View timrandg's full-sized avatar

Tim Rand timrandg

View GitHub Profile
#project_euler problem_56
#A googol (10**100) is a massive number: one followed by one-hundred zeros; 100**100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
#Considering natural numbers of the form, ab, where a, b 100, what is the maximum digital sum?
sum_of_digits =->(a,b){ (a**b).to_s.split('').collect(&:to_i).inject(&:+) }
max_of =->(y, z){ y > z ? y : z}
for a in (1..99)
for b in (1..99)
@max = max_of.(sum_of_digits.(a,b), @max ||= 0)
end
# This sketch demonstrates how to use
# Ruby-Processing.
def setup
size 450, 450
smooth
background 255
end
def draw
module GeneralInit
def initialize(*h)
puts h == 1 && h.first.kind_of?(Hash)
if h.length == 1 && h.first.kind_of?(Hash)
h.first.each { |k,v| instance_variable_set("@#{k}",v) }
end
end
end
module GeneralInit
def initialize(*h)
if h.length == 1 && h.first.kind_of?(Hash)
h.first.each { |k,v| instance_variable_set("@#{k}",v) }
end
end
end
class Me
include GeneralInit
@timrandg
timrandg / fork.rb
Created May 25, 2012 06:55
fork explanation code
parent = Process.pid
puts parent.to_s + ": the parent process id"
forked_id = fork{ exec('ls | grep back')}
#^from that carrot in the line above, a child process is forked from the current (which is then parent) process.
#because there are two processes running, forked_id will be assigned in each process--e.g. two forked_id varaibles are created.
#in the child it is nil, but in the parent it is the child's pid. If a block is provided to fork, the child executes the block contents and
#ends. It may seem that the child process returns after the parent, but if the parent's task is long, the child may return in the middle
#of the parents job.
puts "fork returns #{forked_id.nil? ? 'nil' : forked_id} to " + Process.pid.to_s
1. go to http://www.genenames.org/cgi-bin/hgnc_downloads.cgi and create a text
output of the currated hgnc files.
% head hgnc.cleaned.txt
A12M1~withdrawn
A12M2~withdrawn
A12M3~withdrawn
A12M4~withdrawn
A1BG ENSG00000121410
A1S9T~withdrawn
A2M ENSG00000175899
@timrandg
timrandg / Unix batch download
Created February 15, 2013 06:42
Batch download genbank files from IRES website
1. Created a script for stripping out the urls for genbank files.
#IRES_PLASMID_SCRAPER.rb
pwd = "/Users/timrand/Dropbox/NAT1/"
file = pwd + "IRES_plasmids.txt"
website_url = "http://iresite.org/IRESite_web.php?page=gb_download&file="
out_file = pwd + "ires_plasmid_urls.txt"
f = File.read(file)
@timrandg
timrandg / gist:5054689
Created February 28, 2013 06:29
peptide mapper
#command-line usage:
#% ruby /Users/timrand/Dropbox/NAT1/peptide_mapper3.rb peptide_file target_file
# 1 M 0
# 2 S 0
# 3 P 8 [][][][][][][][]
# 4 A 8 [][][][][][][][]
# 5 G 8 [][][][][][][][]
# 6 S 8 [][][][][][][][]
# 7 C 8 [][][][][][][][]
# 8 D 8 [][][][][][][][]
@timrandg
timrandg / peptide_mapper4.rb
Created March 1, 2013 16:35
Refactoring peptide aligner
#command-line usage:
#% ruby /Users/timrand/Dropbox/NAT1/peptide_mapper3.rb peptide_file target_file
# 1 M 0
# 2 S 0
# 3 P 8 [][][][][][][][]
# 4 A 8 [][][][][][][][]
# 5 G 8 [][][][][][][][]
# 6 S 8 [][][][][][][][]
# 7 C 8 [][][][][][][][]
# 8 D 8 [][][][][][][][]
@timrandg
timrandg / peptide_mapper4.rb
Created March 2, 2013 16:07
More refactoring
#command-line usage:
#% ruby /Users/timrand/Dropbox/NAT1/peptide_mapper3.rb peptide_file target_file
# 1 M 0
# 2 S 0
# 3 P 8 [][][][][][][][]
# 4 A 8 [][][][][][][][]
# 5 G 8 [][][][][][][][]
# 6 S 8 [][][][][][][][]
# 7 C 8 [][][][][][][][]
# 8 D 8 [][][][][][][][]