Skip to content

Instantly share code, notes, and snippets.

@zhao-ji
zhao-ji / initialize_host.sh
Last active March 29, 2024 09:29
Initialize a new host
# Copy public key into .ssh/unthorized_keys
# config locales to en.US-utf-8 and zh, set c.UTF-8 as default locale
sudo dpkg-reconfigure locales
# set timezone
sudo timedatectl set-timezone Pacific/Auckland
# add swap file: https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-debian-11
# add disk as db data folder: https://www.digitalocean.com/community/tutorials/how-to-partition-and-format-storage-devices-in-linux
{
init: function(elevators, floors) {
var elevator = elevators[0]; // Let's use the first elevator
var elevator1 = elevators[1]; // Let's use the first elevator
// Whenever the elevator is idle (has no more queued destinations) ...
elevator.on("idle", function() {
// let's go to all the floors (or did we forget one?)
elevator.goToFloor(0);
});
@zhao-ji
zhao-ji / JapaneseRegex.js
Created April 22, 2020 03:11 — forked from ryanmcgrath/JapaneseRegex.js
Regex to test for presence of Japanese characters
// REFERENCE UNICODE TABLES:
// http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
// http://www.tamasoft.co.jp/en/general-info/unicode.html
//
// TEST EDITOR:
// http://www.gethifi.com/tools/regex
//
// UNICODE RANGE : DESCRIPTION
//
// 3000-303F : punctuation
@zhao-ji
zhao-ji / eslint.sh
Created March 13, 2020 02:04
install the eslint for raw machine
npm i -g eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react
var inputs = document.querySelectorAll("input.js-toggler-target[value='Follow']");
for(var i=0; i<inputs.length;i++) {inputs[i].click();}
@zhao-ji
zhao-ji / unshorten.py
Created July 12, 2018 02:12
recurse unshorten url
# This is for Py2k. For Py3k, use http.client and urllib.parse instead, and
# use // instead of / for the division
import httplib
import urlparse
def unshorten_url(url):
parsed = urlparse.urlparse(url)
h = httplib.HTTPConnection(parsed.netloc)
resource = parsed.path
if parsed.query != "":
sudo python -m smtpd -c DebuggingServer -n localhost:25
@zhao-ji
zhao-ji / tun-ping-linux.py
Created July 28, 2016 09:30 — forked from glacjay/tun-ping-linux.py
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2
@zhao-ji
zhao-ji / start-stop-example.sh
Created July 26, 2016 09:02 — forked from alobato/start-stop-example.sh
start-stop-example
#!/bin/sh
# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh
set -e
# Must be a valid filename
NAME=foo
PIDFILE=/var/run/$NAME.pid
#This is the command to be run, give the full pathname
DAEMON=/usr/local/bin/bar
[admin@RouterOS] > /ip firewall layer7-protocol add name=example.com regexp=example.com
[admin@RouterOS] > /ip firewall mangle add chain=prerouting dst-address=10.0.0.254 layer7-protocol=example.com action=mark-connection new-connection-mark=example.com-forward protocol=tcp dst-port=53
[admin@RouterOS] > /ip firewall mangle add chain=prerouting dst-address=10.0.0.254 layer7-protocol=example.com action=mark-connection new-connection-mark=example.com-forward protocol=udp dst-port=53
[admin@RouterOS] > /ip firewall nat add action=dst-nat chain=dstnat connection-mark=example.com-forward to-addresses=10.0.1.11
[admin@RouterOS] > /ip firewall nat add action=masquerade chain=srcnat connection-mark=example.com-forward