Skip to content

Instantly share code, notes, and snippets.

View wwkeyboard's full-sized avatar
ERR_INSUFFICIENT_COFFEE

Aaron Lee wwkeyboard

ERR_INSUFFICIENT_COFFEE
View GitHub Profile
@wwkeyboard
wwkeyboard / mysql2mongo.rb
Created February 4, 2011 09:14
Dump data from MySQL into MongoDB
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",
@wwkeyboard
wwkeyboard / makeFileNameList2.rb
Created August 19, 2011 19:59 — forked from anonymous/makeFileNameList2.rb
Makes file listing all files in a directory
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
@wwkeyboard
wwkeyboard / gist:3614841
Created September 3, 2012 23:34
Zed's work
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
@wwkeyboard
wwkeyboard / gist:3644401
Created September 5, 2012 20:41
csv in, json out
require 'csv'
require 'json'
CSV.foreach(ARGV[0]) do |row|
puts JSON({one: row[0], two: row[1]})
end
@wwkeyboard
wwkeyboard / bendfordslaw.rb
Created September 18, 2012 00:08
A semi attempt of bendford's law
# 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
@wwkeyboard
wwkeyboard / findingprime.rb
Created September 18, 2012 00:38
Finding the 10,001st prime number
# 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
@wwkeyboard
wwkeyboard / player.rb
Created September 25, 2012 00:17
Player from the 9/24 class
class Player
attr_accessor :warrior
def initialize
@old_health = 20
end
def play_turn(warrior)
@warrior = warrior
ruby -r 'json' -r 'rest-client' -e "[JSON.parse(RestClient.get \"http://www.reddit.com/r/dadjokes.json\")['data']['children'].sample['data']].map{|j| puts \"#{j['title']} \n #{j['selftext']}\" }"
@wwkeyboard
wwkeyboard / cards.hs
Created February 4, 2014 12:28
Trying to model playing cards in Haskell(not sure this is right)
-- | Main entry point to the application.
module Main where
data Suit = Hearts | Dimonds | Clubs | Spades
data Rank = A | R2 | R3 | R4 | R5 | R6 | R7 | R8 | R9 | R10 | J | Q | K
data Card = Card Rank Suit
rankWord :: Rank -> String
rankWord A = "Ace"
rankWord R2 = "Two"