Skip to content

Instantly share code, notes, and snippets.

@suzumura-ss
suzumura-ss / x_reproxy_url_filter.rb
Last active December 22, 2015 00:32
Rack middleware for process X-Reproxy-URL.
=begin
require 'grape'
require 'x_reproxy_url_filter'
class Hello < Grape::API
get 'static' do
status 200
%w{The quick brown fox jumps over the lazy dog}
end
get 'download' do
@suzumura-ss
suzumura-ss / upload_boby.lua
Last active January 8, 2016 14:36
upload request-body to other service
-- https://github.com/diegonehab/luasocket
local HTTP = require("socket.http")
local LTN12 = require("ltn12")
-- source for ngx.req.socket()
function source_tcpsock(handle, bytes)
bytes = tonumber(bytes)
if handle then
return function()
if bytes <= 0 then
@suzumura-ss
suzumura-ss / error.log
Last active December 21, 2015 13:09
nginx-lua: upload request-body to other service with LuaSocket
2015/12/21 20:31:38 [error] 7922#0: *70 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
[C]: in function 'request'
/opt/nginx/scripts/upload4.lua:45: in function </opt/nginx/scripts/upload4.lua:1>, client: 127.0.0.1, server: localhost, request: "POST /upload4 HTTP/1.0", host: "localhost"
see:
http://stackoverflow.com/questions/30111808/luasocket-nginx-error-lua-entry-thread-aborted-runtime-error-attempt-to-yi
@suzumura-ss
suzumura-ss / x_cloudwatchlog_filter.rb
Last active December 23, 2015 02:27
put CloudWatchLogs with X_CLOUDWATCH_LOG header
=begin
require 'grape'
require 'uuid'
require 'ltsv'
class Hello < Grape::API
post 'teapot' do
status 201
id = UUID.generate
header XCloudwatchLogFilter::X_CLOUDWATCH_LOG, LTSV.dump({user_id:id, resource:'/teapot'})
@suzumura-ss
suzumura-ss / upload_body.lua
Last active December 22, 2015 05:17
nginx-lua: upload request-body to other service without LuaSocket
local function header_join_with_crlf(header)
local str = "", k, v
for k,v in pairs(header) do
str = str .. v .. "\r\n"
end
return str
end
-- @return client, err
local function connect(ngxctx, host, port, path)
@suzumura-ss
suzumura-ss / nginx_upload2s3.lua
Last active December 22, 2015 16:47
nginx-lua: upload to aws-s3
local function signature(ngxctx, method, bucket, objectkey)
local access_key = os.getenv('AWS_ACCESS_KEY_ID')
local secret_key = os.getenv('AWS_SECRET_ACCESS_KEY')
local date = ngxctx.http_time(ngxctx.time())
local headers = ngxctx.req.get_headers()
local s2s = method .. "\n"
s2s = s2s .. (headers['content-md5'] or "") .. "\n"
s2s = s2s .. (headers['content-type'] or "") .. "\n"
s2s = s2s .. date .. "\n"
s2s = s2s .. "/" .. bucket .. "/" .. objectkey
@suzumura-ss
suzumura-ss / build-ngx_openresty-with-passenger.rb
Last active December 22, 2015 20:34
build ngx_openresty with passenger
#!/usr/bin/env ruby
=begin
sudo yum -y install gcc openssl-devel zlib-devel pcre-devel lua lua-devel
sudo yum -y install ruby-devel curl-devel gcc-c++
wget https://openresty.org/download/ngx_openresty-1.9.3.2.tar.gz
tar xf ngx_openresty-1.9.3.2.tar.gz
gem install passenger
ruby build.rb
=end
@suzumura-ss
suzumura-ss / config.ru
Last active December 22, 2015 17:10
nginx-lua: upload request-body to AWS-S3
require 'grape'
require 'uuid'
require 'aws-sdk'
class Hello < Grape::API
HTTP_PROXY = ENV['HTTP_PROXY'] || ENV['HTTPS_PROXY']
AWS_REGION = ENV['AWS_REGION'] || 'ap-northeast-1'
module Logic
@suzumura-ss
suzumura-ss / fuse-cloudwatchlogfs.rb
Last active December 23, 2015 15:38
fuse-cloudwatchlogfs - Send to AWS-CloudWatchLog
#!/usr/bin/env ruby
=begin
* install
$ yum -y install fuse fuse-devel
$ gem install rfusefs
* mount
$ mkdir group_name
$ ruby cloudwatchlogfs.rb group_name
#=> log-group name is 'group_name'
@suzumura-ss
suzumura-ss / Trac-Dockerfile
Last active November 2, 2018 00:54
trac with Docker
FROM ubuntu
WORKDIR /root
ENV TZ=JST-9
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get -y install trac
RUN mkdir ./Main
RUN echo "main\n\n" |trac-admin ./Main initenv