Skip to content

Instantly share code, notes, and snippets.

View joshuaclayton's full-sized avatar

Josh Clayton joshuaclayton

View GitHub Profile
alias ..='cd ../'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias .......='cd ../../../../../..'
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
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';
>> class Person
>> def age
>> self.calculate_age
>> end
>>
?> def calculate_age
>> 'age from person'
>> end
>> end
=> nil
# 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 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
#
#!/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"
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
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'
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,