Skip to content

Instantly share code, notes, and snippets.

package main
import (
"flag"
"io"
"log"
"net"
"sync"
"time"
use 5.12.0;
use Benchmark qw/:all/;
my @src = 1 .. 1000;
cmpthese 0, {
push => sub {
my @dest;
for (@src) {
push @dest, $_;
@fujiwara
fujiwara / nginx.conf
Last active June 7, 2018 15:33
nginx dynamic mirror
$ 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 14:55
AWS billing post to SNS
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 March 20, 2018 15:09
min interval exec wrapper
$ 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
@fujiwara
fujiwara / main.go
Created December 11, 2017 04:46
mail2line
package main
import (
"fmt"
"mime"
"net/http"
"net/mail"
"net/url"
"os"
"strings"
@fujiwara
fujiwara / gh-release-download
Created November 27, 2017 04:53
Download GitHub private repo's release files.
#!/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
main.Config{Foo:main.MaybeBool{b:false, isSet:true}, Bar:main.MaybeBool{b:false, isSet:false}}
@fujiwara
fujiwara / bench.js
Created July 21, 2017 10:00
node splitN benchmark
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");
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)