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 TrueFalseComparison | |
def <=>(other) | |
return nil if ![TrueClass, FalseClass].include?(other.class) | |
self.is_a?(FalseClass) ? (other.is_a?(TrueClass) ? -1 : 0) : (other.is_a?(FalseClass) ? 1 : 0) | |
end | |
end | |
TrueClass.send(:include, TrueFalseComparison) | |
FalseClass.send(:include, TrueFalseComparison) | |
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 Statistic < ActiveRecord::Base | |
named_scope :by_month_and_year, :select => "DATE_FORMAT(created_at, '%b %y')", :group => "DATE_FORMAT(created_at, '%b %y')", :order => :created_at | |
end | |
>> Statistic.by_month_and_year.size | |
=> 6 # SELECT count(DATE_FORMAT(created_at, '%b %y')) AS count_date_format_created_at_b_y FROM `statistics` | |
>> Statistic.by_month_and_year.all.size | |
=> 5 # SELECT DATE_FORMAT(created_at, '%b %y') FROM `statistics` GROUP BY DATE_FORMAT(created_at, '%b %y') ORDER BY created_at |
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
# Put this in your app config to omit the div that wraps error fields in form_for | |
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag } |
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
describe String do | |
describe "#increment and #increment!" do | |
it 'should increment nothing to 1' do | |
"Something".increment.should == "Something1" | |
end | |
it 'should increment the digits in the string' do | |
"789".increment.should == "790" | |
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
def loggable(logger) | |
@@logger = logger | |
def method_missing(meth, *args) | |
if meth.to_s =~ /^log_/ | |
@@logger.info "#{Time.now.to_s} - #{meth.to_s.split('_')[1..-1].join(' ')}" | |
else | |
super | |
end | |
end | |
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
# Rails 2.3.2 | |
# Ruby 1.8.6 | |
# Appears to be weirdness when you override a class method that | |
# is also a method_missing finder. Check out the SQL output: | |
class CreatePosts < ActiveRecord::Migration | |
def self.up | |
create_table :posts, :force => true do |t| | |
t.string :title | |
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
response body => \037\213\b\000\000\000\000\000\000\0033624550\006\000,/\327T\a\000\000\000 | |
net/http interpretation => 3624550,/?T | |
response body => \037\213\b\000\000\000\000\000\000\0033624550\001\000\217\272\263\312\a\000\000\000 | |
net/http interpretation => 3624550???? | |
response body => \037\213\b\000\000\000\000\000\000\0033624550\005\000\031\212\264\275\a\000\000\000 | |
net/http interpretation => 3624550??? | |
response body => \037\213\b\000\000\000\000\000\000\0033624550\a\0005\353\272S\a\000\000\000 |
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
var λ = function(k){var a=[];while(a.length+1<arguments.length){a.push(arguments[a.length+1])};return function(o){return((o[k]&&o[k]instanceof Function)?o[k].apply(this,a):o[k]);}}; | |
var ary = [ | |
{num:1, f:function(a,b,c){console.log("A: " + a + "," + b + "," + c);}}, | |
{num:2, f:function(a,b,c){console.log("B: " + a + "," + b + "," + c);}}, | |
{num:3, f:function(a,b,c){console.log("C: " + a + "," + b + "," + c);}} | |
]; | |
ary.forEach(λ('f',1,2,3)); | |
# => A: 1,2,3 |
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
// http://localhost:60210/api/?qid=anvil_songofpain_backtobasics&poll=2&call_id=1273084702020&method=get_results&auth=0D85A28B-BBDA-4F26-96E6-4FAEA0421A0E&jsonp=Playdar.client.handle_results | |
Playdar.client.handle_results({"qid":"anvil_songofpain_backtobasics","poll_interval":1000,"poll_limit":6,"query":{"artist":"Anvil","album":"Back to Basics","track":"Song Of Pain"},"solved":false,"results":[{"sid":"2C2556F9-FFB2-4BBA-93F1-9A8EEA93B058","artist":"Anvil","track":"Keep It Up","album":"Back To Basics","mimetype":"audio/mpeg","score":0.6666666666666666,"duration":230,"bitrate":234,"size":2097152,"source":"tieg-zaharia"}]}); | |
// http://localhost:60210/api/?qid=anvil_keepitup_backtobasics&poll=1&call_id=1273084700988&method=get_results&auth=0D85A28B-BBDA-4F26-96E6-4FAEA0421A0E&jsonp=Playdar.client.handle_results | |
Playdar.client.handle_results({"qid":"anvil_keepitup_backtobasics","poll_interval":1000,"poll_limit":6,"query":{"artist":"Anvil","album":"Back to Basics","track":"Keep it Up"},"solved":true,"results":[{ |
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
{ scopeName = 'source.js'; | |
comment = 'JavaScript Syntax: version 2.0'; | |
fileTypes = ( 'js', 'htc', 'jsx' ); | |
foldingStartMarker = '^.*\bfunction\s*(\w+\s*)?\([^\)]*\)(\s*\{[^\}]*)?\s*$'; | |
foldingStopMarker = '^\s*\}'; | |
patterns = ( | |
{ name = 'meta.class.js'; | |
comment = 'match stuff like: Sound.prototype = { … } when extending an object'; | |
match = '([a-zA-Z_?.$][\w?.$]*)\.(prototype)\s*(=)\s*'; | |
captures = { |
OlderNewer