{{ message }}

Instantly share code, notes, and snippets.

# Johann Chang changyuheng

Last active Aug 29, 2015

View four-char-reverse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' 請用少於 50 (UPD: 45) 個字元的 Python Code 將字串 s 每四個字元為一組反序呈現( s 的長度是 4 的倍數), 舉例 當 s="abcd1234efgh5678" 目前允許多行程式碼: 換行算一個字元, 一層縮排算一個字元 ''' s = 'EFGHABCD56781234'
Last active Aug 29, 2015
Two Eggs Problem
View two-eggs-problem.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 n = int(input()) t = [0] * (n + 1) def find_min_test(x, t): if x < 3: t[x] = x return x if t[x]: return t[x] t[x] = min(max(i, 1 + find_min_test(x - i, t)) for i in range(1, x + 1))
Last active Aug 29, 2015
Clicks on mouse button down
View clicks_on_holding.ahk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #SingleInstance force Hotkey, *~\$LButton, LButtonLabel return LButtonLabel: Loop { if (!GetKeyState("ScrollLock", "T") or !GetKeyState("LButton", "P"))
Last active Aug 29, 2015 — forked from lox/docker-enter
View docker-enter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/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
Last active Aug 29, 2015 — forked from yongjhih/couchbase-sync-gateway_init.d
View _etc_init.d_couchbase-sync-gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/bin/sh # # Startup / shutdown script for the couchbase sync_gateway # if [ "\$(id -u)" != "0" ]; then echo "Must run as root" exit 1 fi
Created Feb 2, 2015
find-not-gitted-dir
View find-not-gitted-dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/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,
Created Feb 2, 2015
find-not-repoed
View find-not-repoed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #!/usr/bin/env python3 # -*- coding: utf-8 -*- import argparse import locale import os import re import shlex import subprocess import sys
Last active Aug 29, 2015
Infinite event loop
View coroutine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import asyncio @asyncio.coroutine def hello_world(): while True: yield from asyncio.sleep(1) print('Hello World') @asyncio.coroutine
Last active Aug 29, 2015
Python preprocessed decorator
View api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Api: def __init__(self): self.apis = [] def register(self): s = self class Api: def __init__(self, func): self.func = func
Last active Aug 29, 2015
View solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 class Solution: # @param {TreeNode} root # @return {TreeNode} def invertTree(self, root): if root: root.left, root.right = self.invertTree(root.right), self.invertTree(root.left) return root