Skip to content

Instantly share code, notes, and snippets.

View winebarrel's full-sized avatar

Genki Sugawara winebarrel

View GitHub Profile
@winebarrel
winebarrel / pg_show_grants.sql
Last active February 21, 2025 10:27
show grants for PostgreSQL
select
pg_user.usename,
t1.nspname,
t1.relname,
relacl.privilege_type,
relacl.is_grantable
from (
select
pg_namespace.nspname,
pg_class.relname,
@winebarrel
winebarrel / price.rb
Last active December 24, 2015 03:57
Rubyとjqでap-northeast-1のLinux/OnDemandの料金を出すやつ
#!/usr/bin/env ruby
require 'json'
require 'jq/extend'
#require 'pp'
trap(:PIPE, :EXIT)
# wget https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json -O AmazonEC2.json
json = File.read('AmazonEC2.json')
jq = JQ(json)
@winebarrel
winebarrel / test.rb
Last active December 23, 2015 07:09
Postfixログパースベンチマーク
#!/usr/bin/env ruby
require 'benchmark'
require 'postfix_status_line'
it = 5
n = 500000
status_lines = "Feb 27 09:02:37 MyHOSTNAME postfix/smtp[26490]: D53A72713E5: to=<[email protected]>, relay=gateway-f1.isp.att.net[204.127.217.16]:25, delay=0.57, delays=0.11/0.03/0.23/0.19, dsn=2.0.0, status=sent (250 ok ; id=20120227140036M0700qer4ne)"
r = /^(?<time>[^ ]* [^ ]* [^ ]*) (?<host>[^ ]+) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?[^\:]*\: (?<key>[^:]+): ?((to|from)=(<(?<address>[^>]+)>)?)?,( ?(orig_to=<(?<orig_to>[^>]+)>),)? ?(relay=(?<relay>[^ ]+)), ?(delay=(?<delay>[^ ]+)), ?(delays=(?<delays>[^ ]+)), ?(dsn=(?<dsn>[^ ]+)), ?(status=(?<status>[^,]+))/
@winebarrel
winebarrel / serverless-gyazo.rb
Last active August 29, 2015 14:24
Replace "Gyazo/script" to follow script:
#!/usr/bin/env ruby
require 'securerandom'
require 'tmpdir'
S3_BACKET = 'my-bucket'
S3_PATH = 'path'
ENDPOINT = 'my-bucket.s3-website-ap-northeast-1.amazonaws.com'
Dir.mktmpdir do |dir|
now = Time.now.utc

Follow these steps to install graphite on OS X Mavericks.

Prerequisites

  • Homebrew
  • Python 2.7
  • Git

Install dependencies

Install Cairo and friends

@winebarrel
winebarrel / drone-template.rb
Created March 30, 2014 13:19
Drone on AWS
Parameters do
ImageId do
Type "String"
# http://cloud-images.ubuntu.com/precise/current/
# ap-northeast-1; 64-bit; ebs
Default "ami-1f334f1e"
end
InstanceType do
Type "String"
@winebarrel
winebarrel / template.rb
Created March 10, 2014 15:55
Kumogata: Post command
Resources do
MyInstance do
Type "AWS::EC2::Instance"
Properties do
ImageId "ami-0d13700c"
InstanceType "t1.micro"
KeyName "XXX"
NetworkInterfaces [
@winebarrel
winebarrel / template.rb
Created March 9, 2014 17:29
Kumogata+Serf - template.rb
hosts = [:cthulhu, :hastur, :nyar]
Parameters do
SerfURL do
Type "String"
Default "https://dl.bintray.com/mitchellh/serf/0.4.5_linux_amd64.zip"
end
EventHandlerURL do
Type "String"
@winebarrel
winebarrel / event_handler.rb
Last active August 29, 2015 13:57
Kumogata+Serf- event_handler.rb
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
require 'socket'
HOSTS_PATH = '/etc/hosts'
EVENTS = %w(member-join member-leave member-failed)
EXCLUDES = %w(127.0.0.1)
def open_hosts
An h1 header
============
Paragraphs are separated by a blank line.
2nd paragraph. *Italic*, **bold**, `monospace`. Itemized lists
look like:
* this one
* that one