Skip to content

Instantly share code, notes, and snippets.

@mondwan
mondwan / find_usage.sh
Last active August 29, 2015 14:16
Usage of Bash command find
# Find filename with gcc under folder /usr
find /usr -name gcc
# Find directory based on filename gcc under folder /usr
find /usr -type d -name gcc
# Find file which modified today under current directory
find -type f -mtime 0
# Find file which filesize is zero
@mondwan
mondwan / command_for_dns.sh
Created March 5, 2015 14:51
Different commands for looking up name server information
# Look up hostname using dns
host linuxfoundation.org
# To look up name server interactively
nslookup linuxfoundation.org
# To look up domain name server information from the name server
dig linuxfoundation.org
@mondwan
mondwan / io_redirect
Created March 14, 2015 05:30
Types of io redirection in Linux
# redirect stdout
echo "hello" > a.out
# redirect stderr
echo "hello" 2> a.out
# redirect both of them
echo "hello" > a.out 2>&1
# shortcut
echo "hello" >& a.out
@mondwan
mondwan / tar_usage.sh
Created March 15, 2015 04:55
Archiving and compressing files in Linux
# Extract files fomr mydir.tar
tar xvf mydir.tar
# Create the archive for file mydir and compress with gzip
tar zcvf mydir.tar.gz mydir
# Create the archive for file mydir and compress with bz2
tar jcvf mydir.tar.bz2 mydir
# Create the archive for file mydir and compress with xz
@mondwan
mondwan / binary_search.py
Created December 22, 2015 15:53
How to do binary search in python
from bisect import bisect_left
# Source https://docs.python.org/2/library/bisect.html
def index(a, x):
'Locate the leftmost value exactly equal to x'
i = bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
raise ValueError
@mondwan
mondwan / bfs.py
Last active December 22, 2015 16:03
How to do bfs in python
from treelib import Tree
tree = Tree()
# Create a tree for demo purpose
tree.create_node('A', 'a')
tree.create_node('B', 'b', parent='a')
tree.create_node('C', 'c', parent='a')
tree.create_node('D', 'd', parent='b')
tree.create_node('E', 'e', parent='b')
tree.create_node('F', 'f', parent='c')
@mondwan
mondwan / dfs.py
Created December 22, 2015 16:03
Demo how to use dfs in python
from treelib import Tree
tree = Tree()
# Create a tree for demo purpose
tree.create_node('A', 'a')
tree.create_node('B', 'b', parent='a')
tree.create_node('C', 'c', parent='a')
tree.create_node('D', 'd', parent='b')
tree.create_node('E', 'e', parent='b')
tree.create_node('F', 'f', parent='c')
@mondwan
mondwan / .gitconfig
Last active February 29, 2016 05:03 — forked from pksunkara/config
# [MUST] Define user information which will be recorded in any newly created commits
[user]
name = Mond Wan
email = mondwan.1015@gmail.com
# [OPTIONAL] Define personal working preferences
[core]
# for window, use true
# for linux, MacOS, use input
autocrlf = input
editor = vim
@mondwan
mondwan / .eslintrc
Last active February 29, 2016 05:04
My .eslintrc
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"amd": true
},
"settings": {
"ecmascript": 6,
"jsx": true
@mondwan
mondwan / React-basic-digest.md
Last active March 19, 2017 16:41
Knowledge digested from react-basic