Skip to content

Instantly share code, notes, and snippets.

View beechnut's full-sized avatar

Matt Cloyd beechnut

  • 18F (work) + personal projects
  • Philadelphia, PA
View GitHub Profile
/*
* A function that converts a PostGIS query into a GeoJSON object.
* Copyright (C) 2012 Samuel Giles <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@beechnut
beechnut / hypermedia-review.md
Last active January 2, 2016 23:59
A "blow-by-blow" of my hypermedia-in-Rails work on beechnut/mfapi

I started with simple, concrete hypermedia for Objectives. For the collection I created a collection method, into which I passed the Objectives to create a collection+json object. For a single record, I loop through its associations with reflect_on_all_associations, and create links to all its associated objects.

I then moved this logic to ApplicationController and abstracted it for use with Indicators.

Namespaces in this hackery were a little tricky: self_link could theoretically mean either:

{"rel": "self", "href": "/path/to/self"}
E, [2014-02-21T19:55:06.988850 #758] ERROR -- : Operation not permitted (Errno::EPERM)
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.2/lib/unicorn/worker.rb:146:in `initgroups'
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.2/lib/unicorn/worker.rb:146:in `user'
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:621:in `init_worker_process'
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:647:in `worker_loop'
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:521:in `spawn_missing_workers'
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:532:in `maintain_worker_count'
/home/deployer/apps/staging.regionalindicators.org/shared/bundle/ruby
# Set environment to development unless something else is specified.
env = ENV['RAILS_ENV'] || 'development'
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for documentation
worker_processes 4
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen '/tmp/regionalindicators.socket', backlog: 64
@beechnut
beechnut / README.md
Created April 2, 2014 22:26
A First Attempt at Multi-Table Models in Rails

Multi-Table Models in Rails (without Rails for now)

I have Census datasets that store attributes in three separate files, corresponding to three separate summary levels, or spatial resolutions -- in this case, Municipalities, Census Tracts, and Census Blockgroups.

It's not the Rails way: I know. But it's not anybody else's way -- not even GeoNode has solved the problem of having attribute data separate from spatial data and joining them on the fly to one of several possible geographies.

I'd love to be able to write

@beechnut
beechnut / backtick-surround.js
Last active December 6, 2021 06:11
Surround with backticks in Sublime Text 3
// Copy the following into Preferences > Key Bindings -- User
// Thanks to:
// http://sublimetext.userecho.com/topic/86166-backtick-quoting-selected-text-does-not-work-like-single-quotes-and-double-quotes/
[
// Auto-pair backticks
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
@beechnut
beechnut / sociogeoruby.md
Last active August 29, 2015 14:06
Social Influence, Equity, and Geospatial Ruby

This talk will present a vision for how our tutorials and code examples can influence new developers in ways beyond helping them to code, and exposing them to new ideas and making the ideologies embedded within code clearer. I will make a case for and present several ways we might develop the equivalent of 'media literacy' in code.

Ruby doesn't yet have geospatial libraries, but there's a new movement of developers to make mapping platforms and tile servers as easy to build as a Rails apps.

Rubyists represent an interesting demographic because so many of them -- myself included -- are new programmers, coming in from MOOCs like CodeAcademy or accelerators like LaunchAcademy. Code examples include Ten-Minute Blogs and Twitter clones, and are generally considered ideology-neutral. However, these examples have their own ideologies, and code examples could be more conscious of and deliberate about the ideas they present. Tutorials be could a place to influence new programmers, nudging them towrds doing work for

@beechnut
beechnut / flatten_with_path.rb
Created March 2, 2015 19:10
Flatten hashes recursively
# From http://stackoverflow.com/questions/16497719/flatten-a-nested-hash-in-ruby-on-rails
module Enumerable
def flatten_with_path(parent_prefix = nil)
res = {}
self.each_with_index do |elem, i|
if elem.is_a?(Array)
k, v = elem
else
@beechnut
beechnut / wish-knew.md
Last active August 29, 2015 14:17
What I wish people new about coding

What I wish people knew about coding, including beginner programmers.

  • Coding isn't mystical.
    • Don't revere developers.
  • Getting started is hard, especially if you don't have a community of real, live people to help you out.
    • StackOverflow doesn't count. Meetups do.
  • The gap between the code you see on GitHub and running code is often massive. If you can't get a relatively simple codebase running quickly, it's probably because the developer assumes a lot about your system, not because you've done something wrong.
  • If code looks messy and scatterbrained, it probably is.
  • Read Ruby books. Avdi Grimm and Sandi Metz have a lot of important things you should read, whether you write Ruby or not.
  • So-called '10x programmers' leave 10x the technical debt of other programmers. The 10x myth has a cost.
@beechnut
beechnut / gem_make.out
Created August 29, 2017 14:26
GDAL is failing to compile (zoning.io)
/Users/matt/.rubies/ruby-2.2.3/bin/ruby -r ./siteconf20170829-5441-z90xo9.rb extconf.rb
checking for main() in -lgdal... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling osr.cpp
In file included from osr.cpp:1888:
In file included from /Applications/Postgres.app/Contents/Versions/9.6/include/cpl_string.h:35: