Tuesday, October 20, 2009

So that I don't ever lose this information (it was very very hard to find/figure out), here is how you should compile programs using the portaudio library on a Mac:
(YOU MUST LINK libportaudio.a TO YOUR PROJECT (obviously) )
gcc YOURPROGRAM.c libportaudio.a -framework CoreAudio -framework AudioToolbox -framework AudioUnit -framework CoreServices -o YOURPROGRAM

Not so hard to find, but I may possibly need at some point in time:
For Linux:
gcc -lrt -lasound -ljack -lpthread -o YOUR_BINARY main.c libportaudio.a


For Windows:

Good question....it's not in the documentation (kind of like how the Mac compilation info wasn't), but I'm assuming it's somewhere close to how you would do it with Linux (unless you're using MSVC++...which I won't be)

Friday, August 1, 2008

Smackbook Pro

Today I noticed on reddit, an article titled "Knock-based Commands for Your Linux Laptop", which showed you how to take advantage of the accelerometer in your (IBM/Lenovo Thinkpad) laptop to allow you to issue commands by physically tapping your laptop. It's a really great idea, and I got to thinking about my laptop (a Macbook Pro,which does indeed have an accelerometer in it) and wondered how I could emulate this idea. It turns out it had already been done. In fact, this guy wrote about it two months before the previously mentioned article. It requires a program which reports data from the sensor and a script which uses this data to issue any particular command. It's slightly complicated (if you're not used to compiling programs) but can be simplified A LOT if you're using Leopard. I rewrote his program in python and added an applescript within the program which allows you to switch virtual desktops (spaces, whatever) by tapping the side of your screen. It's really neat, but it probably needs to be tweaked a good deal.

Anyway, here is the program:
#Detect taps via AMSTracker in order to change
#spaces. Based on the Perl script by Erling Ellingsen (http://blog.medallia.com/2006/05/smacbook_pro.html)
#
#by Sean Brewer (http://seabre986.googlepages.com)

#Note:
#AMSTracker MAY NOT BE DISTRIBUTED WITH THIS PROGRAM.
#The author of AMSTracker does not allow distribution (without his permission anyway)
#so, in order to use this script you must download AMSTracker from:
# http://www.osxbook.com/software/sms/amstracker/
#If anyone actually reads this PLEASE PLEASE PLEASE someone
#come up with a free software alternative to this! If I have time I'll do it!

#License:
#This program is licensed under the GPL.
#See http://www.gnu.org/licenses/gpl.txt for more details.

#Instructions: It's simple really.
#1. Download AMSTracker and put this program and AMSTracker into the
# same directory.
#2. Run this program. If you don't know how, ask a friend.
#3. Tap the side of your screen to change spaces.
from os import waitpid
from subprocess import Popen,PIPE
from signal import SIGTERM

amscheck = Popen (["./AMSTracker","-s","-u0.01"], stdout=PIPE)
stable = 0

#Hopefully you have at least one space, right?
space = 1

#This is the maximum number of spaces
#on my mac, though yours may be more or less, so
#change this accordingly.
space_max = 4

#The actual script to change spaces.
def spaces_script(num):
return """osascript -e 'tell application "System Events"
tell process "Finder"
keystroke\"""" + str(num) + """\" using control down
end tell
end tell'"""
while 1:
i = amscheck.stdout.readline().split()

if len(i) > 3:
continue

i = map(lambda j: int(j),i)
#We get a signed short written as two unsigned bytes.
if i[0] < 0:
i[0] += 256

x = (i[1] * 256) + i[0]

if abs(x) < 20:
stable += 1

if abs(x) > 30 and stable > 30:
stable = 0
#The logic here allows for movement
#to the next specified (by the tap) space.
if x < 0 and space == 1:
space += 1
elif x < 0 and space == space_max:
space -= 1
elif x < 0:
space -= 1
else:
space += 1

#I really need to make this cleaner.
p = Popen (spaces_script(space), shell=True)
sts = waitpid(p.pid,0)




It's really simple to run. All you need to do is download the script: here
and then download the program to get the sensor data: here

Put both programs into the same directory, and then run smack.py, then test it out. It should work.

Tuesday, July 29, 2008

Thursday, July 17, 2008

To Those Who Use Flash mp3 Players

If you want people to listen to an mp3 or some other audio format, but need to hide it so that it can't be downloaded, don't do it like this:
No.     Time        Source                Destination           Protocol Info
10 3.226133 xxx.xxx.xxx.xxx 208.218.214.207 HTTP GET /audio/one-day-as-a-lion-wild_international.mp3 HTTP/1.1

Frame 10 (803 bytes on wire, 803 bytes captured)
Ethernet II, Src: Apple_c5:69:76 (xx:xx:xx:xx:xx:xx), Dst: Pni_21:32:01 (00:0c:10:21:32:01)
Internet Protocol, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 208.218.214.207 (208.218.214.207)
Transmission Control Protocol, Src Port: 54728 (54728), Dst Port: http (80), Seq: 1, Ack: 1, Len: 737
Hypertext Transfer Protocol
GET /audio/one-day-as-a-lion-wild_international.mp3 HTTP/1.1\r\n
Request Method: GET
Request URI: /audio/one-day-as-a-lion-wild_international.mp3
Request Version: HTTP/1.1
Referer: http://www.okayplayer.com/component/option,com_myblog/show,Audio-One-Day-As-A-Lion-Wild-International-.html/Itemid,140/\r\n
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1\r\n
Accept: */*\r\n
Accept-Language: en-us\r\n
Accept-Encoding: gzip, deflate\r\n
Cookie: __qca=1216283565-53773085-91470207; __qcb=397966741; __utma=132546704.1432803422.1216283568.1216283568.1216283568.1; __utmb=132546704; __utmc=132546704; __utmz=132546704.1216283568.1.1.utmccn=(referral)|utmcsr=reddit.com|utmcct=/r/
Connection: keep-alive\r\n
Host: blogs.okayplayer.com\r\n
\r\n

From this data taken from a packet sniffer, it is fairly easy to see that the flash player (from here) is accessing the url http://blogs.okayplayer.com/audio/one-day-as-a-lion-wild_international.mp3

Fall 2008 Books

These, apparently, are the books for my classes I'm taking this coming semester:

Principles of Modern Operating Systems

Haskell School of Expression
Piano for the Developing Musician
Chemistry in Your Life
Puntos de partida

Puntos de partida : Workbook
Puntos de partida : Laboratory Manual

Here is a breakdown of the cost of each book compared to my school's and to amazon.com (who is usually the least expensive)


* - Lowest price was actually about $25.00, but it it was supposed to have been in fairly terrible condition, so I went the next cheapest, which is actually on par with the price of other used copies of this book.
** - I think I already own this book.

Also another note, where the price was N/A the price for the book that was available was substituted (i.e. where the new version of the book was not available, the price of the used one was substituted). Also, shipping on the Amazon.com books will be at least $4 a piece, which still makes buying from them much more sensible than the school's bookstore.


As you can see, I can spend as much as $605.99 or as little as $190.81. Which option do you think that my broke college student self is going to go with? The used option that isn't from my school's bookstore of course.

Friday, July 4, 2008