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 / 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
$ irb -rterraformer -ruri -rlaunchy
>> Terraformer::Circle.new([-122.6764, 45.5165], 100).to_feature.geojson_io
=> #<Thread:0x007fd313f05fd0 sleep>
>> Terraformer::Circle.new([-122.6764, 45.5165], 100, 16).to_feature.geojson_io
=> #<Thread:0x007fd313040fb8 sleep>
>> Terraformer::Circle.new([-122.6764, 45.5165], 100, 8).to_feature.geojson_io
=> #<Thread:0x007fd313dcfb20 sleep>
@kenichi
kenichi / gist:c5038ee9ba09ae0f8333
Created August 7, 2014 21:52
simplifying polygons with terraformer.rb
# load up waldo
wc = Terraformer.parse 'test/examples/waldocanyon.geojson'
# grab the line string of the outer polygon ring
ls = wc.geometry.polygons[0].line_strings[0]
# new array to hold new outer ring
scs = []
# only put every 5th coordinate in the new array
@kenichi
kenichi / bd_limit.rb
Created August 8, 2014 17:57
BigDecimal.limit setting
require 'bigdecimal'
t1 = Thread.new { 5.times { puts "(1) limit: #{BigDecimal.limit}"; sleep 1 } }
sleep 2
BigDecimal.limit BigDecimal.double_fig
puts "(main) limit: #{BigDecimal.limit}"
t2 = Thread.new { 5.times { puts "(2) limit: #{BigDecimal.limit}"; sleep 1 } }
t1.join
t2.join
#!/usr/bin/env ruby
class DefMethard
define_method :go do |&block|
5.times {|n| yield n}
end
define_method :yo do |&block|
5.times {|n| block[n]}
end
end
$ mkdir -p ~/.weechat/themes
$ cd ~/.weechat/python
$ curl -O http://weechat.org/files/temp/theme/theme.py
$ cd ../themes
# find a theme at http://weechat.org/themes/ and curl -O it into ~/.weechat/themes
$ weechat
/help theme
require 'benchmark/bigo'
def b(size)
[size + 5]
end
Benchmark.bigo do |x|
x.generator do |size|
(0...size).to_a
$ curl -H 'X-Foo: bar' -d @reel.rb -v http://127.0.0.1:4567/ http://127.0.0.1:4567/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 4567 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 127.0.0.1:4567
> Accept: */*
> X-Foo: bar
> Content-Length: 165