Skip to content

Instantly share code, notes, and snippets.

View brentd's full-sized avatar

Brent Dillingham brentd

  • Asheville, NC
View GitHub Profile
@brentd
brentd / webmock_stubbing_helper.rb
Created August 2, 2019 16:39
Webmock stubbing helper
# Quick way to log both stubbing instructions and the response of a real request.
# Useful for stubbing real requests without having to resort to VCR.
WebMock.allow_net_connect!
WebMock.after_request do |request_signature, response|
puts "\nA real HTTP request was made."
puts WebMock::RequestSignatureSnippet.new(request_signature).stubbing_instructions
puts "----- RESPONSE HEADERS -----"
@brentd
brentd / bashdb
Created June 26, 2019 14:25
bashdb
#!/bin/bash
DBNAME=${DBNAME:-database}
help() {
echo "A very lol key/value database written in bash.
usage: bashdb <command> <args>
get <key> Get a value from the database
@brentd
brentd / combineLatestActive.js
Last active November 7, 2017 20:41
combineLatestActive: like combineLatest, but for a stream of streams, and only combines non-completed streams
import { Observable } from 'rxjs'
// Takes a higher-order observable as input and subscribes to its inner
// observables. Emits an array containing the last emitted value from each *active*
// inner observable when:
//
// 1. any inner observable emits
// 2. any inner observable completes
//
// In contrast to `combineLatest`, the latest value from completed observables

Three.JS Cubes

@brentd
brentd / gist:5017017
Last active December 14, 2015 02:49
Require outside of bundle
# Allows `require` to work for libs outside of Bundler's environment, so you can require
# gems that aren't in the project's Gemfile while inside an irb session (for example).
if defined?(Gem.post_reset_hooks)
Gem.post_reset_hooks.reject!{ |hook| hook.source_location.first =~ %r{/bundler/} }
Gem::Specification.reset
load 'rubygems/custom_require.rb'
alias gem require
end
@brentd
brentd / _hidpi.scss
Last active December 12, 2015 08:58
SASS/SCSS mixin for hidpi/retina devices. Altered from work by @kaelig: https://github.com/kaelig/hidpi/blob/master/_hidpi.scss
@import 'compass/css3';
// Create a media query for hidpi (retina) devices. If `$image` is provided,
// generates CSS that sets the image as a background for both normal and hidpi
// screens, assuming that the hidpi version ends with `@2x` before the file
// extension. `$extension` must be supplied separately because Sass does not
// yet support string substitution (defaults to png).
//
// Note: assumes a Rails 3.1 environment using the asset pipeline with compass
// installed. Only minimal changes are needed for it to work elsewhere.
@brentd
brentd / gist:4591959
Last active December 11, 2015 11:08
Sublime Text 2 performance on 13" Retina MBP

I love my new 13" rMBP, but there are performance issues here and there - Sublime is definitely one of them. However with a few tweaks I've been able to get performance up to what I would call acceptable.

Steps:

  1. Grab the latest build of Sublime (currently 2219); it has retina fixes. http://www.sublimetext.com/nightly
  2. Install HEAD of the Soda theme (instructions under "Download Manually"): https://github.com/buymeasoda/soda-theme/
  3. Make these tweaks to your User Preferences (cmd-,):
{
@brentd
brentd / spec_helper.rb
Created September 30, 2012 00:09
Useful for monitoring/debugging requests when using VCR
VCR.configure do |c|
c.after_http_request do |request, response|
puts "\n\n#{request.method.upcase} #{request.uri}"
puts
puts caller.grep(/^#{Rails.root}/)
puts
puts request.to_yaml
puts
puts response.to_yaml
end
@brentd
brentd / parallel_asset_compiler.rb
Created July 31, 2012 23:11
Parallelize assets:precompile
require 'parallel' # gem install parallel (https://github.com/grosser/parallel)
# Monkey patch to Sprockets::StaticCompiler, a class provided by actionpack
# that's used by the assets:precompile task. This patch uses the Parallel gem
# to parallelize asset compilation in the simplest way possible.
#
# Parallel wraps Process.fork to handle things like inter-process communication
# via pipes and determining the maximum number of processes to run based on
# your system's total logical processors. So far only tested on MRI 1.9.3 on OS X.
module Sprockets
# encoding: utf-8
module Mongoid #:nodoc:
module Associations #:nodoc:
module EmbeddedCallbacks
# bubble callbacks to embedded assocaitions
def run_callbacks(*args)
# now bubble callbacks down
self.associations.each_pair do |name, meta|
if meta.association == Mongoid::Associations::EmbedsMany