Skip to content

Instantly share code, notes, and snippets.

@cupakromer
cupakromer / flatten_map_bm.rb
Last active August 29, 2015 13:56
If you may have an array of arrays, `flat_map` is probably the way to go
require "benchmark"
require "benchmark/ips"
def arr
Array.new(1_000, 1)
end
def arr_of_arrs
Array.new(1_000){ (1..1000).to_a }
end
@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'
)
@csexton
csexton / v.zsh
Created January 27, 2015 20:01
Use a fuzzy finder to open a file in $EDITOR
# v Command {{{
# Fuzzy file opener in your editor
v(){
file=$(fzf)
[[ -n "$file" ]] && $EDITOR $file
}
# }}}
@fcoury
fcoury / mongomapper_polymorphic.rb
Created July 19, 2009 08:25
Example of polymorphic one to many association using mongomapper
require 'mongomapper'
class Media
include MongoMapper::EmbeddedDocument
key :file, String
end
class Video < Media
key :length, Integer
end
#!/bin/bash
usage ()
{
cat <<UsageHERE
boot2docker-fwd -- Helper function to quickly manage port forwards between the boot2docker-vm and the host
Usage: boot2docker-fwd [ -n RULE_NAME ] [ -h HOST_PORT ] [ -p {tcp|udp} ] [ -i HOST_IP ] GUEST_PORT
or boot2docker-fwd -d RULE_NAME
or boot2docker-fwd -l
or boot2docker-fwd -A
@practicingruby
practicingruby / 1_rcat_tests.rb
Last active September 27, 2015 15:47
Implementing a clone of UNIX cat in Ruby
# Task: Implement the rcat utility and get these tests to pass on a system
# which has the UNIX cat command present
# To see Gregory Brown's solution, see http://github.com/elm-city-craftworks/rcat
# Feel free to publicly share your own solutions
rrequire "open3"
working_dir = File.dirname(__FILE__)
gettysburg_file = "#{working_dir}/data/gettysburg.txt"
config.model PagePart do
edit do
field :content, :text do
ckeditor do
true
end
end
end
end
@NewAlexandria
NewAlexandria / rbenv_ree_install.sh
Created February 13, 2012 21:11
Installing Ruby Enterprise Edition into rbenv
########
# This file script wil show you how to install Ruby Enterprise Edition (REE) 1.8.7-2011-12 with
# rbenv, rails 3 and homebrew. Bundler is also used.
########
#setup the installer environment
brew install wget
wget -q http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.12.tar.gz
tar xzf ruby-enterprise-1.8.7-2011.12.tar.gz
@cupakromer
cupakromer / solution1.c
Last active October 13, 2015 22:18
Array Jump solution
#define MAX_STEPS 100000
#define NO_SOLUTION -1
int arrayJump(int *A, int size) {
int *p = A, steps = 0;
while (++steps < MAX_STEPS && A <= (p+=*p) && p < A+size);
return steps >= MAX_STEPS ? NO_SOLUTION : steps;
}
@jszmajda
jszmajda / Readme.md
Created March 25, 2013 18:32
template loading in angular.js with rails

Basically the angular_templates helper method creates script tags like

<script type="app/x-angular-template" name="whichever_app/templates/foo">
  template code here as html with {{}}s etc
</script>

We then reference that in angular with jQuery via $("script[name='whichever_app/templates/foo']").html().