Skip to content

Instantly share code, notes, and snippets.

@coryf
coryf / screenshot.rb
Last active August 29, 2015 13:57
Poltergeist RSpec screenshot
# spec/support/screenshot.rb
RSpec.configure do |config|
# A work-around to support accessing the current example that works in both
# RSpec 2 and RSpec 3.
fetch_current_example = RSpec.respond_to?(:current_example) ?
proc { RSpec.current_example } : proc { |context| context.example }
config.after do
example = fetch_current_example.call(self)
@coryf
coryf / bootstrap_alert_helper.rb
Created May 23, 2014 15:38
Bootstrap alert Rails helpers
def bootstrap_alert(type, message, options = {})
options.reverse_merge!(dismissable: true)
classes = %w(alert)
classes << case type
when :error, :alert
'alert-danger'
else
'alert-info'
end
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# Forces all threads to share the same connection. This works on
@coryf
coryf / .profile
Created November 30, 2011 22:09
Cory's Prompt
Green="\033[0;32m"
Yellow="\033[0;33m"
Blue="\033[0;34m"
Red="\033[0;31m"
GreyB="\033[1;30m"
Normal="\033[0m"
smiley() {
ret_val=$?
if [ "$ret_val" = "0" ]
@coryf
coryf / sinatra_proxy.rb
Created July 20, 2012 14:02
Sinatra POST/GET Proxy using RestClient
# POST proxy
post '/api/*' do
splat = params.delete('splat')
RestClient.post "http://#{@dest_host_port}/#{splat}", params
end
# GET proxy
get '/api/*' do
splat = params.delete('splat')
RestClient.get "http://#{@dest_host_port}/#{splat}", :params => params
@coryf
coryf / .vimrc
Last active October 11, 2015 09:17
Vim setup with plugin update script
set nocompatible " We don't want vi compatibility.
set guifont=Menlo\ For\ Powerline:h10
set guioptions-=m " No menu
set guioptions-=T " No toolbar
set guioptions+=c " Use console dialogs where possible
set modelines=0
set encoding=utf-8 " Necessary to show Unicode glyphs
var _ = require('underscore');
var config = require('../config');
var envPrefix = 'PREFIX_'
var envPrefixLen = envPrefix.length;
var envKeys = _.chain(config.base).keys().map(function(key){return envPrefix + key;}).value();
var procEnvOverrides = {};
@coryf
coryf / deep_munge_fix.rb
Created May 26, 2014 00:51
Rails deep_munge patch
# This is a monkey patch to fix the Rails deep_munge issue described here:
# https://github.com/rails/rails/issues/13420
#
# Rails converts incoming empty array params into nils. This patch reverts that.
# This goes in /config/initializers
#
# Before patch:
#
# | JSON | Hash |
# |----------------------------------|-------------------------|
@coryf
coryf / Dockerfile
Created September 1, 2016 15:53
Phoenix + Docker Compose + Live Reload
# Starting from the official Elixir 1.3.2 image:
# https://hub.docker.com/_/elixir/
FROM elixir:1.3.2
# Based off of a Dockerfile by David Anguita <david@davidanguita.name>
MAINTAINER Cory Fabre <cfabre@gmail.com>
ENV DEBIAN_FRONTEND=noninteractive
# Install hex
@coryf
coryf / .tmux.conf
Created December 21, 2016 16:34
tmux battery status
# clone https://github.com/tmux-plugins/tmux-battery to <tmux-battery-path>
# add to .tmux.conf:
set -g status-right "#[fg=yellow]#(date +'%a %d') #[fg=green]#(date +'%I:%M%p')#[fg=white] #[bg=black] #{battery_percentage} #{battery_icon} "
set -g @batt_charged_icon "🔌"
set -g @batt_charging_icon "⚡"
set -g @batt_discharging_icon "🔋"
set -g @batt_attached_icon "⚠️"