Skip to content

Instantly share code, notes, and snippets.

@yoppi
yoppi / xhrImageLoad.js
Created September 5, 2016 09:33
同じsrcなんだけど実は裏で画像が更新されていて変化したタイミングで取ってきたいという贅沢な悩みを解決するやつ
'use strict';
// LastModifiedの変化を検知してimgをロードする
let $ = require('jquery');
module.exports = (imgSrc, callback) => {
let beforeLastModified;
let downloadImg = () => {
$.get(imgSrc, (data, status, xhr) => {
@yoppi
yoppi / ab-iris.txt
Last active July 9, 2016 10:08
benchmark net/http vs iris
< ab -n 1000 -c 10 'http://127.0.0.1:8080/' [~/local/go/1.7-rc1]
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index ea29f2e..ff971f3 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -1070,10 +1070,10 @@ cmd_var_resolve(struct stream *s, char *spec, char *buf)
*/
else if (!strcmp(spec, "stream.window")) {
if (s->id) {
- snprintf(buf, 20, "%ld", s->ws);
+ snprintf(buf, 20, "%lld", s->ws);
@yoppi
yoppi / a.js
Created March 11, 2016 03:10
custom mangle props
// ObjectKeyVal
// Dot
// Sub
var obj = {
'hoge': 'val'
};
var obj2 = {
foo: 'val'
@yoppi
yoppi / a.rb
Created October 29, 2015 01:44
after_actionするやつ
class AController < ApplicationController
after_action :f, if: -> { response.status == 200 }
def f
end
def x
head 200 # call f
# head 404 # not call f
end
@yoppi
yoppi / fn.js
Created August 27, 2015 02:18
jslint結構良い
'use strict';
var fn = function (hoge, fuga) {
console.log(hoge);
};
// > jslint --indent=2 fn.js
// fn.js
// #1 Unused 'fuga'.
@yoppi
yoppi / Makefile
Last active August 26, 2015 08:49
AWS lambda甩のnodeスクリプトをビルドするやつ、の比較
build: copy.js deps
zip -r copy.zip copy.js node_modules > /dev/null 2>&1
deps:
npm install
.PHONY: zip deps
@yoppi
yoppi / nolog.go
Last active August 29, 2015 14:26
こう書いても良さそう。けど、logパッケージと被る。
type AdLogger struct {
mu sync.Mutex
Path string
Out *os.File
buf []byte
}
func (l *AdLogger) Write(log logs.Log) {
l.mu.Lock()
defer l.mu.Unlock()
@yoppi
yoppi / geoip_bench.rb
Created July 15, 2015 00:49
geoip and geoip-c benchmark
require 'geoip'
require 'benchmark'
n = 1000000
# geoip-c C extended library
Benchmark.bm do |x|
geoip = GeoIP::City.new("/usr/share/GeoIP/GeoLiteCity.dat", :memory, false)
x.report { n.times { geoip.look_up("144.206.125.148") } }
# user system total real
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
const (
password = "hello"