Skip to content

Instantly share code, notes, and snippets.

Avatar

Johann Chang changyuheng

View GitHub Profile
@changyuheng
changyuheng / api.py
Last active Aug 29, 2015
Python preprocessed decorator
View api.py
class Api:
def __init__(self):
self.apis = []
def register(self):
s = self
class Api:
def __init__(self, func):
self.func = func
@changyuheng
changyuheng / coroutine.py
Last active Aug 29, 2015
Infinite event loop
View coroutine.py
import asyncio
@asyncio.coroutine
def hello_world():
while True:
yield from asyncio.sleep(1)
print('Hello World')
@asyncio.coroutine
View find-not-repoed
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import locale
import os
import re
import shlex
import subprocess
import sys
View 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,
@changyuheng
changyuheng / 20-noto-cjk.conf
Created Nov 15, 2014
.config/fontconfig/conf.d/20-noto-cjk.conf
View 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>
View _etc_init.d_couchbase-sync-gateway
#!/bin/sh
#
# Startup / shutdown script for the couchbase sync_gateway
#
if [ "$(id -u)" != "0" ]; then
echo "Must run as root"
exit 1
fi
View docker-enter
#!/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
@changyuheng
changyuheng / clicks_on_holding.ahk
Last active Aug 29, 2015
Clicks on mouse button down
View clicks_on_holding.ahk
#SingleInstance force
Hotkey, *~$LButton, LButtonLabel
return
LButtonLabel:
Loop
{
if (!GetKeyState("ScrollLock", "T") or !GetKeyState("LButton", "P"))
View bfs.py
# 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
View dfs.py
# 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)