Skip to content

Instantly share code, notes, and snippets.

View wklken's full-sized avatar
😄
Coding

wklken wklken

😄
Coding
View GitHub Profile
@wklken
wklken / tornado-unix-socket.py
Created January 12, 2016 06:59 — forked from superduper/tornado-unix-socket.py
Tornado web server with unix socket support
import tornado.ioloop
import tornado.web
from tornado.options import options, define
from tornado.netutil import bind_unix_socket
from tornado.httpserver import HTTPServer
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
@wklken
wklken / request.sh
Last active September 1, 2016 19:27 — forked from nuxlli/unix_socket_request.sh
Examples of http request (in unix domain socket) with bash and [nc|socat]
#!/bin/bash
# References
# http://www.computerhope.com/unix/nc.htm#03
# https://github.com/daniloegea/netcat
# http://unix.stackexchange.com/questions/26715/how-can-i-communicate-with-a-unix-domain-socket-via-the-shell-on-debian-squeeze
# http://unix.stackexchange.com/questions/33924/write-inside-a-socket-open-by-another-process-in-linux/33982#33982
# http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip
# http://www.dest-unreach.org/socat/
# http://stuff.mit.edu/afs/sipb/machine/penguin-lust/src/socat-1.7.1.2/EXAMPLES
@wklken
wklken / switch_proxy.sh
Created January 28, 2016 15:24
keyboard maestro + goagentx, switch wifi connection between office(need proxy) and home(use goagentx). `do shell script "/Users/ken/bin/switch_net" user name "xxxx" password "xxxx" with administrator privileges`
#!/bin/bash
# 在公司
if [ "$(networksetup -getairportnetwork en1 | awk '{print $4}')" = "Office" ]; then
# 先关闭 Wi-Fi 的所有代理设置
sudo networksetup -setwebproxystate Wi-Fi off
sudo networksetup -setsocksfirewallproxystate Wi-Fi off
sudo networksetup -setautoproxystate Wi-Fi off
@wklken
wklken / deencrypt_3des.go
Created September 22, 2016 07:00
3des: encrypt with python & deencrypt with golang
package main
// reference: https://golang.org/pkg/crypto/des/
// reference: http://blog.studygolang.com/2013/01/go%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86%E4%B9%8Bdes/
import (
"crypto/cipher"
"crypto/des"
"encoding/base64"
"encoding/json"
@wklken
wklken / elasticsearch-cheatsheet.txt
Created February 20, 2017 07:36 — forked from stephen-puiszis/elasticsearch-cheatsheet.txt
Elasticsearch Cheatsheet - An Overview of Commonly Used Elasticsearch API Endpoints and What They Do
# Elasticsearch Cheatsheet - an overview of commonly used Elasticsearch API commands
# cat paths
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
@wklken
wklken / get_chinese_words.py
Created November 7, 2017 02:32
get chinese words and sentenses from js/py files
# -*- coding: utf-8 -*-
# just quick & dirty job
import sys
import re
def process_one_file(file_path):
results = []
# 1. all "" and ''
" mkdir -p $HOME/.vim/swapfiles && mkdir -p $HOME/.vim/backupfiles
set directory=$HOME/.vim/swapfiles/
set backupdir=$HOME/.vim/backupfiles/
@wklken
wklken / mock_requests.py
Created November 28, 2018 07:41 — forked from evansde77/mock_requests.py
Example of mocking requests calls
#!/usr/bin/env python
"""
mocking requests calls
"""
import mock
import unittest
import requests
from requests.exceptions import HTTPError
@wklken
wklken / docker_images.sh
Created February 25, 2019 09:11 — forked from hydra1983/docker_images.sh
Save and load docker images in batch
#!/bin/bash
readonly DB_FILE="$(pwd)/images.db"
readonly IMG_DIR="$(pwd)/images"
save-images() {
echo "Create ${DB_FILE}"
echo "$(docker images|grep -v 'IMAGE ID'|awk '{printf("%s %s %s\n", $1, $2, $3)}'|column -t)" > "${DB_FILE}"
echo "Read ${DB_FILE}"
##
## HTTP Router benchmarks -- Jan 9, 2019 with Go 1.11.4 on Linux X1 Carbon laptop
##
## This benchmark suite is based on https://github.com/julienschmidt/go-http-routing-benchmark
## using the most up-to-date version of each pkg as of today. Each router has their own
## pros and cons, so consider the designs of each router to suit your application.
##
## We use the most up-to-date version of each router available in the tests below.
##