Skip to content

Instantly share code, notes, and snippets.

View mrjohannchang's full-sized avatar

Johann Chang mrjohannchang

View GitHub Profile
#!/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)
@mrjohannchang
mrjohannchang / two-eggs-problem.py
Last active August 29, 2015 13:59
Two Eggs Problem
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))
@mrjohannchang
mrjohannchang / four-char-reverse.py
Last active August 29, 2015 13:56
魏老師的挑戰狀2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
請用少於 50 (UPD: 45) 個字元的 Python Code 將字串 s 每四個字元為一組反序呈現( s 的長度是 4 的倍數), 舉例 當 s="abcd1234efgh5678"
目前允許多行程式碼: 換行算一個字元, 一層縮排算一個字元
'''
s = 'EFGHABCD56781234'
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#include <unistd.h>
int main() {
FILE * f1 = fopen("output1.txt", "a");
FILE * f2 = fopen("output2.txt", "a");
char buf[4] = {0};
//Dog.java
public class Dog extends Animal {
public final String mMyString = "bark";
@Override
public void doSomething() {
System.out.print(mMyString);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#define BUF_SIZE (1<<16)
#define LIST_LEN (1024*1024*38)
#define WORD_LEN (16)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include <sys/time.h>
#include <pthread.h>