Skip to content

Instantly share code, notes, and snippets.

View bquorning's full-sized avatar

Benjamin Quorning bquorning

View GitHub Profile
@bquorning
bquorning / gist:460ad070893cbe498df5
Last active August 29, 2015 14:16
Uniqueness validation bug in Rails 4.1.10.rc1
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.1.10.rc1'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
#!/bin/sh
STAGED=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.rb$' -e '\.rake$' -e '\.ru$' -e Capfile -e 'Gemfile$')
if [ "$STAGED" ]; then
./bin/rubocop -- $STAGED
fi
#!/usr/bin/env ruby
grep_result = `grep -ri "def " #{ARGV.join(' ')}`
methods = grep_result.split("\n").collect do |line|
line[/.*:\s+def ([a-z_]+)(\((.*)\))?/i, 1]
end
filtered_methods = methods.uniq - ["initialize"]
dirs = (Dir.glob("*") - ['vendor', 'log']).join(" ")
Errno::EINVAL (Invalid argument):
redis (2.1.1) lib/redis/connection.rb:46:in `write'
redis (2.1.1) lib/redis/connection.rb:46:in `write'
redis (2.1.1) lib/redis/client.rb:60:in `process'
redis (2.1.1) lib/redis/client.rb:59:in `each'
redis (2.1.1) lib/redis/client.rb:59:in `process'
redis (2.1.1) lib/redis/client.rb:154:in `ensure_connected'
redis (2.1.1) lib/redis/client.rb:180:in `ensure_connected'
/usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
redis (2.1.1) lib/redis/client.rb:176:in `synchronize'
@bquorning
bquorning / payex.rb
Created May 16, 2011 09:09 — forked from dbackeus/payex.rb
Simple helper module to help communicate with payex.
module Payex
mattr_accessor :account_number
mattr_accessor :encryption_key
MD5_CHECK_FIELDS = {
"pxorder/pxorder.asmx/Initialize7" => [:accountNumber, :purchaseOperation, :price, :priceArgList, :currency, :vat, :orderID, :productNumber, :description, :clientIPAddress, :clientIdentifier, :additionalValues, :externalID, :returnUrl, :view, :agreementRef, :cancelUrl, :clientLanguage],
"pxagreement/pxagreement.asmx/CreateAgreement3" => [:accountNumber, :merchantRef, :description, :purchaseOperation, :maxAmount, :notifyUrl, :startDate, :stopDate],
"pxagreement/pxagreement.asmx/DeleteAgreement" => [:accountNumber, :agreementRef],
"pxorder/pxorder.asmx/Complete" => [:accountNumber, :orderRef],
"pxagreement/pxagreement.asmx/AutoPay2" => [:accountNumber, :agreementRef, :price, :productNumber, :description, :orderId, :purchaseOperation],
@bquorning
bquorning / gist:1146099
Created August 15, 2011 12:05
Careful Cutting To Get Faster RSpec Runs with Rails -- fix for Devise
# Don't need passwords in test DB to be secure, but we would like 'em to be
# fast -- and the stretches mechanism is intended to make passwords
# computationally expensive.
module Devise
module Models
module DatabaseAuthenticatable
def valid_password?(password)
return false if encrypted_password.blank?
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@bquorning
bquorning / gist:5325718
Created April 6, 2013 10:46
Here's the script I use to remove my merged branches, both remote and local. Disclaimer: Don’t blame me if you use this script to remove something you wanted do keep. Maybe add the `-n` flag to `git push` while you’re trying out how the script works. If in trouble, read [man git-reflog](http://git-scm.com/docs/git-reflog).
git checkout master
git pull
git remote prune origin
git branch -r --merged | grep bquorning | awk -F'/' '{ print ":" $2 "/" $3 }' | xargs git push origin
git branch --merged | grep -v "\* master" | xargs git branch -d
# That was actually a somewhat simplified version. Here's what I really use:
git checkout master && git pull && (git remote prune origin && git branch -r --merged | grep bquorning | awk -F'/' '{ print ":" $2 "/" $3 }' | xargs git push origin) & ; git branch --merged | grep -v "\* master" | xargs git branch -d
@bquorning
bquorning / post-checkout hook
Last active December 17, 2015 21:39
Run bundler automatically when needed. Save file as .git/hooks/post-checkout in your project, and do a `chmod +x`. Heavily inspired by https://gist.github.com/whilefalse/1019087
#!/bin/bash
if [ ! `git diff --name-only HEAD@{1}..HEAD Gemfile Gemfile.lock | wc -l` -eq 0 ]
then
echo -e "\033[0;31m*** Gemfile change detected, running bundle check ***\033[0m"
(unset GIT_DIR ; bundle check || bundle install --local || bundle install)
fi
@bquorning
bquorning / active_record_master.rb
Last active March 7, 2016 13:53
Eager loaded belongs_to associations are always readonly
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'