Skip to content

Instantly share code, notes, and snippets.

Alexa, ask the future of America to be great again! (try it)

Daniel (dB.) Doubrovkine dblock

Alexa, ask the future of America to be great again! (try it)
View GitHub Profile
dblock / tags-mapreduce-mongodb-inline.rb
Created May 12, 2011
Improving tags map/reduce with MongoDB 1.8.x
View tags-mapreduce-mongodb-inline.rb
class Tag
include Mongoid::Document
def self.rebuild
tags_before = Hash[ * Tag.all.collect { |tag|
[, tag]
map = <<-EOS
function() {
dblock / delayed_jobs_controller.rb
Created Jun 4, 2011
Delayed job view and controller
View delayed_jobs_controller.rb
class Admin::DelayedJobsController < AdminController
# GET /admin/delayed_jobs
def index
@delayed_jobs = Delayed::Backend::Mongoid::Job.desc(:created_at)
.paginate :page => params[:page], :per_page => 20
dblock / without_callbacks.rb
Created Jun 4, 2011
Suppress ActiveSupport callbacks
View without_callbacks.rb
module ActiveSupport::Callbacks::ClassMethods
def without_callbacks(callbacks, &block)
saved = {}
callbacks.each do |callback|
saved[callback] = instance_method(callback)
remove_method(callback) if respond_to?(callback)
define_method(callback){ true }
dblock /
Created Jun 9, 2011
Delete merged git branches.
git branch --merged | grep -v master | xargs git branch -d
git branch -r --merged | awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' | xargs git push origin --delete
dblock / getWeek.js
Created Jul 13, 2011
get week of the year in JavaScript
View getWeek.js
function( d ) {
// Create a copy of this date object
var target = new Date(d.valueOf());
// ISO week date weeks start on monday
// so correct the day number
var dayNr = (d.getDay() + 6) % 7;
// Set the target to the thursday of this week so the
dblock / kaminari.rb
Created Jul 28, 2011
Kaminari pagination information.
View kaminari.rb
# see and
module Kaminari
# = Helpers
module ActionViewExtension
extend ::ActiveSupport::Concern
module InstanceMethods
def page_entries_info(collection, options = {})
collection_name = options[:collection_name] || (collection.empty?? 'entry' :'_', ' '))
if collection.num_pages < 2
dblock / capybara-448-selenium.rb
Created Aug 16, 2011
Selenium Webdriver dropdown selection
View capybara-448-selenium.rb
require 'rubygems'
require 'selenium-webdriver'
path = File.expand_path("test.html"), "w") { |io| io << }
browser = Selenium::WebDriver.for :firefox # replace :firefox with the browser you're having trouble with
browser.get "file://#{path}"
dblock / spreadsheet_encodings.rb
Created Sep 1, 2011
Spreadhseet encodings monkey-patch, fixes "can't modify a frozen string" error.
View spreadsheet_encodings.rb
# monkey patch frozen string bug, see
module Spreadsheet
module Encodings
def client string, internal='UTF-16LE'
string = string.dup
string.force_encoding internal
string.encode Spreadsheet.client_encoding
def internal string, client=Spreadsheet.client_encoding
string = string.dup
dblock / jade-pseudo-upper.pas
Created Sep 6, 2011
An obscure piece of code from Jade, 1997
View jade-pseudo-upper.pas
function TJadeMainForm.PseudoUpper(iStr: string): string;
stNum: string;
stDes: string;
stNam: string;
stPre: string;
stTmp: string;
if JadeTable.State <> dsEdit then JadeTable.Edit;
iStr := Trim(LowerCase(iStr));
View new_relic_agent_instrumentation_api.rb
if Rails.env.production?
require 'new_relic/agent/instrumentation/controller_instrumentation'
module NewRelic
module Agent
module Instrumentation
module API
def newrelic_request_headers