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
@dblock
dblock / api_logger.rb
Created December 10, 2012 01:43
API logger with Grape under Rails
class ApiLogger < Grape::Middleware::Base
def before
Rails.logger.info "[api] Requested: #{request_log_data.to_json}\n" +
"[api] #{response_log_data[:description]} #{response_log_data[:source_file]}:#{response_log_data[:source_line]}"
end
private
def request_log_data
@dblock
dblock / dropbox.sh
Last active September 11, 2020 14:46
Auto-start Dropbox.
#!/bin/bash
DROPBOX_USERS="root"
DAEMON=.dropbox-dist/dropboxd
start() {
echo "Starting dropbox..."
for dbuser in $DROPBOX_USERS; do
HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
@dblock
dblock / git-delete-merged-branches.sh
Created June 9, 2011 21:12
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
dblock / dokku-mongo-export.sh
Last active June 11, 2020 12:20
Backup MongoDB databases with Dropbox and Dokku
#!/bin/bash
set -e
echo "Backing up MongoDB databases to Dropbox ..."
dt=$(date +"%Y-%m-%d")
echo " today is $dt"
@dblock
dblock / api_page_helper.rb
Created November 2, 2011 23:08
pagination helper with Grape
module ApiPageHelper
PAGINATE_OPTIONS = {
:default_page_size => 10
}
PAGINATE_PARAMS = [ "page", "offset", "size" ]
def paginate(coll, options = {})
options = PAGINATE_OPTIONS.merge(options)
if params[:page]
page = params[:page].to_i
size = (params[:size] || options[:default_page_size]).to_i
@dblock
dblock / grape-rackup-with-static.rb
Created February 20, 2012 17:53
Rackup static pages along with a Grape API, inspired by Rack::TryStatic
class App
def initialize(options)
@try = ['', *options.delete(:try)]
@static = ::Rack::Static.new(
lambda { [404, {}, []] },
options)
end
def call(env)
/*
Create Element:
$Rainb.el('div',{'attribute':"value",style:{"color":"red"}},[ (childnodes) ])
becomes: <div attribute="value" style="color: red;"></div>
Append Element
$Rainb.add(element,elementToAppend)
Get Element By Id
$Rainb.id(id);
Create TextNode
$Rainb.tn(text);
@dblock
dblock / ActiveDirectoryDecoratorFilter.java
Created June 27, 2012 13:31
Obtain additional user information from ActiveDirectory using Com4J
//
// from http://waffle.codeplex.com/workitem/10034
//
package waffle.servlet.spi;
import java.io.IOException;
import java.security.Principal;
import java.util.Date;
import java.util.Enumeration;
@dblock
dblock / failures_formatter.rb
Created May 4, 2012 19:52
RSpec tests broken up into suites with retry.
# inspired by https://github.com/rspec/rspec-core/pull/596
require 'rspec/core/formatters/base_formatter'
module RSpec
module Core
module Formatters
class FailuresFormatter < BaseFormatter
def dump_failures
return if failed_examples.empty?
@dblock
dblock / assert_url_helper.rb
Last active September 18, 2018 03:47
A monkey patch for serving compressed assets for Rails 3.0 (asset_tag_helper.rb) and another for Rails 3.1 (asset_paths.rb).
# Rails 4
require 'action_view/helpers/asset_url_helper'
module ActionView
module Helpers
module AssetUrlHelper
def accept_encoding?(encoding)
request = self.request if respond_to?(:request)
return false unless request