Skip to content

Instantly share code, notes, and snippets.

View jcmuller's full-sized avatar

Juan C. Müller jcmuller

View GitHub Profile
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
[{"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)",
@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
#!/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 / 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
@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
# 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