Skip to content

Instantly share code, notes, and snippets.

@hezhao
hezhao / ls_filesize_name.sh
Created August 4, 2015 19:47
Print file size and name
$ ls -ls | awk '{print $7,$11}'
@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 / 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 / alipay.html
Created March 28, 2016 03:34
支付宝生活支付按钮
<form action="https://shenghuo.alipay.com/send/payment/fill.htm" method="post" target="_blank" accept-charset="GBK" id="alipayForm">
<input name="optEmail" type="hidden" value="zph61@139.com" />
<input name="payAmount" type="hidden" value="1.00" />
<input id="title" name="title" type="hidden" value="捐赠给”前端技术分享”网站" />
<input name="memo" type="hidden" value="文章写的不错,支持站长,我来捐赠鼓励的!" />
<input name="pay" type="image" src="https://img.alipay.com/sys/personalprod/style/mc/btn-index.png" width="250" height="58">
</form>
@hezhao
hezhao / RPi.sh
Created August 13, 2016 06:05
Raspberry Pi setup commands
$ sudo raspi-config
$ sudo apt-get update
$ sudo apt-get install supervisor