Skip to content

Instantly share code, notes, and snippets.

View beanieboi's full-sized avatar

Ben Fritsch beanieboi

View GitHub Profile
def house_id
@house_id
end
def house_id=house_id
@house_id = house_id
end
def room_number
if !self.room.nil?
# traceroute6 chaosbay.hq.c3d2.de
traceroute6: Warning: chaosbay.hq.c3d2.de has multiple addresses; using 2001:6f8:1194:c3d2:a800:5bff:fe08:f05b
traceroute6 to chaosbay.hq.c3d2.de (2001:6f8:1194:c3d2:a800:5bff:fe08:f05b) from 2002:8d1e:cc52::21e:c2ff:fea4:da2f, 64 hops max, 12 byte packets
1 2002:8d1e:cc52::224:36ff:fea0:cb6b 1.715 ms 0.749 ms 0.680 ms
2 * * *
3 2001:638:c:c049::2 10.652 ms 10.853 ms 10.198 ms
4 zr-fra1-te0-7-0-4.x-win.dfn.de 14.843 ms 15.287 ms 14.243 ms
5 fe0-1-2-0.br1.ixfra.de.easynet.net 24.755 ms 25.033 ms 24.612 ms
6 2001:6f8:1::87:86:77:246 24.473 ms 24.270 ms 24.141 ms
7 2001:6f8:1::87:86:71:229 87.788 ms 302.628 ms 229.181 ms
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 :|
var file = fs.createReadStream(path);
var sha1_for_file = crypto.createHash('sha1');
file.addListener('error', function(err) {
throw err;
});
file.addListener('data', function(data) {
sha1_for_file.update(data);
});
file.addListener('close', function() {
@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