Skip to content

Instantly share code, notes, and snippets.

View jimmycuadra's full-sized avatar
☠️
GitHub profits from the separation of families and the deaths of children.

jimmycuadra

☠️
GitHub profits from the separation of families and the deaths of children.
View GitHub Profile
@jimmycuadra
jimmycuadra / bashrc
Created November 9, 2010 05:55
My bashrc config
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
e=`printf "\033"`
end="$e[0m"
red="$e[1;31m"
green="$e[1;32m"
yellow="$e[1;33m"
@jimmycuadra
jimmycuadra / gist:765942
Created January 5, 2011 04:49
Discography: An exercise to learn some basic Ruby
# Write some classes to keep track of an artist's discography. Start by creating an
# artist, then an album, then songs. Add songs to the album and then add the
# album to the artist. Finally, call the discography method on the artist
# to print out a nice formatted string detailing that artist's discography.
# You should be able to use it like this:
nebyoolae = Artist.new('Nebyoolae')
cs13 = Album.new('Clocks Striking 13')
@jimmycuadra
jimmycuadra / gist:768450
Created January 6, 2011 19:45
Solution to "Discography: An exercise to learn some basic Ruby" https://gist.github.com/765942
class Artist
attr_reader :name
attr_accessor :albums
def initialize(name)
@name = name
@albums = []
end
@jimmycuadra
jimmycuadra / gist:771433
Created January 9, 2011 05:03
Accessing a model attribute inside an ActiveRecord callback
class Foo < ActiveRecord::Base
# assume Foo has an attribute called "title"
before_save :my_callback
def my_callback
self.title = "Prefix: #{self.title}" # this doesn't work if you remove "self" - why?
end
end
@jimmycuadra
jimmycuadra / gist:856867
Created March 6, 2011 00:26
Jimmy's wish list

Jimmy's wish list

  • Threadless gift certificates
  • iTunes store credit
@jimmycuadra
jimmycuadra / gist:866770
Created March 11, 2011 23:08
Generate empty string padded arrays of digits from 1 to 6 digits with equal probability for each number of digits
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function getRandomDemandCountArray() {
var demandCount,
digitCount = getRandomInt(1, 6),
maxDigits = 6,
demandCountArray = [];
@jimmycuadra
jimmycuadra / gist:869577
Created March 14, 2011 18:16
Determining which ancestor defines a particular method
# determining where a method was defined
module Organic
def organic?
true
end
end
class Fruit
def edible?
@jimmycuadra
jimmycuadra / gist:887126
Created March 25, 2011 16:22
Oops, my commit should have been on a branch
[rvm 1.9.2] ~/Code $ mkdir gittest
[rvm 1.9.2] ~/Code $ cd gittest/
[rvm 1.9.2] ~/Code/gittest $ git init
Initialized empty Git repository in /Users/jimmy/Code/gittest/.git/
[rvm 1.9.2] ~/Code/gittest (master)$ touch foo
[rvm 1.9.2] ~/Code/gittest (master)$ git add foo
[rvm 1.9.2] ~/Code/gittest (master)$ git ci -a -m "initial commit"
[master (root-commit) 700ec02] initial commit
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 foo
@jimmycuadra
jimmycuadra / gist:920203
Created April 14, 2011 18:52
Clear defaults before submitting
// http://jimmycuadra.com/posts/screencast-default-form-values-with-jquery
$('form').submit(function (evt) {
$(evt.currentTarget).find('input, textarea').each(function (index, element) {
var $element = $(element);
if ($element.val() == $element.data('default')) {
$element.val('');
}
});
@jimmycuadra
jimmycuadra / A Lock on the Door.textile
Created May 27, 2011 09:10
Altered Perception lyrics

A Lock on the Door (2001)

Melt

When it gets to the point I can’t control
I feel so small
The hole left unfulfilled again

You’re my only one
And salvation feels so far away