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 / License
Last active September 25, 2025 16:34
Python: Remove C/C++ style comments #parser
Copyright 2025 Chun-Min Chang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OT
@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
"""