Skip to content

Instantly share code, notes, and snippets.

@gregeng
gregeng / serialize.rb
Created October 15, 2013 13:29
to-do serialization
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :progress # :progress, :html, :textmate
end
@gregeng
gregeng / api_parsing.rb
Last active December 25, 2015 13:09
Safe For Work Reddit
require 'json'
require 'rest_client'
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json'))
html_reddit = "<html><head></head><body><ul>"
reddit_hash["data"]["children"].each do |post|
next if post["data"]["over_18"] == true
@gregeng
gregeng / version_sort.rb
Created October 14, 2013 18:57
version_sort, accounts for differences in the letter before .ext by converting it to the ASCII code first
require 'pry'
class Array
def version_sort
array = self.sort_by do |file|
file.gsub(/[a-z].ext/) {|x| x.ord }
end
array.sort_by do |item|
item.scan(/\d+|[a-z]*/).collect do |el|
@gregeng
gregeng / anagram.rb
Created October 14, 2013 15:14
anagram
require 'pry'
class Anagram
attr_reader :word
def initialize(word)
@word = word
end
def match(array=%w(hello world zombies pants))
@gregeng
gregeng / my_each.rb
Created October 11, 2013 15:30
my_each
class Array
def my_each
i = 0
while i < self.length
yield(self[i])
i+=1
end
self
end
@gregeng
gregeng / student_scrape.rb
Last active December 25, 2015 00:49
oop-studentscrape
require 'pry'
require 'nokogiri'
require 'open-uri'
require_relative './student_scrape'
class Student
attr_accessor :name, :twitter, :linkedin, :facebook, :website
@@students = []
def initialize(name, twitter, linkedin, facebook, website)
@gregeng
gregeng / oop-jukebox-practice.rb
Last active December 25, 2015 00:18
oop-jukebox-practice
# Build a Jukebox
require 'pry'
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
@gregeng
gregeng / binary_handshake.rb
Last active December 25, 2015 00:09
binary-handshake
require 'pry'
class SecretHandshake
attr_accessor :binary
def initialize(binary)
@binary = binary
end
def commands
@gregeng
gregeng / scraping_students.rb
Last active December 24, 2015 16:49
scraping student pages
# Scraping Most Voted Hackernews
require 'pry'
require 'nokogiri'
require 'open-uri'
# Get all the Posts on Hackernews
# student_profile = Nokogiri::HTML(open('http://students.flatironschool.com/students/greg_eng.html'))
student_index_page = Nokogiri::HTML(open('http://students.flatironschool.com'))
@gregeng
gregeng / nyc-pidgeon-organizer.rb
Created October 3, 2013 02:51
NYC Pigeon Organizer
########################
# NYC PIGEON ORGANIZER #
########################
# Start with the following collected data on NYC pigeons.
require 'pry'
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],