This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias ..='cd ../' | |
alias ...='cd ../..' | |
alias ....='cd ../../..' | |
alias .....='cd ../../../..' | |
alias ......='cd ../../../../..' | |
alias .......='cd ../../../../../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "handling actions when a user doesn't have access" do | |
def before_each | |
login_with(:sales_rep) | |
@quote = mock("QuotePresenter", :current_user_has_access? => false, :full_name => "test") | |
QuotePresenter.stub!(:new).and_return(@quote) | |
current_user.stub!(:quotes).and_return([@quote]) | |
current_user.quotes.stub!(:find).and_return(@quote) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $break = { }; | |
Object.extend = function(destination, source) { | |
for (var property in source) | |
destination[property] = source[property]; | |
return destination; | |
}; | |
Object.extend(Object, { | |
inspect: function(object) { | |
try { | |
if (Object.isUndefined(object)) return 'undefined'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> class Person | |
>> def age | |
>> self.calculate_age | |
>> end | |
>> | |
?> def calculate_age | |
>> 'age from person' | |
>> end | |
>> end | |
=> nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This could be used to generate a list of first-order URLs that should be unavailable | |
# to a model if you're going to follow the routing convention of site.com/:slug | |
# Obviously, if you namespace the site, you're going to want to modify the index of 'segments' | |
ActionController::Routing::Routes.routes.map {|c| c.segments[1].value if c.segments[1]}.compact.uniq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This would go within your ~/.irbrc file | |
# | |
# The idea behind this is that you can store blocks of code not within clipboard or a | |
# misc. file, but within IRB, when hacking at code | |
# | |
# Snip is a singleton class that holds all your snippets for the current session | |
# An instance method 'snip' was also added to Object to allow for super-simple snip creation | |
# | |
# Here's a demo from IRB | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
branch=$(git branch 2>/dev/null | grep ^\*) | |
[ x$1 != x ] && tracking=$1 || tracking=${branch/* /} | |
git config branch.$tracking.remote origin | |
git config branch.$tracking.merge refs/heads/$tracking | |
echo "tracking origin/$tracking" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def slide(direction) | |
case direction.to_sym | |
when :left | |
self << self.shift | |
when :right | |
self.insert 0, self.pop | |
else | |
raise "Unknown direction" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT s.* | |
FROM scores s | |
JOIN ( | |
SELECT MAX(s1.score_value) AS score_value, s1.user_id | |
FROM scores s1 | |
JOIN companies c1 ON c1.id = s1.company_id | |
WHERE s1.company_id = 8 AND s1.status = 'validated' | |
GROUP BY s1.user_id | |
) AS high_scores ON high_scores.user_id = s.user_id AND high_scores.score_value = s.score_value | |
WHERE s.company_id = 8 AND s.status = 'validated' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Generate | |
def self.user(attributes = {}) | |
key = ActiveSupport::SecureRandom.hex(16) | |
user = User.new(attributes.reverse_merge({ | |
:first_name => "John", | |
:last_name => "Doe", | |
:password => "password", | |
:password_confirmation => "password", | |
:active => true, |