Skip to content

Instantly share code, notes, and snippets.

View mrjohannchang's full-sized avatar

Johann Chang mrjohannchang

View GitHub Profile
@mrjohannchang
mrjohannchang / api.py
Last active August 29, 2015 14:21
Python preprocessed decorator
class Api:
def __init__(self):
self.apis = []
def register(self):
s = self
class Api:
def __init__(self, func):
self.func = func
@mrjohannchang
mrjohannchang / coroutine.py
Last active August 29, 2015 14:21
Infinite event loop
import asyncio
@asyncio.coroutine
def hello_world():
while True:
yield from asyncio.sleep(1)
print('Hello World')
@asyncio.coroutine
@mrjohannchang
mrjohannchang / find-not-repoed
Created February 2, 2015 06:07
find-not-repoed
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import locale
import os
import re
import shlex
import subprocess
import sys
@mrjohannchang
mrjohannchang / find-not-gitted-dir
Created February 2, 2015 06:06
find-not-gitted-dir
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import locale
import shlex
import subprocess
def _execute(cmd):
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE,
@mrjohannchang
mrjohannchang / 20-noto-cjk.conf
Created November 15, 2014 17:41
.config/fontconfig/conf.d/20-noto-cjk.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test name="lang">
<string>zh-tw</string>
</test>
<test name="family">
<string>sans-serif</string>
</test>
#!/bin/sh
#
# Startup / shutdown script for the couchbase sync_gateway
#
if [ "$(id -u)" != "0" ]; then
echo "Must run as root"
exit 1
fi
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "You must be root to execute this script" 2>&1
else
PID=$(docker inspect --format "{{ .State.Pid }}" "$1")
nsenter --target $PID --mount --uts --ipc --net --pid
fi
@mrjohannchang
mrjohannchang / clicks_on_holding.ahk
Last active August 29, 2015 14:01
Clicks on mouse button down
#SingleInstance force
Hotkey, *~$LButton, LButtonLabel
return
LButtonLabel:
Loop
{
if (!GetKeyState("ScrollLock", "T") or !GetKeyState("LButton", "P"))
@mrjohannchang
mrjohannchang / bfs.py
Last active January 5, 2019 00:42
BFS
# Ref. http://eddmann.com/posts/depth-first-search-and-breadth-first-search-in-python/
def bfs(graph, queue, visited=None):
if visited is None:
visited = set()
if not queue:
return
start = queue.pop(0)
yield start
@mrjohannchang
mrjohannchang / dfs.py
Last active January 5, 2019 00:40
DFS
# Ref. http://eddmann.com/posts/depth-first-search-and-breadth-first-search-in-python/
def dfs(graph, start, visited=None):
if visited is None:
visited = set()
if start in visited:
return
yield start
visited.add(start)