Skip to content

Instantly share code, notes, and snippets.

@raywu
raywu / LearnRuby_Die.rb
Created May 22, 2011 20:48
Chris Pine's exercises
class Die
def initialize
roll
end
def roll
@numberShowing = 1 + rand(6)
end
def showing
@raywu
raywu / RubyNuby_HW_Class.rb
Created May 23, 2011 23:50
Snuggs's HW: new class
class Cigs
def initialize(brand = "Cigarettes")
@brand = brand
end
def light
puts "I'm lighting up a #{@brand}."
end
def smoke
puts "#{@brand} tastes great!"
end
@raywu
raywu / gist:1471008
Created December 13, 2011 07:10 — forked from igrabes/gist:1471001
HTML Scraper
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'sqlite3'
require 'active_record'
require 'active_support'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
@raywu
raywu / gist:1475545
Created December 14, 2011 06:47
.vimrc 12/2011
set nocompatible
set number
set ruler
syntax on
" Set encoding
set encoding=utf-8
" Whitespace stuff
@raywu
raywu / gist:1475548
Created December 14, 2011 06:48
.gvimrc 12/2011
if has("gui_macvim")
" Fullscreen takes up entire screen
set fuoptions=maxhorz,maxvert
" Command-T for CommandT
macmenu &File.New\ Tab key=<D-T>
map <D-t> :CommandT<CR>
imap <D-t> <Esc>:CommandT<CR>
" Command-Return for fullscreen
@raywu
raywu / seeds.db
Created March 18, 2012 15:32
Enumerate database seeds
questions = [
'How spontaneous of a traveler are you?',
'Do you drink alcohol?',
'Do you smoke cigarettes?',
'Do you like to know how things work?',
'I always like to try new things:',
'How religious are you?',
'In general, it is important to follow the rules:',
'Are you sensitive to others\' needs?'
]
@raywu
raywu / user.rb
Created March 18, 2012 15:37
User model, modified omniauth sessions scraper, and created a smoke-screen search
class User < ActiveRecord::Base
has_many :events
has_many :ratings
has_many :messages
belongs_to :profile
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
@raywu
raywu / development.rb
Created March 18, 2012 15:59
OmniAuth authentication keys environment handling
Tourious::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
TWITTER_KEY = 'Development Keys'
TWITTER_SECRET = 'Development Secret'
FACEBOOK_KEY = 'Development Keys'
FACEBOOK_SECRET = 'Development Secret'
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
@raywu
raywu / problem9.rb
Created March 19, 2012 03:42
Project Euler problem 9
found = false
(1..1E3).each { |x|
(1..1E3).each { |y|
puts "a = #{x}, b = #{y}, c = #{1000 - x - y}, product = #{x * y * (1000 - x - y)}"
found = true if x ** 2 + y ** 2 == (1000 - x - y) ** 2
break if found
}
break if found
}
@raywu
raywu / problem11.rb
Created October 1, 2012 16:38
Project Euler: Problem 11
grid_string = <<EOS
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72