Skip to content

Instantly share code, notes, and snippets.

@ChunMinChang
ChunMinChang / foo.html
Created December 21, 2014 01:54
html basic template
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css" media="all">
</style>
@ChunMinChang
ChunMinChang / foo.cpp
Last active August 29, 2015 14:11
language binding
#include "foo.h"
void
Foo::hello(){
std::cout << "Hello world" << std::endl;
}
int
Foo::add(int a, int b){
return a + b;
@ChunMinChang
ChunMinChang / binary_search_tree.cpp
Last active August 29, 2015 14:12
Recursive Binary Search Tree
#include <iostream>
#include <iomanip>
#include "binary_search_tree.h"
bool
BinarySearchTree::lookup(node* n, int d)
{
if(!n){
return false;
}
@ChunMinChang
ChunMinChang / binary_search_tree.cpp
Last active August 29, 2015 14:12
Iterative Binary Search Tree
#include <iostream>
#include <iomanip>
#include "binary_search_tree.h"
bool
BinarySearchTree::lookup(node* n, int d)
{
while(n){
if(d == n->data){
return true;
@ChunMinChang
ChunMinChang / binary_tree.cpp
Created January 19, 2015 14:02
Serialize and Deserialize a Binary Tree
#include "binary_tree.h"
#include <iostream> // std::cout
#include <iomanip> // std::setw
#include <string> // std::string
#include <sstream> // std::istringstream
bool
BinaryTree::ReadNext(std::ifstream& fin, int* data, bool* isNumber)
{
if(!fin.is_open() || !fin.good()){
@ChunMinChang
ChunMinChang / GetAllDescendantsOfNode.cpp
Created March 5, 2015 06:10
Get all the descendant nodes of one tree node
#include <iostream> // std::cout
#include <iomanip> // std::setw()
#include <vector> // std::vector
std::vector<int> getDescendants(std::vector<std::vector<int>> tree, int node){
std::vector<int> descendants;
descendants.insert(descendants.end(), tree[node].begin(), tree[node].end());
for(int i = 0 ; i < descendants.size() ; i++){
if( descendants[i] < tree.size() && !tree[descendants[i]].empty() ){
//append
@ChunMinChang
ChunMinChang / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ChunMinChang
ChunMinChang / dictionaryDiffer.py
Created September 8, 2015 09:16
Python: Diff the dictionary
#!/usr/bin/python
class DictDiffer(object):
"""
Calculate the difference between two dictionaries as:
(1) items intersected
(2) items added
(3) items removed
(4) keys same in both but changed values
(5) keys same in both and unchanged values
"""
@ChunMinChang
ChunMinChang / os_detect.sh
Created January 13, 2016 04:12
Detect your OS
case "$OSTYPE" in
solaris*) echo "SOLARIS" ;;
darwin*) echo "OSX" ;;
linux*) echo "LINUX" ;;
bsd*) echo "BSD" ;;
cygwin) echo "cygwin" ;;
*) echo "unknown: $OSTYPE" ;;
esac
@ChunMinChang
ChunMinChang / HardwareKeyboardSimulator.sh
Last active January 13, 2016 08:33
Simulate hardware keyboard input
#!/bin/bash
# Get the simulated key
KEY=$1
#print variable on a screen
echo "Send heardware key '$KEY'"
case "$OSTYPE" in
darwin*)
echo "OSX"
# osascript -e 'tell application System Events" to key code 0'