This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=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'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rackup | |
# encoding: UTF-8 | |
=begin | |
# start application | |
$ mkdir files | |
$ ./fileUploader.ru | |
# upload | |
$ curl localhost:9292/files -F comment="hello,world" -F "[email protected];type=image/jpg" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import commands | |
class MyIP: | |
def rawips(self): | |
cmd = "awk 'NR!=1 { split($2,arr,\":\"); print arr[1] }' /proc/net/tcp|sort|uniq" | |
return commands.getoutput(cmd).split("\n") | |
def raw2str(self, raw): | |
n = [int(raw[n:n+2],16) for n in [6,4,2,0]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#from peewee import * | |
#import pymysql | |
import peewee | |
# 'id' to 'BIGINT AUTO_INCREMENT' | |
peewee.MySQLDatabase.field_overrides['primary_key'] = 'BIGINT AUTO_INCREMENT' | |
db = peewee.MySQLDatabase( | |
database='peewee_development', | |
user='root', | |
password='', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class ModifyPath | |
def initialize(exe) | |
@exe = exe | |
@dylibs = `otool -L #{exe}`.each_line.map{|line| | |
$1 if line=~%r{\t([^/@].+\.dylib) .*$} | |
}.compact.delete_if{|dy| | |
File.basename(dy)==File.basename(exe) or !File.exist?(File.basename(exe)) | |
} |