Skip to content

Instantly share code, notes, and snippets.

@qrush
qrush / gist:10401517
Created April 10, 2014 16:51
Replace tabs with 4 spaces, remove leading spaces/tabs for Objective-C .m, .h files
find . -name "*.[mh]" | while read line; do expand -t 4 $line > $line.new; mv $line.new $line; done
find . -name "*.[mh]" | while read line; do git stripspace < $line > $line.new; mv $line.new $line; done
@caged
caged / score-buildings.sql
Last active August 29, 2015 14:01
Scoring buildings based on proximity to neighborhood features
drop table if exists target_homes;
with
supermarket_zones as (select st_expand(geom, 0.0045) as zone, 5 as score from osm_polygons where osm_polygons.shop='supermarket'),
rail_stop_zones as (select st_expand(geom, 0.0045) as zone, 5 as score from trimet_rail_stops),
park_zones as (select st_expand(geom, 0.0045) as zone, 2 as score from osm_polygons where osm_polygons.leisure='park'),
target_buildings as (
select * from supermarket_zones inner join buildings on st_intersects(supermarket_zones.zone, buildings.geom) where buildings.subarea='City of Portland'
union select * from rail_stop_zones inner join buildings on st_intersects(rail_stop_zones.zone, buildings.geom) where buildings.subarea='City of Portland'
)
@avdi
avdi / unindent.rb
Created September 16, 2014 19:00
Stripping indentation from heredocs
TEXT = <<EOF
See, the interesting thing about this text
is that while it seems like the first line defines an indent
it's actually the last line which has the smallest indent
there are also some blank lines
both with and without extra spaces in them
and it just goes on and on
@solnic
solnic / require_measure.rb
Last active August 29, 2015 14:14
A hack to measure how long it takes to require bundled gems in a rails app
REQUIRE_DATA = {}
BUNDLED_GEMS = `bundle show | grep "*" | awk '{print $2}'`.split("\n").sort
require 'bigdecimal'
def require(name)
start = Time.now
ret = super
stop = Time.now
total = BigDecimal(stop-start, 6)
REQUIRE_DATA[name] = total if BUNDLED_GEMS.include?(name)
@coreyhaines
coreyhaines / prompt.sh
Created March 26, 2015 22:09
My prompt
export PROMPT_COMMAND='prompt_status=$?'
export PS1='$(if [[ $prompt_status == 0 ]]; then echo "¯\_(ツ)_/¯"; else echo "ᕕ( ᐛ )ᕗ"; fi) 🐈 $'
@RStankov
RStankov / articles_controller.rb
Created July 8, 2012 21:35
hexagonal rails try
class ArticlesController < ApplicationController
def create
PublishArticle.publish(current_user, params[:article]) do |result|
result.success { |article| redirect_to article_path(article) }
result.failure { |article| @article = article; render :new }
end
end
end
@epitron
epitron / spec_helper.rb
Created September 15, 2012 18:11
How to use pry-rescue in your specs.
require 'spork'
Spork.prefork do
require 'rspec'
require 'pry'
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
@chrismdp
chrismdp / run-changed-tests.sh
Created November 29, 2012 12:00
Handy little command to run all the tests that I've changed since the last commit
git status --porcelain | grep 'test' | grep -v 'factories' | cut -c4- | sort | uniq | xargs zeus test
#!/usr/bin/env ruby
if name = ARGV.first
path = `gem which #{name}`
readme = Dir.glob(File.join(File.dirname(path), "../", "README.{md,markdown}")).first
fail "Failed to find readme for gem '#{name}'" unless File.exist?(readme)
puts File.read(readme)
else
puts "Usage: gem-man gem_name"
end
@thbar
thbar / Guardfile
Last active December 15, 2015 10:28
How to automatically restart the simulator in RubyMotion when code is updated (beta version!)
require 'childprocess'
guard 'shell' do
watch %r{^app/(.+)\.rb$} do |m|
`killall rake`
# Why this:
# - spawn a child process to avoid locking Guard
# - make sure that the child process has stdout and stdin otherwise it crashes
# - bonus point: get REPL access in the simulator!