Skip to content

Instantly share code, notes, and snippets.

View beanieboi's full-sized avatar

Ben Fritsch beanieboi

View GitHub Profile
x^0 -> 1 0 0
x^1 -> 0 1 0
x^2 -> 0 0 1
x^3 -> 2 0 1
x^4 -> 2 2 1
x^5 -> 2 2 0
x^6 -> 0 2 2
x^7 -> 1 0 1
x^8 -> 2 1 1
x^9 -> 2 2 2
DELETE FROM traffics WHERE created_at < (CURDATE()-30)
DELETE FROM traffics WHERE created_at < DATE_SUB(NOW(), INTERVAL 1 MONTH)
DELETE FROM traffics WHERE created_at < '2010-01-01 00:00:00'
nothing works :|
AllCops:
Exclude:
- config/**/*
- db/**/*
Metrics/LineLength:
Description: 'Limit lines to 120 characters.'
Max: 120
Metrics/CyclomaticComplexity:
@beanieboi
beanieboi / mongoid version diff
Created January 26, 2011 13:13
shows the diff between two versions when you use Mongoid::Versioning
def compare_to(version)
reject_fields = ["_id", "updated_at", "version"]
diff_array = self.versions[version-1].attributes.to_hash.to_a - self.attributes.to_hash.to_a
diff_array.delete_if {|f| reject_fields.include?(f.first) }
Hash[diff_array]
end
scope :case_insensitive_email, lambda { |email| where("email ILIKE ?", email) }
request parameters: {"email"=>"foo\\"}
PGError: ERROR: LIKE pattern must not end with escape character
: SELECT "users".* FROM "users" WHERE (email ILIKE 'foo\') LIMIT 1
@beanieboi
beanieboi / resque.rb
Created September 22, 2011 13:42 — forked from bitbckt/resque.rb
munin plugin for resque
#!/usr/bin/env ruby
require 'rubygems'
require 'resque'
HOST = ENV['host'] ? ENV['host'] : '127.0.0.1'
PORT = ENV['port'] ? ENV['port'] : '6379'
Resque.redis = "#{HOST}:#{PORT}"
@beanieboi
beanieboi / resque.rb
Created November 2, 2011 18:38 — forked from bitbckt/resque.rb
munin plugin for resque
#!/usr/bin/env ruby
require 'rubygems'
require 'resque'
HOST = ENV['host'] ? ENV['host'] : '127.0.0.1'
PORT = ENV['port'] ? ENV['port'] : '6379'
Resque.redis = "#{HOST}:#{PORT}"
@beanieboi
beanieboi / tracking_controller.rb
Created February 15, 2012 14:57
Rails Metal DataStreaming broken?!
class Api::V1::OpenRateController < ActionController::Metal
include ActionController::DataStreaming
def show
tracking_gif = "GIF89a\x03\x00\x02\x00\x80\x00\x00\xC0\xC0\xC0\x00\x00\x00!\xF9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x03\x00\x02\x00\x00\x02\x02\x84_\x00;".freeze
send_data tracking_gif
end
end
cd tmp/x86_64-darwin11.3.0/ruby_mapnik/1.9.3
make
compiling ../../../../ext/ruby_mapnik/_mapnik_feature.rb.cpp
cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++
In file included from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/../to_from_ruby.hpp:5,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/Auto_Function_Wrapper.ipp:12,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/Auto_Function_Wrapper.hpp:826,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/wrap_function.ipp:10,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/wrap_function.hpp:338,
@beanieboi
beanieboi / gist:2717328
Created May 17, 2012 08:12
Mapnik build error
cd tmp/x86_64-darwin11.3.0/ruby_mapnik/1.9.3
make
compiling ../../../../ext/ruby_mapnik/_mapnik_feature.rb.cpp
cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++
In file included from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/../to_from_ruby.hpp:5,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/Auto_Function_Wrapper.ipp:12,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/Auto_Function_Wrapper.hpp:826,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/wrap_function.ipp:10,
from /Users/ben/.rvm/gems/ruby-1.9.3-p194@mapnik/gems/rice-1.4.3/ruby/lib/include/rice/detail/wrap_function.hpp:338,