Skip to content

Instantly share code, notes, and snippets.

@hezhao
hezhao / bwratio.matlab
Created March 29, 2014 07:11
Count the percentage of black and white pixels in an RGB-converted-to-grayscale image
filename = 'irregular.bmp';
RGB = imread(filename);
grayscale = rgb2gray(RGB);
numTotalPixel = size(grayscale,1) * size(grayscale, 2);
numBlackPixel = sum(grayscale(:)==0);
numWhitePixel = sum(grayscale(:)==255);
percentBlackPixel = numBlackPixel / numTotalPixel * 100;
percentWhitePixel = numWhitePixel / numTotalPixel * 100;
/* Sleep Demo Serial
* -----------------
* Example code to demonstrate the sleep functions in a Arduino. Arduino will wake up
* when new data is received in the serial port USART
* Based on Sleep Demo Serial from http://www.arduino.cc/playground/Learning/ArduinoSleepCode
*
* Copyright (C) 2006 MacSimski 2006-12-30
* Copyright (C) 2007 D. Cuartielles 2007-07-08 - Mexico DF
*
* With modifications from Ruben Laguna 2008-10-15
@hezhao
hezhao / checkerboard7x11
Created June 25, 2014 23:07
Print a checkerboard of 7x11 inner corners with 400px square
I = checkerboard(400,4,6) > 0.5;
imwrite(I, 'check.png');
#version 120
uniform sampler2D uSampler;
varying vec2 vUv;
void main()
{
// if ( !gl_FrontFacing ) {
// discard;
@hezhao
hezhao / qt4xcode.sh
Last active August 29, 2015 14:04
Create and deploy Xcode project from Qt 4 .pro file
## http://dragly.org/2012/01/13/deploy-qt-applications-for-mac-os-x/
## http://bleepsandpops.com/post/8447919182/adding-the-fmod-api-to-an-xcode-4-project
$ qmake -spec macx-xcode yourprojectname.pro
$ macdeployqt yourappname.app -dmg
## $ otool -L yourappname.app/Contents/MacOS/yourappname
## $ install_name_tool -change /app_dir/lib.dylib @executable_path/../Frameworks/Versions/lib.dylib yourappname
@hezhao
hezhao / maya_shortcuts
Created October 14, 2014 23:09
Maya Shortcuts
- Modify -> Center Pivot. Make world pivots go to the center of the mesh.
- Modify -> Freeze Transformations. Reset translation and rotation axes.
@hezhao
hezhao / opencv_cmake.sh
Last active August 29, 2015 14:09
Build OpenCV static libraries from source using cmake
# build static libraries for both i386 and x86_64 arch
$ mkdir build
$ cd build
$ cmake -DBUILD_SHARED_LIBS=OFF "-DCMAKE_OSX_ARCHITECTURES=i386;x86_64" ..
$ make -j8
@hezhao
hezhao / arch.sh
Last active August 29, 2015 14:09
Check the architectures of a library
# Linux / Mac
$ lipo -info filename.a
$ file filename.a
# Windows
$ dumpbin /rawdata:1 library.lib
$ dumpbin /headers program.exe
@hezhao
hezhao / advanced_copy.sh
Last active August 29, 2015 14:13
Copy every nth file and show progress bar
# http://www.tecmint.com/advanced-copy-command-shows-progress-bar-while-copying-files/
#
$ wget https://dl.dropboxusercontent.com/u/6233134/cp
$ sudo chmod +x cp
$ ./cp -gR src/*[13579].jpg dest/
@hezhao
hezhao / multithreading.cpp
Created May 26, 2015 19:25
Example of shared data with multiple threads in C++
#include <atomic>
#include <conio.h>
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
using namespace std;
atomic<int> data(0);