Skip to content

Instantly share code, notes, and snippets.

View zenja's full-sized avatar

Xing, Wang zenja

View GitHub Profile
@zenja
zenja / .tmux.conf
Last active August 22, 2020 09:41
My tmux config file
# Set prefix key to Ctrl-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# reload settings
unbind r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
# Ctrl-j/k cycles thru windows (no prefix)
@zenja
zenja / ip-monitoring.sh
Last active February 26, 2019 12:18
Poor man's IP reachability monitoring and alerting script
#/usr/bin/env bash
main() {
local ip=$1; shift;
local maxGapMinutes=$1; shift;
local epochLastSuccess=`date +%s`
while true; do
# check if network is good to avoid false alarming
@zenja
zenja / ConsistentHash.java
Created December 27, 2013 00:30
A simple implementation of consistent hash taken from https://weblogs.java.net/blog/2007/11/27/consistent-hashing
import java.util.Collection;
import java.util.SortedMap;
import java.util.TreeMap;
public class ConsistentHash<T> {
private final HashFunction hashFunction;
private final int numberOfReplicas;
private final SortedMap<Integer, T> circle = new TreeMap<Integer, T>();
@zenja
zenja / vsfs.py
Created December 23, 2013 22:27
A simulator for "Very Simple File System" (vsfs) based on http://pages.cs.wisc.edu/~remzi/OSFEP/file-implementation.pdf
#! /usr/bin/env python
import random
from optparse import OptionParser
DEBUG = False
def dprint(str):
if DEBUG:
print str
@zenja
zenja / bfs.py
Created December 21, 2013 15:30
Simple BFS (Breadth-First Search) for graph in Python
from collections import defaultdict
from collections import deque
# adjacency list for the graph
graph = defaultdict(list)
# queue for bfs
q = deque()
# distances of nodes
@zenja
zenja / sample_dfs.py
Created December 15, 2013 22:23
Sample DFS implementation in Python for a tree using adjacency list
from collections import defaultdict
graph = defaultdict(list)
visited = []
for edge in [[1,2], [1,7], [1,8], [2,3], [2,6], [3,4], [3,5], [8,9], [8,12], [9,10], [9,11]]:
graph[edge[0]].append(edge[1])
graph[edge[1]].append(edge[0])
import SocketServer
import BaseHTTPServer
import urllib
PORT = 5678
class Proxy(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
@zenja
zenja / .gitconfig
Created November 4, 2013 10:31
My global git configuration file: .gitconfig
[user]
name = Xing, Wang
email = zenja.wang@gmail.com
[core]
editor = /usr/bin/vim
excludesfile = /Users/wangxing/.gitignore_global
[alias]
co = checkout
ci = commit
st = status
#!/bin/bash
while :
do
clear
git --no-pager log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all
sleep 1
done
@zenja
zenja / CheckUsername.java
Created April 8, 2012 12:46
Check if the username is valid by using regex
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UsernameValidator{
private Pattern pattern;
private Matcher matcher;
private static final String USERNAME_PATTERN = "^[a-z0-9_-]{3,15}$";