Skip to content

Instantly share code, notes, and snippets.

require "sqlite3"
require 'open-uri'
require 'nokogiri'
###############
# # Open a database
db = SQLite3::Database.new "students.db"
rows = db.execute <<-SQL
module Enumberable
a = {:key => nil, :other_key => "value" }
def flatiron_flatten
self.select do |key, value|
value!=nil
end
end
@ajwaxman
ajwaxman / gist:5831137
Created June 21, 2013 13:31
codewarmup
index = 0
stopper = false
until stopper == true
counter = 0
index+= 19
(1..20).each do |num|
if index % num == 0
counter += 1
end
app.rb
require 'rack'
class MyApp
def call(env)
puts "Hello from MyApp!"
[200, {}, ["Hello"]]
end
end
@ajwaxman
ajwaxman / gist:5820088
Created June 20, 2013 03:26
hellorack
require 'rack'
class AdamApp #change this name
def call(env)
[200, {'Content-Type' => 'text/html'},
['<a href="http://students.flatironschool.com/students/awaxman.html"><h1 style="color:blue">Adam Waxman<h1></a>']
]
end
end
@ajwaxman
ajwaxman / gist:5814556
Created June 19, 2013 14:03
student-oo-take2
class School
attr_accessor :name, :roster
def initialize(name)
@name = name
@roster = {}
end
def add_student(name, grade)
student = Student.new
@ajwaxman
ajwaxman / gist:5811055
Created June 19, 2013 01:37
school-oo
class School
attr_accessor :name, :roster
def initialize(name)
@name = name
@roster = {}
end
def add_student(name, grade)
student = Student.new
@ajwaxman
ajwaxman / gist:5802511
Created June 18, 2013 03:35
reverse-word
# reverse_each_word.rb
# Write a method that takes a sentence and returns it with each word reversed in place.
# A String has many methods that can be called on it:
# http://www.ruby-doc.org/core-1.9.3/String.html
sentence = "Hello there, and how are you?"
def reverse_each_word(sentence)
sentence.split.collect { |word| word.reverse}.join(" ")
@ajwaxman
ajwaxman / gist:5797512
Created June 17, 2013 14:56
student scrapper
require "sqlite3"
require 'open-uri'
require 'nokogiri'
###############
# # Open a database
db = SQLite3::Database.new "test.db"
rows = db.execute <<-SQL
@ajwaxman
ajwaxman / gist:5794511
Created June 17, 2013 03:38
object-oriented jukebox
# jukebox.rb
# list, play, help, exit
class Jukebox
attr_accessor :songs
def start