Skip to content

Instantly share code, notes, and snippets.

View kenichi's full-sized avatar

Kenichi Nakamura kenichi

  • Portland, Oregon
View GitHub Profile
$ 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
$ ruby reel.rb
E, [2014-12-03T16:03:19.939500 #53590] ERROR -- : Actor crashed!
Reel::StateError: already processing a request
/opt/ruby/2.1.5/lib/ruby/gems/2.1.0/gems/reel-0.5.0/lib/reel/connection.rb:55:in `request'
/opt/ruby/2.1.5/lib/ruby/gems/2.1.0/gems/reel-0.5.0/lib/reel/connection.rb:72:in `each_request'
reel.rb:6:in `block in <main>'
...
task :command do |p|
case p
when Proc; p[]
when Hash; p[:time] = Time.now.to_i
else; p.inspect
end
end
get '/' do
redirect 'index.html'
require 'sinatra/base'
require 'celluloid'
class Nmapper
include Celluloid
def nmap opts = ''
`nmap #{opts}`
end
end