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 / bluetooth.py
Last active September 25, 2017 18:54
Trying PyBluez
import bluetooth
print "Start discovering...."
nearby_devices = bluetooth.discover_devices()
print "Found devices:"
for bdaddr in nearby_devices:
print bluetooth.lookup_name( bdaddr ), "with address:", bdaddr
@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 / remove_c_style_comments.py
Last active March 12, 2024 16:42
Python: Remove C/C++ style comments #parser
#!/usr/bin/python
import re
import sys
def removeComments(text):
""" remove c-style comments.
text: blob of text with comments (can include newlines)
returns: text with comments removed
"""
pattern = r"""
@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
"""