This file contains hidden or 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
# find the 10,001st prime number | |
# prime is divisable by itself and only 1 | |
def prime?(number) | |
(2..Math.sqrt(number)).each do |divisor| | |
return false if number % divisor == 0 | |
end | |
return true | |
end |
This file contains hidden or 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
# benford's law | |
def extract_number(number) | |
number.to_s[0] | |
end | |
distribution = [0,0,0,0,0,0,0,0,0,0] | |
100000.times do | |
number = (rand(1000)+1)**2 | |
value = extract_number(number).to_i |
This file contains hidden or 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 'csv' | |
require 'json' | |
CSV.foreach(ARGV[0]) do |row| | |
puts JSON({one: row[0], two: row[1]}) | |
end |
This file contains hidden or 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 'open-uri' | |
open("http://www.ruby-lang.org/en") do |f| | |
f.each_line {|line| p line} | |
puts f.base_uri # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/> | |
puts f.content_type # "text/html" | |
puts f.charset # "iso-8859-1" | |
puts f.content_encoding # [] | |
puts f.last_modified # Thu Dec 05 02:45:02 UTC 2002 | |
end |
This file contains hidden or 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 makeFileNameList2(nameDir,fname) | |
puts "the beginning" | |
File.open(fname, "w") do|fname| | |
puts "in the do" | |
Dir.foreach(nameDir) {|x| fname.puts file_to_string(x) } | |
end | |
puts "after the do" | |
end |
This file contains hidden or 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
goo!!! |
This file contains hidden or 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 'rubygems' | |
require 'mysql2' | |
require 'mongo' | |
CHUNK = 5000 | |
collection = Mongo::Connection.new.db('ipadmin').collection("my_collection_name") | |
client = Mysql2::Client.new(:host => "localhost", | |
:username => "root", |
NewerOlder