This file contains hidden or 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
| (function($) { | |
| var binder = function(e, dataKey, dataValue) { | |
| var $this = $(this), | |
| oldValue = $this.data(dataKey), | |
| newValue = dataValue, | |
| passed = { | |
| attr: dataKey, | |
| from: oldValue, | |
| to: newValue | |
| }; |
This file contains hidden or 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
| # 1) Point *.example.com in your DNS setup to your server. | |
| # | |
| # 2) Setup an Apache vhost to catch the star pointer: | |
| # | |
| # <VirtualHost *:80> | |
| # ServerName *.example.com | |
| # </VirtualHost> | |
| # | |
| # 3) Set the current account from the subdomain | |
| class ApplicationController < ActionController::Base |
This file contains hidden or 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
| module WillPaginate | |
| module ViewHelpers | |
| def will_paginate_with_collection_check(*args) | |
| # if args.first.respond_to?(:total_pages) doesn't work if using | |
| # with a presenter, since the presenter probably uses method_missing to | |
| # delegate method calls to the collection instance variable | |
| if (args.first.total_pages rescue false) | |
| will_paginate_without_collection_check(*args) | |
| end |
This file contains hidden or 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 hidden or 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, |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |