Skip to content

Instantly share code, notes, and snippets.

View brianjlandau's full-sized avatar

Brian Landau brianjlandau

  • Walnut Creek, CA
View GitHub Profile
@brianjlandau
brianjlandau / .babelrc
Last active March 29, 2018 07:41
Rails 5.1 webpacker config for react + jest + enzyme
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},

Keybase proof

I hereby claim:

  • I am brianjlandau on github.
  • I am brianjlandau (https://keybase.io/brianjlandau) on keybase.
  • I have a public key ASADZdepX0J5-Vj2nmxaby26kkElaVpSHeHAW6n6Hg3j_Qo

To claim this, I am signing this object:

/*
DatePicker v4.4 by frequency-decoder.com
- This is a revised version that works with jQuery 1.2.6 as I found the original didn't work properly.
Released under a creative commons Attribution-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-sa/2.5/)
Please credit frequency-decoder in any derivative work - thanks.
You are free:
#!/usr/bin/env bash
if [ ${#1} -eq 0 ]
then echo "Error: Please supply a URL"; exit 1;
fi
ENCODING_HEADER=$(curl --silent -I $1 -H "Accept-Encoding: gzip,deflate" | tr -d '\r' | sed -En 's/^Content-Encoding: (.+)$/\1/p')
if [ "$ENCODING_HEADER" == "gzip" ]
then echo "GZIP: Enabled"
@brianjlandau
brianjlandau / sti_nested_attributes_association_builder.rb
Created March 25, 2016 18:19
This can be used so that when building records via nested attributes the correct subclass is used when creating the record.
ActiveRecord::Reflection::AbstractReflection.class_eval do
def build_association(*options, &block)
attributes = if options.first.is_a?(Hash)
options.first.with_indifferent_access
end
if attributes && attributes[:type].present?
attributes[:type].constantize.new(*options, &block)
else
klass.new(*options, &block)
# History control
HISTFILESIZE=100000
export HISTFILESIZE
HISTSIZE=100000
export HISTSIZE
HISTCONTROL=ignoredups:erasedups
export HISTCONTROL
shopt -s histappend
_bash_history_sync() {
@brianjlandau
brianjlandau / top_gifs.rb
Created January 2, 2013 17:07
This will go through all the gifs for the past year in one campfire room (back to the first of the current year) and calculate the most commonly posted gifs. It does this by grabbing the URL of the gif, getting the data and MD5ing it for comparison.
#!/usr/bin/env ruby
require 'rubygems'
require 'set'
require 'digest/md5'
require 'open-uri'
require 'tinder'
require 'active_support/all'
require 'awesome_print'
@brianjlandau
brianjlandau / spec_helper.rb
Created November 7, 2012 18:53
Visit a location in a Capybara rspec spec without following a redirect.
# ...
RSpec.configure do |config|
# ...
config.include VisitWithoutRedirectsHelper, :type => :request
# ...
end
class EmailCollection
include Enumerable
delegate :each, :to => :email_addresses
def initialize(raw_email_addresses)
@raw_email_addresses = raw_email_addresses
end
def valid_emails
select do |email|
@brianjlandau
brianjlandau / gist:3639233
Created September 5, 2012 16:15
Setting up for using JS driver in RSpec
config.before(:each, :type => :request) do
if example.metadata[:js]
self.class.use_transactional_fixtures = false
end
end
config.after(:each, :type => :request) do
if example.metadata[:js]
self.class.use_transactional_fixtures = true
DatabaseCleaner.clean # Truncate the database
Capybara.reset_sessions! # Forget the (simulated) browser state