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
require 'spec_helper'
require 'grape'
module DATA
class User
attr_accessor :loginname, :email, :person
def initialize(attrs)
@loginname = attrs[:loginname]
@email = attrs[:email]
@dblock
dblock / capybara_wait_until.rb
Created July 24, 2013 07:38
Re-implementation of Capybara wait_until.
class Capybara::Session
def wait_until(timeout = Capybara.default_wait_time)
Timeout.timeout(timeout) do
sleep(0.1) until value = yield
value
end
end
end
@dblock
dblock / gist:5777415
Created June 13, 2013 21:12
Git push to Heroku with a segfault during asset compilation.
[2013-06-13 20:40:48 +0000] git push -f git@heroku.com:gravity-production.git FETCH_HEAD:master
Warning: Permanently added the RSA host key for IP address '50.19.85.154' to the list of known hosts.
-----> Deleting 13 files matching .slugignore patterns.
-----> Ruby/Rails app detected
-----> Using Ruby version: ruby-1.9.3
-----> Installing dependencies using Bundler version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
find: `spec': No such file or directory
find: `bin': No such file or directory
@dblock
dblock / snapshot_names.cs
Created April 1, 2013 12:55
Get the list of snapshots using VMWareTasks.
private List<string> GetSnapshotNames(IEnumerable<VMWareSnapshot> snapshots)
{
List<string> result = new List<string>();
foreach (VMWareSnapshot snapshot in snapshots)
{
result.Add(snapshot.DisplayName);
result.AddRange(GetSnapshotNames(snapshot.ChildSnapshots));
}
return result;
}
@dblock
dblock / svn2svn-sample.txt
Created March 30, 2013 19:58
Run sv2svn, revision 2 to 136.
C:\>Svn2Svn.exe /source:c:\source\dni\trunk /destination:c:\Users\dblock\Source\CodePlex\Dni\trunk -r:2:136 -prompt
Svn2Svn: 1.0.12089.0
From: c:\source\dni\trunk
To: c:\Users\dblock\Source\CodePlex\Dni\trunk
Collecting svn log: 2:136 Source SVN root: https://dotnetinstaller.svn.sourceforge.net/svnroot/dotnetinstaller/
Source SVN uri: https://dotnetinstaller.svn.sourceforge.net/svnroot/dotnetinstaller/trunk/
Relative path: /trunk/
.........................................................................................................
Collected 105 revisions.
Revision 2 (11/27/2006 6:42:51 PM)
@dblock
dblock / debug_require.rb
Created February 18, 2013 22:10
Measure how long require(s) take.
if ENV['DEBUG_REQUIRE']
require 'benchmark'
def require(file)
@@first ||= Time.now
rc = false
ts = Benchmark.measure do
rc = super
end
if ENV['DEBUG_REQUIRE'].to_f < ts.total
@dblock
dblock / thin_connection.rb
Created February 16, 2013 16:28
Instrument thin to measure wait time inside its internal queue.
module Thin
class Connection < EventMachine::Connection
attr_accessor :init_ts, :data_ts
def initialize
super
@init_ts = Time.now
Gravity.metrics.increment 'thin.connection'
end
@dblock
dblock / mongoid_paginate_by_cursor_helper.rb
Created February 14, 2013 14:53
A way to paginate "by cursor" with mongoid.
def cursor_and_tiebreak_id_from_params(options = {})
cursor, tiebreak_id = nil
if params[:cursor]
raw_cursor = params[:cursor].split(":")[0...-1].join(":")
cursor = (options[:field_type] == String ? raw_cursor : raw_cursor.to_i)
tiebreak_id = params[:cursor].split(":")[-1]
elsif options[:default_cursor]
cursor = (options[:field_type] == String ? options[:default_cursor] : options[:default_cursor].to_i)
end
[ cursor, tiebreak_id ]
@dblock
dblock / find_corrupted_mongoid_embedded_items.rb
Created February 2, 2013 20:17
Find corrupted MongoDB embedded items inside multiple collections. Code from @macreery.
summary_totals = {}
summary_totals.default = 0
count = 0
{
Collection => :items,
Artwork => :images
}.each do |coll, orderable_subcoll|
coll.all.each do |item|
$stdout.write "." if count % 1000 == 0
count += 1
@dblock
dblock / deep_zoom.rb
Last active December 11, 2015 17:48
Tile images for SeaDragon.
# MIT License (c) Artsy Inc. 2013
# Deep Zoom module for generating Deep Zoom (DZI) tiles from a source image
# Borrows heavily from https://github.com/meso-unimpressed/deep_zoom_slicer
module DeepZoom
extend ActiveSupport::Concern
# Defaults
DEFAULT_TILE_SIZE = 512