Skip to content

Instantly share code, notes, and snippets.

View jcmuller's full-sized avatar

Juan C. Müller jcmuller

View GitHub Profile
# frozen_string_literal: true
require 'rails_helper'
require 'immigrant'
RSpec.describe "assert that no foreign keys are added without constraints", :aggregate_failures do
# These relationships should not be thought of as real FKs
let(:ignored_constraints) { YAML.load(<<~YAML) }
---
- :from_table: some_table
@jcmuller
jcmuller / eq_long_string_matcher.rb
Created October 30, 2017 19:20
Show long errors in RSpec
RSpec::Matchers.define :eq_long_string do |expected|
match do |string|
expected == string
end
failure_message do |actual|
"Failed with [#{actual}]\n\n" \
"Expected [#{expected}]"
end
@jcmuller
jcmuller / timer.rb
Last active March 16, 2017 22:15
Someone today asked for a way to aggregate timings of operations in different places across an app. This is a single threaded solution.
class Timer
include Singleton
def initialize
Thread.current[:timers] ||= Hash.new(0)
end
def display(timer)
Thread.current[:timers][timer]
end
#!/bin/sh
# Pre-commit hook for git which removes trailing whitespace, converts tabs to spaces, and enforces a max line length.
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@jcmuller
jcmuller / scale.coffee
Created April 17, 2014 13:30
Scale Function
scale = (inMin, inMax, outMin, outMax) ->
inMax = parseFloat(inMax)
inMin = parseFloat(inMin)
outMin = parseFloat(outMin)
outMax = parseFloat(outMax)
inRange = inMax - inMin
outRange = outMax - outMin
inMultiplier = 1 / inRange
[{"id":1,"user_id":1,"foursquare_id":"5313fb49498eaddbc72fbc28","shout":"with Juan C.","latitude":"33.6248941821904","longitude":"-84.45117885518563","venue_name":"Sheraton Gateway Hotel Atlanta Airport","address":"1900 Sullivan Rd","city":"Atlanta","state":"GA","venue_type":"Hotel"},{"id":2,"user_id":1,"foursquare_id":"531369a5498e762e980ae869","shout":"with Juan C.","latitude":"37.25608836765668","longitude":"-77.39258870743865","venue_name":"Applebee's","address":"449 S. Park Cir.","city":"Colonial Heights","state":"VA","venue_type":"American"},{"id":3,"user_id":1,"foursquare_id":"5313021e11d230e8fdd6f96a","shout":null,"latitude":"40.739943978226975","longitude":"-73.99397873738853","venue_name":"Spotify","address":"45 W 18th St","city":"New York","state":"NY","venue_type":"Tech Startup"},{"id":4,"user_id":1,"foursquare_id":"5312f645498ec97349c6c20c","shout":null,"latitude":"40.738676864716815","longitude":"-73.9958151502776","venue_name":"Hollywood Diner","address":"574 6th Ave. (Avenue of the Americas)",
for i in `find . \( -name '*html*' -or -name '*.rb' -or -name '*css' -or -name '*sass' -or \
-name '*.feature' \) -type f \! \( -path '*.git*' -or -path '*tmp*' -or -path '*solr*' -or \
-path '*/log/*' -or -path '*/public/*' -or -path '*/vendor/*' \)`
do
echo "Processing ${i}..."
cat -s "$i" > "$i.work"; mv "$i.work" "$i" # remove mulptiple lines empty within file
awk '/^$/ {nlstack=nlstack "\n";next;} {printf "%s",nlstack; nlstack=""; print;}' "$i" > "$i.work"; mv "$i.work" $i # only one new line character at EOF
done
@jcmuller
jcmuller / fix.sh
Last active December 21, 2015 17:49
$ rvm ruby-1.9.3-p429@platform-dev-param --create
$ bundle check
Gemfile syntax error:
Gemfile:12: syntax error, unexpected ':', expecting $end
gem "sso", git: "git@github.com:challengepost...
^
Gemfile syntax error:
Gemfile:12: syntax error, unexpected ':', expecting $end
gem "sso", git: "git@github.com:challengepost...
^
--ignore-ack-defaults
--ignore-directory=is:.bzr
--ignore-directory=is:.cdv
--ignore-directory=is:~.dep
--ignore-directory=is:~.dot
--ignore-directory=is:~.nib
--ignore-directory=is:~.plst
--ignore-directory=is:.git
--ignore-directory=is:.hg
--ignore-directory=is:.pc
@jcmuller
jcmuller / ctags
Last active December 20, 2015 11:38
ctags script for git hooks
#!/bin/bash
# Install at ~/.git_template/hooks/ctags (and set init.templatedir to ~/.git_template)
set -e
PATH="/usr/local/bin:$PATH"
trap "rm -f .git/tags.$$" EXIT
ctags --tag-relative -Rf.git/tags.$$ --exclude=.git --exclude='*.min.*'
mv .git/tags.$$ .git/tags