Skip to content

Instantly share code, notes, and snippets.

@fujiwara
fujiwara / nginx.conf
Last active Jun 7, 2018
nginx dynamic mirror
View nginx.conf
$ curl -H"X-Mirror1: 127.0.0.1:5000" -H"X-Mirror2: 127.0.0.1:5001" -H"X-Mirror3: 127.0.0.1:5002" localhost:8000
@fujiwara
fujiwara / index.js
Last active May 8, 2018
AWS billing post to SNS
View index.js
const aws = require('aws-sdk');
const cw = new aws.CloudWatch({region: 'us-east-1'});
const sns = new aws.SNS();
exports.handler = (event) => {
const endTime = new Date();
const startTime = new Date();
startTime.setDate(endTime.getDate() - 2); // 2 days ago
const param = {
MetricName: 'EstimatedCharges',
@fujiwara
fujiwara / example.md
Last active Mar 20, 2018
min interval exec wrapper
View example.md
$ min-interval-exec 5 date
Wed Mar 21 00:08:38 JST 2018
$ sleep 3
$ min-interval-exec 5 date
$ sleep 2
$ min-interval-exec 5 date
Wed Mar 21 00:08:44 JST 2018
View main.go
package main
import (
"fmt"
"mime"
"net/http"
"net/mail"
"net/url"
"os"
"strings"
@fujiwara
fujiwara / gh-release-download
Created Nov 27, 2017
Download GitHub private repo's release files.
View gh-release-download
#!/bin/bash
set -eu
repo="$1" # fujiwara/foo
tag="$2" # v0.1.0
name="$3" # foo-0.1.1-linux-amd64.zip
releases=$(curl -s -H "Authorization: token ${TOKEN}" "https://api.github.com/repos/${repo}/releases/tags/${tag}")
url=$(echo "$releases" | jq -r ".assets[] | select(.name == \"${name}\").url")
echo $url
View result.txt
main.Config{Foo:main.MaybeBool{b:false, isSet:true}, Bar:main.MaybeBool{b:false, isSet:false}}
@fujiwara
fujiwara / bench.js
Created Jul 21, 2017
node splitN benchmark
View bench.js
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
suite.add('indexOf', function() {
var s = "time:2017-01-01T11:22:33Z"
var i = s.indexOf(":")
return [ s.slice(0,i), s.slice(i+1) ];
})
.add("replace\\0", function() {
var s = "time:2017-01-01T11:22:33Z"
return s.replace(":", "\0").split("\0");
View dialer.go
var ResovedAddress = make(map[string][]string)
var mu sync.RWMutex
func Dialer(network, addr string) (net.Conn, error) {
host, port, _ := net.SplitHostPort(addr)
mu.RLock()
addrs, found := ResovedAddress[host]
mu.RUnlock()
if found {
// log.Println("cache hit for", host)
@fujiwara
fujiwara / i18n.go
Created Oct 7, 2016
go-gettext i18n
View i18n.go
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/samuel/go-gettext/gettext"
)
View chef_recipe_to_stns_toml.rb
require "toml"
class Group
def initialize(name)
@name = name
end
def gid(gid)
@gid = gid
end