Skip to content

Instantly share code, notes, and snippets.

View chaosong's full-sized avatar
🍺
homebrew

chaosong

🍺
homebrew
View GitHub Profile
@chaosong
chaosong / reply-to-empty-udp.py
Created January 6, 2023 02:25 — forked from jcwarp/reply-to-empty-udp.py
Simple Python UDP echo server
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: David Manouchehri <manouchehri@protonmail.com>
# This script will always echo back data on the UDP port of your choice.
# Useful if you want nmap to report a UDP port as "open" instead of "open|filtered" on a standard scan.
# Works with both Python 2 & 3.
import socket
@chaosong
chaosong / token.go
Created March 6, 2017 08:31
get token ring for batch accumulation
func (t *tokenRing) GetIndexForPartitionKey(partitionKey []byte) int {
if t == nil {
return 0
}
hash := t.partitioner.Hash(partitionKey)
l := len(t.tokens)
// no host tokens, no available hosts
if l == 0 {
return 0
@chaosong
chaosong / home_env.lua
Created March 28, 2016 11:06
nodemcu read dht22 and pms5003
function initWIFI()
print("Setting up WIFI...")
wifi.setmode(wifi.STATION)
wifi.sta.config("<wifi-id>", "<wifi-password>")
wifi.sta.connect()
tmr.alarm(1, 1000, 1,
function()
if wifi.sta.getip()== nil then
print("IP unavailable, Waiting...")
@chaosong
chaosong / pil.py
Created November 21, 2014 11:07
ipython notebook 显示 pil 图像对象
from PIL import Image
import requests
from IPython.display import Image as DisplayImage
import io
def get_im_by_url(url):
r = requests.get(url)
return Image.open(io.BytesIO(r.content))
def display(im):
@chaosong
chaosong / custom.el
Created September 16, 2014 03:42
emacs custom
(set-frame-font "Monaco-12")
(set-fontset-font "fontset-default" 'han '("Hiragino Sans GB W3" . "unicode-bmp"))
(defun set-font (english chinese english-size chinese-size)
(set-face-attribute 'default nil :font
(format "%s:pixelsize=%d" english english-size))
(dolist (charset '(kana han symbol cjk-misc bopomofo))
(set-fontset-font (frame-parameter nil 'font) charset
(font-spec :family chinese :size chinese-size))))
(set-font "Monaco" "Hiragino Sans GB W3" 12 14)
@chaosong
chaosong / install.sh
Created November 21, 2013 14:55
openresty install.sh
./configure --prefix=/opt/openresty \
--with-debug \
--with-http_iconv_module \
--with-http_postgres_module \
--with-luajit \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
@chaosong
chaosong / util.py
Created October 28, 2013 07:15
python snippets
#!/usr/bin/env python
# coding=utf8
import sys
import time
reload(sys)
sys.setdefaultencoding('utf8')
def timeit(method):
@chaosong
chaosong / auth_callback.lua
Last active February 10, 2022 12:44
sso in nginx (by openresty)
local cjson = require('cjson')
local util = require('login_util')
if ngx.var.request_method ~= 'POST' then
ngx.log(ngx.WARN, 'request method is not post')
ngx.exit(400)
end
ngx.req.read_body()
local args = ngx.req.get_post_args()
@chaosong
chaosong / intercept.sh
Created April 8, 2013 04:07
tcpcopy interceptor exclude office ip section
#!/bin/bash
sudo modprobe ip_queue
sudo iptables -I OUTPUT -p tcp --sport 8080 -j QUEUE
sudo iptables -I OUTPUT -d 192.168.98.0/24 -j ACCEPT
sudo intercept
sudo iptables -F OUTPUT
// ==UserScript==
// @name my calepin style
// @namespace
// @description fix max-width of <p> and font-size of code block
// @include http://chaos.calepin.co/*
// @require http://code.jquery.com/jquery-1.6.2.min.js
// ==/UserScript==
$("article p, article ol, article li").css("max-width", "748px");
$(".codehilite *, .gist *").css("font-size", "9pt");