Skip to content

Instantly share code, notes, and snippets.

View justlaputa's full-sized avatar
:octocat:
coding 🐾🐾

Han Xiao justlaputa

:octocat:
coding 🐾🐾
  • PayPay
  • Tokyo, Japan
View GitHub Profile
@justlaputa
justlaputa / express-example.js
Last active June 7, 2018 23:33
example express application code for my blog post
const express = require('express')
const app = express()
app.use(function middlewareWithoutPath(req, res, next) {
console.log('use middleware without path')
next()
})
app.use('/foo', function middlewareWithPath(req, res, next) {
console.log('use middleware with path')
@justlaputa
justlaputa / docker-clean.py
Last active December 13, 2017 14:17
cleanup unused diffs in docker aufs folder
#!/bin/env python
import os
import json
import hashlib
from functools import reduce
import argparse
import logging
import shutil
DOCKER_DIR = '/var/lib/docker'
$ sudo systemctl cat resilio-sync.service
# /lib/systemd/system/resilio-sync.service
[Unit]
Description=Resilio Sync service
Documentation=http://help.getsync.com/
After=network.target network-online.target
[Service]
Type=forking
User=rslsync
$ sudo systemctl edit resilio-sync.service
[Service]
User=laputa
Group=laputa
PIDFile=/home/laputa/.config/resilio-sync/sync.pid
ExecStartPre=
ExecStart=
ExecStart=/usr/bin/rslsync --config /home/laputa/.config/resilio-sync/config.json
$ /etc/resilio-sync/init_user_config.sh
$ cat ~/.config/resilio-sync/config.json
{
"storage_path" : "/home/laputa/.config/resilio-sync/storage",
"pid_file" : "/home/laputa/.config/resilio-sync/sync.pid",
"webui" :
{
"listen" : "127.0.0.1:8888"
}
#!/bin/sh
mkdir -p $HOME/.config/resilio-sync
BTSYNC_STORAGE=$HOME/.config/btsync/storage
RESILIO_STORAGE=$HOME/.config/resilio-sync/storage
CONFIG_PATH=$HOME/.config/resilio-sync/config.json
$ sudo systemctl cat resilio-sync.service
# /lib/systemd/system/resilio-sync.service
[Unit]
Description=Resilio Sync service
Documentation=http://help.getsync.com/
After=network.target network-online.target
[Service]
Type=forking
User=rslsync
@justlaputa
justlaputa / ps-rslsync
Last active December 24, 2016 14:16
fix resiliosync daemon user
laputa@laputa-nuc-ubuntu:~$ ps aux | grep rslsync
rslsync 8388 0.2 0.0 504900 13676 ? Ssl 23:03 0:01 /usr/bin/rslsync --config /etc/resilio-sync/config.json
laputa 8420 0.0 0.0 15208 928 pts/17 S+ 23:10 0:00 grep --color=auto rslsy
@justlaputa
justlaputa / latency.markdown
Created November 6, 2016 06:15 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

# Copy from https://github.com/MarvAmBass/docker-nginx-registry-proxy/blob/master/docker-registry.conf
# For versions of Nginx > 1.3.9 that include chunked transfer encoding support
# Replace with appropriate values where necessary
upstream docker-registry {
server registry:5000;
}
server {
listen 443 default_server;