Skip to content

Instantly share code, notes, and snippets.

@hezhao
hezhao / twitter_pin_auth.py
Created February 12, 2013 18:45
Twitter PIN-based authorization using tweepy
### See PIN-based authorization for details at
### https://dev.twitter.com/docs/auth/pin-based-authorization
import tweepy
consumer_key=<your_app_consumer_key>
consumer_secret=<your_app_consumer_secret>
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
@hezhao
hezhao / xbmc_get_title.py
Last active December 12, 2015 13:39
XBMC get current music info (artist and song title)
# WARNING: here getArtist() implicitly converts unicode into str...
self.tag = player.getMusicInfoTag()
artist = self.tag.getArtist()
title = self.tag.getTitle()
# skip weird cases when music stop (title == '') or is streaming (title == 'Streaming...')
if not title or title.lower() == 'streaming...':
print 'title = ' + title
return
@hezhao
hezhao / hangout.applescript
Last active December 14, 2015 02:58
Open Safari, start Google Hangout and stream it live to youtube. It also outputs and returns the iframe embed HTML containing the youtube link.
tell application "Safari" to activate
tell application "Safari"
tell window 1
set current tab to (make new tab with properties {URL:"http://hangout.google.com"})
end tell
delay 5
tell application "System Events"
-- navigate to "Name this hangout"
repeat 10 times
keystroke tab
@hezhao
hezhao / switch_spray.ino
Created April 17, 2013 17:30
toggle servo movement (CCW and then CW) with momentary push button switch.
#include <Servo.h>
Servo myservo;
int servoPin = 9;
int switchPin = 2;
void setup()
{
myservo.attach(servoPin);
@hezhao
hezhao / myapp.conf
Last active May 20, 2022 05:34
Example supervisor config file /etc/supervisor/conf.d/myapp.conf
[program:myapp]
autostart = true
autorestart = true
command = python /home/pi/myapp.py
environment=HOME="/home/pi",USER="pi",SECRET_ID="secret_id",SECRET_KEY="secret_key_avoiding_%_chars"
stdout_logfile = /home/pi/stdout.log
stderr_logfile = /home/pi/stderr.log
startretries = 3
user = pi
@hezhao
hezhao / twcf.ino
Last active December 19, 2015 13:39
// See http://bildr.org/2011/02/74hc595/
int SER_Pin = 11; //pin 14 (Data) on the 75HC595
int RCLK_Pin = 9; //pin 12 (Latch) on the 75HC595
int SRCLK_Pin = 8; //pin 11 (Clock) on the 75HC595
//How many of the shift registers - change this
#define number_of_74hc595s 8
@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');
@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);
void loop()
{
if ( connected )
{
int packetSize = Udp.parsePacket();
if ( packetSize != 0 ) {
Udp.read( data, numPins );
Serial.println( "Data received" );
@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