Skip to content

Instantly share code, notes, and snippets.

@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 / 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
#version 120
uniform sampler2D uSampler;
varying vec2 vUv;
void main()
{
// if ( !gl_FrontFacing ) {
// discard;
@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');
/* 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 / 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;
@hezhao
hezhao / lcd_i2c.ino
Created March 24, 2014 22:24
YwRobot LCM1602 IIC V1 20x4 LCD Display with PCF8574T
// See http://forum.arduino.cc/index.php?topic=158312.0
// NewLiquidCrystal library
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Define I2C Address for the PCF8574T
void loop()
{
if ( connected )
{
int packetSize = Udp.parsePacket();
if ( packetSize != 0 ) {
Udp.read( data, numPins );
Serial.println( "Data received" );
@hezhao
hezhao / oscillator.m
Last active December 22, 2015 06:49
Wave form function generator in Matlab, it also plays the wave sound.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Example:
%%%
%%% Create a 3000Hz triangel wave data for 3 seconds, and
%%% play the wave data at 44100Hz (default) sample rate, also
%%% save to .wav file.
%%%
%%%
%%% wave = OSCILLATOR('Triangle', 3, 3000);
%%% soundsc(wave, 44100);
@hezhao
hezhao / draw.m
Last active December 21, 2015 04:59
Draw random dots within black filled circle
%
% Draw random dots within black filled circle
% Dots number from 89 to 299
%
for n = 89:299
% Draw filled circle
f = figure;
filledCircle([0,0], 1,1000, 'k');