Skip to content

Instantly share code, notes, and snippets.

View kenichi's full-sized avatar

Kenichi Nakamura kenichi

  • Portland, Oregon
View GitHub Profile
#!/usr/bin/env ruby
class A
def b
'b'
end
end
module X
def b
$ ruby pdx_maps.rb
irb(main):001:0> lot = get_lot -122.6769435581849, 45.5488853183137
=> #<Terraformer::Feature:0x007fb778cb1df8 @geometry=#<Terraformer::Polygon:0x007fb778c48128 @coordinates=[[#<Terraformer::Coordinate lon=-122.6767446408871 lat=45.54882332280822 >, #<Terraformer::Coordinate lon=-122.6771349121657 lat=45.54882481627093 >, #<Terraformer::Coordinate lon=-122.6771338692216 lat=45.54896194793751 >, #<Terraformer::Coordinate lon=-122.6767436024346 lat=45.5489604538493 >, #<Terraformer::Coordinate lon=-122.6767446408871 lat=45.54882332280822 >]]>>
irb(main):002:0> puts JSON.pretty_generate lot.to_hash
{
"type": "Feature",
"properties": {
},
"geometry": {
"type": "Polygon",
class App
def call env = {}
r = Rack::Request.new env
if r.session[:hi]
STDERR.puts "found in session: #{r.session[:hi]}"
else
r.session[:hi] = 'hello'
end
require 'angelo'
class BG < Angelo::Base
websocket '/' do |ws|
websockets << ws
end
end
#!/usr/bin/env ruby
require 'angelo'
# require 'httpclient'
class Worker
include Celluloid
def fib n = 40
n <= 1 ? n : fib(n-1) + fib(n-2)
@kenichi
kenichi / config.ru
Last active February 20, 2016 18:00
fibbers
require 'rack'
require 'puma'
class Fib
def call env
request = Rack::Request.new env
s = []
case request.path
@kenichi
kenichi / Gemfile
Last active August 29, 2015 14:27
playing with the official mapbox ruby client and terraformer
source 'https://rubygems.org'
gem 'mapbox-sdk', github: 'kenichi/mapbox-sdk', branch: 'to_sym'
gem 'terraformer'
set-option -g default-path .
neww -t 1 -n web 'bin/tracklet'
neww -t 2 -n psql 'psql tracklet'
neww -t 3 -n irb 'ruby -rirb -r./lib/tracklet -e "Bundler.require :dev; IRB.start"'
neww -t 4 -n tig 'tig'
neww -t 5 -n workers 'bundle exec sidekiq -r ./lib/tracklet.rb -c 8'
bind T neww -t 0 -n bash 'bash'
bind Y neww -t 1 -n web 'bin/tracklet'
@kenichi
kenichi / nghttp_output
Last active August 29, 2015 14:25
http-2 + nghttp options/upgrade -> post
$ echo foo=bar | nghttp -d - -t 0 -vu http://127.0.0.1:8080/
[ 0.003] Connected
[ 0.005] HTTP Upgrade request
OPTIONS * HTTP/1.1
Host: 127.0.0.1:8080
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: AAMAAABkAAQAAP__
Accept: */*
User-Agent: nghttp2/1.1.3-DEV
@kenichi
kenichi / webrick_gzip_post_body.rb
Created July 9, 2015 03:56
webrick gzip post body
require 'webrick'
require 'zlib'
require 'stringio'
s = WEBrick::HTTPServer.new Port: 4567, BindAddress: '127.0.0.1'
s.mount_proc '/' do |req, res|
puts "unzipped_body:\n" + Zlib::GzipReader.new(StringIO.new(req.body)).read
res.status = 200
res.content_length = 0
end