Skip to content

Instantly share code, notes, and snippets.

View dblock's full-sized avatar
🐝
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

Keybase proof

I hereby claim:

  • I am dblock on github.
  • I am dblock (https://keybase.io/dblock) on keybase.
  • I have a public key whose fingerprint is 4A72 0FE7 90B0 7A68 744E 3716 75BF 031B 7C94 E183

To claim this, I am signing this object:

require 'mongoid'
require 'mongoid_collection_snapshot'
Mongoid.load!("mongoid.yml", :development)
class Widget
include Mongoid::Document
end
@dblock
dblock / Gemfile
Created May 15, 2015 19:51
Grape on Goliath
source 'https://rubygems.org'
gem 'grape'
gem 'goliath'
gem 'json'
@dblock
dblock / tags-mapreduce-mongodb-inline.rb
Created May 12, 2011 13:45
Improving tags map/reduce with MongoDB 1.8.x
class Tag
include Mongoid::Document
def self.rebuild
tags_before = Hash[ * Tag.all.collect { |tag|
[tag.name, tag]
}.flatten]
map = <<-EOS
function() {
@dblock
dblock / delayed_jobs_controller.rb
Created June 4, 2011 20:06
Delayed job view and controller
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
end
end
@dblock
dblock / without_callbacks.rb
Created June 4, 2011 20:08
Suppress ActiveSupport callbacks
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 }
end
begin
@dblock
dblock / kaminari.rb
Created July 28, 2011 13:50
Kaminari pagination information.
# see https://github.com/amatsuda/kaminari/issues/56 and https://github.com/amatsuda/kaminari/pull/140
module Kaminari
# = Helpers
module ActionViewExtension
extend ::ActiveSupport::Concern
module InstanceMethods
def page_entries_info(collection, options = {})
collection_name = options[:collection_name] || (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
if collection.num_pages < 2
@dblock
dblock / capybara-448-selenium.rb
Created August 16, 2011 14:45
Selenium Webdriver dropdown selection
require 'rubygems'
require 'selenium-webdriver'
path = File.expand_path("test.html")
File.open(path, "w") { |io| io << DATA.read }
browser = Selenium::WebDriver.for :firefox # replace :firefox with the browser you're having trouble with
begin
browser.get "file://#{path}"
@dblock
dblock / spreadsheet_encodings.rb
Created September 1, 2011 23:15
Spreadhseet encodings monkey-patch, fixes "can't modify a frozen string" error.
# monkey patch frozen string bug, see https://github.com/dblock/spreadsheet/commit/164dcfbb24097728f1a7453702c270107e725b7c
module Spreadsheet
module Encodings
def client string, internal='UTF-16LE'
string = string.dup
string.force_encoding internal
string.encode Spreadsheet.client_encoding
end
def internal string, client=Spreadsheet.client_encoding
string = string.dup
@dblock
dblock / jade-pseudo-upper.pas
Created September 6, 2011 02:28
An obscure piece of code from Jade, 1997
function TJadeMainForm.PseudoUpper(iStr: string): string;
var
stNum: string;
stDes: string;
stNam: string;
stPre: string;
stTmp: string;
begin
if JadeTable.State <> dsEdit then JadeTable.Edit;
iStr := Trim(LowerCase(iStr));