Skip to content

Instantly share code, notes, and snippets.

View kenichi's full-sized avatar

Kenichi Nakamura kenichi

  • Portland, Oregon
View GitHub Profile
@kenichi
kenichi / bk_points.geojson
Last active August 29, 2015 13:59
full GPS of bike ride over sellwood/hawthorne bridges
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kzerza:terraformer-ruby $ irb -I./lib -rterraformer
>> f = Terraformer::Feature.new
=> #<Terraformer::Feature:0x00000000d90468>
>> f.geometry = Terraformer::Coordinate.new(-122.6764, 45.5165).buffer 100; nil
=> nil
>> puts f.to_json
{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-122.67550601034951,45.516562033665174],[-122.67551894559217,45.51662290132699],[-122.67554036587042,45.51668278727813],[-122.67557006489525,45.51674070977981],[-122.67560775664884,45.516796668829606],[-122.67565307813899,45.51684968268687],[-122.67570559289496,45.516899751348255],[-122.67576479517095,45.51694491133269],[-122.67583011481669,45.51698614437468],[-122.67590092276828,45.51702345047074],[-122.67597653710642,45.51705486613829],[-122.67605622962373,45.51708137311326],[-122.67613923283767,45.517101989652815],[-122.67622474738195,45.51711769749451],[-122.67631194970474,45.517126533156244],[-122.6764,45.517129478376944],[-122.67648805029526,45.517126533156244],[-122.67657525261805,45.51711769749
# geographic postgis
>> DB.get :st.distance( :st.geogfromwkb( :st.makepoint(-122.6764, 45.5165) ), :st.geogfromwkb( :st.makepoint(-122.6864, 45.5265) ) )
=> 1358.549604392
# geomteric postgis (?)
>> DB.get :st.distance( :st.transform(:st.setsrid(:st.makepoint(-122.6764, 45.5165), 4326), 3857), :st.transform(:st.setsrid(:st.makepoint(-122.6864, 45.5265), 4326), 3857) )
=> 1939.9894392485
@kenichi
kenichi / chat.rb
Created May 12, 2014 21:35
websocket "chat" with angelo!
require 'angelo'
require 'tilt'
require 'angelo/tilt/erb'
class Chat < Angelo::Base
include Angelo::Tilt::ERB
@@views = '.'
get '/' do
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
require 'ruby-prof'
class Array
def a_slice_exists? ary
raise ArgumentError unless Array === ary
each_index.select {|i| at(i) == ary[0]}.any? {|i| self[i,ary.length] == ary}
end
def b_slice_exists? slice
FROM ubuntu:precise
MAINTAINER Kenichi Nakamura <knakamura@esri.com>
# set locale
RUN locale-gen --no-purge en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
RUN echo 'LANG="en_US.UTF-8"' >> /etc/default/locale
@kenichi
kenichi / gist:d39a340bb4483d97b78b
Last active August 29, 2015 14:02
How to get Geotrigger polygons into an editable map on geojson.io in 4 easy steps
require 'terraformer'
require 'geotrigger'
require 'launchy'
# create a new FeatureCollection
#
fc = Terraformer::FeatureCollection.new
# create a Geotrigger Application session with credentials stored in ~/.geotrigger under the :foo key
#
@kenichi
kenichi / sse.rb
Last active August 29, 2015 14:03 — forked from tpitale/server.rb
require 'reel'
require 'json'
require 'pry'
class Server < Reel::Server::HTTP
include Celluloid::Logger
def initialize host = '127.0.0.1', port = 4567
info "listening on #{host}:#{port}"
super host, port, &method(:on_connection)
@kenichi
kenichi / gist:97116d3a12b64f02943a
Last active August 29, 2015 14:04
sequel <3 postgis
class Symbol
def method_missing meth, *args
if self == :st
Sequel.function(:"st_#{meth}", *args)
else
super
end
end
end