Skip to content

Instantly share code, notes, and snippets.

Pry Cheat Sheet

Youtube Tutorial 2013

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environemtn.rb - load your rails into a pry session

Debugger

// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
//
// map-fetch($map, $keys)
//
// An easy way to fetch a deep value in a multi-level map. Works much like
// map-get() except that you pass multiple keys as the second parameter to
@carolineartz
carolineartz / 0.2.2-ruby_and_databases.rb
Last active August 29, 2015 13:59 — forked from dbc-challenges/0.2.2-ruby_and_databases.rb
UPDATED: All applicable methods changed to guard against sql injection
require 'sqlite3'
$db = SQLite3::Database.open 'congress_poll_results.db'
def print_arizona_reps
puts 'AZ REPRESENTATIVES'
az_reps = $db.execute("SELECT name FROM congress_members WHERE location = 'AZ'")
az_reps.each { |rep| puts rep }
end

Todo.rb

Todo.rb is a simple command-line tool for managing todos. It's minimal, straightforward, and you can use it with your favorite text editor.

Getting Started

Todo.rb doesn't require any third-party gems so you can copy the file anywhere and use it as long as it's executable:

# Your awesome code goes here!
class Song
attr_reader :track, :artist
def initialize(track, artist)
@track = track
@artist = artist
end
def play
puts 'NOW PLAYING' + ' ' + self.track + '-' + self.artist
class Student
attr_accessor :scores, :ssn, :first_name
def initialize(fname, ssn, scores)
@first_name = fname
@ssn = ssn
@scores = scores
end
def average
#Output: number of possible teams
def choose_team(n, k)
return n if k == 1
return 0 if k == 0 || n == 0
choose_team(n-1,k-1) + choose_team(n-1,k)
end
p choose_team(6,1) == 6
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/wiki/SyntaxHighlighter:Donate
*
* @version
* 2.0.320 (May 03 2009)
*
@carolineartz
carolineartz / print_times_table.rb
Last active August 29, 2015 13:57 — forked from dbc-challenges/phase0_template_gist.rb
print out a times table
# PSEUDOCODE
# INPUT rows: integer (0 or positive) for number of rows (/columns)
# OUPUT times table: printed times table with the input number of rows/columns
# STEPS
# SET a collection with elements 1..rows
# SET counter to 1
# WHILE counter is less than/equal to rows
# ITERATE over elements of collection
# MULTIPLY element by counter
=begin
As you are debugging, ask yourself:
* Do you have enough information to decipher the problem?
* Is the error message referencing a line in your file, or a different file?
* Is there a methodology that you are following to systematically tackle these bugs? What is a step by step approach?
###2) Decipher the bugs
For each bug (there are three initial bugs that cause interpreter errors), answer the following questions: