Skip to content

Instantly share code, notes, and snippets.

@gabebw
gabebw / all_about_hashes.md
Created June 26, 2014 21:26
All about Ruby hashes

Ruby Hashes

  • Represents a key-value mapping
  • Contains zero or more key/value pairs
  • Can only access values by referencing keys

Exercises

How do you get "Gabe" out of the following hash?

@gabebw
gabebw / meat-cubes.mediawiki
Created June 19, 2014 01:47
Most Delicious Meat Cubes

a/k/a boti gosht

Serves 3-4.

From Madhur Jaffrey's Quick & Easy Indian Cooking

Ingredients

  • 3 Tablespoons vegetable oil

First things to throw in oil

@gabebw
gabebw / routes_and_objects.md
Last active August 29, 2015 14:02
Routes as objects

Routes and their Objects

Note that show paths and index paths are not arrays.

The object to use is what you'd pass to form_for, link_to, or redirect_to.

Name at /rails/info/routes object to use path
root_path no object-oriented way. Need to use root_path /
@gabebw
gabebw / punctuation.rb
Created June 16, 2014 18:57
Punctuation in Ruby
class Punctuation
def _?(*args)
yield 5
end
end
punctuation = Punctuation.new
# 8: . _ ? ( & : ! )
puts punctuation._?(&:!)
@gabebw
gabebw / hash_quiz.md
Last active August 29, 2015 14:02
Hashes

Hashes

  1. Create a function in Ruby that takes in a hash with fruit names as keys and fruit colors as values (e.g. banana/yellow). The keys should be symbols and the values should be strings. It should then iterate through the hash, printing out e.g. "A banana is yellow", "An apple is red", etc. Your program should create and pass in an example hash, so for example fruit_colors(my_hash). Write out the hash that you're passing in to the function.
@gabebw
gabebw / keybase.md
Created March 26, 2014 18:09
Prove I am who I say I am

Keybase proof

I hereby claim:

  • I am gabebw on github.
  • I am gabebw (https://keybase.io/gabebw) on keybase.
  • I have a public key whose fingerprint is 5C92 A568 C2DB C5B4 3003 943E 82E1 B128 0D95 2DD1

To claim this, I am signing this object:

- (BOOL)hasCards
{
// Is relying on the implicit "NO == 0" ok?
// Should I do `[self.cards count] > 0` instead?
return [self.cards count];
}
@gabebw
gabebw / git-push-git-paid.bash
Created March 17, 2014 03:12
GIT PUSH GIT PAID dot com
#!/bin/bash
# Run this inside a git repo.
# Change name of `origin` remote to `git`
sed -i '' 's/remote "origin"/remote "git"/' .git/config
# Pushing to `paid` means pushing to `master`
# http://stackoverflow.com/questions/549920/is-it-possible-to-alias-a-branch-in-git
git symbolic-ref refs/heads/paid refs/heads/master
@gabebw
gabebw / phantomjs
Last active August 29, 2015 13:56
Workaround for CoreText errors with PhantomJS on OSX 10.9
#!/bin/bash
/usr/local/bin/phantomjs-real $@ 2> >(grep -v CoreText 1>&2)