Skip to content

Instantly share code, notes, and snippets.

@octosteve
octosteve / seeds.rb
Created May 14, 2013 02:13
First pass at Movie data
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
#
puts "Adding a Whole bunch of movies"
Movie.create [
@octosteve
octosteve / repo
Created May 9, 2013 02:48
Because creating new repos happens a lot to me for some reason
#!/bin/bash
git init && git add . && git commit -m 'Initial Commit'
@octosteve
octosteve / wtf.rb
Last active December 16, 2015 17:50
This makes me angry... but it makes sense.
class Subteddit
def self.add_story(story)
@story ||= []
@story << story
end
def add_story(story)
@story ||= []
@story << story
end
@octosteve
octosteve / arashes.rb
Last active December 16, 2015 11:29
Array Notes
# create simple array
array = [1,2,3,4,5]
# Iterate through each value
array.each {|num| puts num * 20 }
puts num
# You're gonna have a bad time
# plays nice with variable outside
x = 2
array.each {|num| puts num * 20 + x }
@octosteve
octosteve / friday_lyrics
Created April 16, 2013 20:54
Rebecca Black's Friday
Rebecca Black Friday is the debut single by new Internet sensation Rebecca Black. The music video for "Friday" received over 1 million plays on Youtube in its premiere day.
(Yeah, Ah-Ah-Ah-Ah-Ah-Ark)
Oo-ooh-ooh, hoo yeah, yeah
Yeah, yeah
Yeah-ah-ah
Yeah-ah-ah
Yeah-ah-ah
Yeah-ah-ah
Yeah, yeah, yeah
@octosteve
octosteve / rubeque.rb
Last active December 15, 2015 10:29
Fetch by category from Rubeque. You need the rest-client gem
#!/usr/bin/env ruby
require 'rest-client'
require 'json'
class Rubeque
def initialize
@questions = categorize
end
def categories
@octosteve
octosteve / bash_keys(osx)
Last active December 15, 2015 01:49
List of bash Navigations I find helpful
Tab Completion: Press Tab to finish commands/paths
Moving around
Control + a: Go to the beginning of the line
Control + e: Go the the end of the line
Option + b: Move back one word
Option + f: Move forward one word
Deleting
Control + k: Delete from current cursor position
@octosteve
octosteve / forms
Created March 7, 2013 01:57
A tutorial on how to work nested forms in rails.
When we last left our application it there were list and task models. They were associated with a list having many tasks and a task belonging to a list.
We wanted to build a nested form so we had to let the list model know it has some additional responsibilities.
In the List model we had to add this:
accepts_nested_attributes_for :tasks
This line creates an attribute on the list objects available at :task_attributes.
Since rails has mass assignment protection, and we WANT our form to use mass assignment to create tasks through a list we need to white list our new attribute on the attr_accessible line
attr_accessible :name, :tasks_attributes
@octosteve
octosteve / expenses.rb
Created January 20, 2013 19:28
Expenses With David
require 'google_drive'
class Transaction
def initialize(date, merchant, amount)
@date = date
@merchant = merchant
@amount = amount
end
def self.all
ws.rows.map{|row| Transaction.new row[0], row[1], row[2]}
@octosteve
octosteve / notes.rb
Created January 18, 2013 04:07
These are some notes from the 2nd week's Thursday class
# We covered a lot in class and I wanted to go over some of the things we discussed in class in more details
# First things first! This file is an .rb file. You can run it in your terminal. Try it!
##----------------------------------------------------------------------------------------------------
puts "I can haz codingz?"
##----------------------------------------------------------------------------------------------------
# Great now comment out that line. We'll have a bunch of code examples you will have to uncomment to get them to run.
# Your editor has a short cut for commenting and uncommenting code so don't do this manually.
# Ok. Something specific to classes
# We mentioned some specific stuff about property 'visibility'.
# All that means is what can you ask your object for that won't piss it off.