This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── 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). |
NewerOlder