Skip to content

Instantly share code, notes, and snippets.

View timrandg's full-sized avatar

Tim Rand timrandg

View GitHub Profile
@timrandg
timrandg / kmer_find.rb
Last active December 31, 2015 09:59
all mutations
class Array
def expand(master, mut)
collection = []
each do |str|
c = str.count('.')
case
when c < mut
collection << str + master[str.length]
collection << str + '.'
when c == mut
@timrandg
timrandg / kmer_find.rb
Created December 15, 2013 08:58
create all mutant sequences with m mutations or fewer from protein or DNA
class Array
def expand(master, mut)
collection = []
each do |str|
c = str.count('.')
case
when c < mut
collection << str + master[str.length]
collection << str + '.'
when c == mut
@timrandg
timrandg / Block Demo2.rb
Created October 25, 2013 16:28
sending to block
public
def average_by_every(arr, q)
arr.each_slice(q).collect{|q_set| q_set.inject{|s,n| s+n}/q }
end
p average_by_every([1,2,3,4,5,6,7,8,9], 2)
p average_by_every([1,2,3,4,5,6,7,8,9], 3)
@timrandg
timrandg / Block Demo
Created October 25, 2013 06:19
block demo for Ben
def test_blocks(some_obj)
yield some_obj #remember you could add parenthesis to make it read yield(some_obj).
end
test_blocks(10){|so| puts so}
test_blocks('hello, world'){|so| puts so}
@timrandg
timrandg / Elliot Smith Whatever lyrics
Created October 24, 2013 04:50
Elliot Smith Whatever lyrics
http://www.youtube.com/watch?v=7tOnIDRc0kg
"Whatever (Folk Song In C)"
They come here alone and they leave in twos
Except for you and me who just came to use
If you're all done like you said you'd be
What are you doing hanging out with me
Why you tell me stuff that's so plainly untrue
@timrandg
timrandg / web parser challenge.rb
Created October 8, 2013 09:23
web parser challenge for Ben
require 'nokogiri'
require 'open-uri'
url = "http://www.nationsonline.org/oneworld/country_code_list.htm"
nodes = Nokogiri::XML(open(url))
#xml path to country table data nodes
table_data = "//td[@class='border1']"
@timrandg
timrandg / web parser challenge.rb
Created October 8, 2013 09:13
web parser challenge for Ben
require 'nokogiri'
require 'open-uri'
#helper function for printing out table, just need to construct a country struct
def print(c)
puts "%-50s %5s %5s %5s" % [ c[:name], c[:abr_two], c[:abr_three], c[:code] ]
end
url = "http://www.nationsonline.org/oneworld/country_code_list.htm"
nodes = Nokogiri::XML(open(url))
@timrandg
timrandg / GO
Created August 24, 2013 20:42
GO
I am also learning GO after being happy with ruby for a long time. The package system is intriguing to me and it forms a central feature that makes GO easier to work in than C, for instance. When writing GO code, one benefits from adopting the GO workspace file structure--set $GOPATH to the directory you want to keep your GO code in (perhaps ~/Dropbox/go or ~/Google Drive/go), within the $GOPATH place a src directory, which will contain all the packages you create. Within src, you place a separate directory for each package you write. A package is the composed of all of the files in this directory. The directory name and the package files inside do not have to match each other--but you will find it most sensible to make them the match (i.e. package strings lives in the src/strings directory). All of the files in a directory should be part of the same package. You don't mix 'package main' file with 'package foo' files. If you mix files in this way, GO will complain when you try to go install the file. The impo
@timrandg
timrandg / GO packages
Created August 24, 2013 20:41
GO packages
I am also learning GO after being happy with ruby for a long time. The package system is intriguing to me and it forms a central feature that makes GO easier to work in than C, for instance. When writing GO code, one benefits from adopting the GO workspace file structure--set $GOPATH to the directory you want to keep your GO code in (perhaps ~/Dropbox/go or ~/Google Drive/go), within the $GOPATH place a src directory, which will contain all the packages you create. Within src, you place a separate directory for each package you write. A package is the composed of all of the files in this directory. The directory name and the package files inside do not have to match each other--but you will find it most sensible to make them the match (i.e. package strings lives in the src/strings directory). All of the files in a directory should be part of the same package. You don't mix 'package main' file with 'package foo' files. If you mix files in this way, GO will complain when you try to go install the file. The impo
@timrandg
timrandg / package main
Last active December 20, 2015 02:59
where to store package main
├── bin
├── pkg
│ └── darwin_amd64
│ └── file.a
├── src
│ └── file
│ └── file.go
└── test.go
Within the partent of src, create the package.main file (in this case called test.go).