Skip to content

Instantly share code, notes, and snippets.

@octosteve
octosteve / using_class_eval.rb
Created October 29, 2012 17:36
Done with class_eval
class Cart
def confirm
"Your order is being processed"
end
end
cart = Cart.new
cart.class.class_eval do
def deny
@octosteve
octosteve / Cakefile
Created December 8, 2012 23:34
Used to lint and test files
{spawn, exec} = require 'child_process'
task 'lint', 'Lint Everything', ->
lint_command = "./node_modules/.bin/coffeelint -r Cakefile ."
lint = exec lint_command, (error, stdout, stderr) ->
console.log stdout.toString()
console.log stderr.toString()
if error isnt null
console.log "Errors prevented your task from continuing"
process.exit(1)

GOAL

Be able to push to Heroku as any of three Heroku users from a single computer and a single user.

For this, you will not be allowed to copy and paste anything - except SSH keys themselves, because we're not THAT evil.

If you get error messages, read them carefully, and make note of what you understand, what you don't understand, and what you think you understand.

@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.
@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 / 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 / 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 / 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 / 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 / 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 }