Archive for the ‘Code’ Category

Tracking an outbound link as a goal with Google Analytics

As part of some SEO I’ve been doing, I’ve been wanting to track an outbound link (specifically, to the app store) as a goal in Google Analytics.

The roundabout explanation is that the Google Documentation for tracking outbound links is wrong, because they want you to track it as an event (and events cannot be goals).  Here’s the right way:

//<!--Normal GA code in header-->
    function recordLink(link,newname)
  {
    try {
          var pageTracker = _gat._getTracker('UA-8841539-3');
      pageTracker._trackPageview(newname);
      setTimeout('document.location ="' + link.href + '"',100)
    } catch(err){window.alert(err)}
  }
</script>

Then just format your links like this:

<a href="http://real-url.com" onClick="recordLink(this,'/fake/goal/url');return false;">URL text</a>

This will redirect the user to real-url.com, and log it to GA as http://currentdomain.com/fake/goal/url enabling you to treat it as a goal.

bassdll – an Arduino Piezo music library

I’m finally getting around to publishing bassdll, a project that (unfortunately) has sat on my shelf for over a year now.

bassdll is an arduino sound/music engine that lets you wire up piezo buzzers across your arduino pins and make multichannel music!

Check out the demo below:

Check out the source on github.

Tower of Hanoi in MIPS (32 instructions)

##############################
####DREW CRAWFORD#############
####ASSIGNMENT 2##############
####COMPUTER ARCHITECTURE#####
####FEB 2 2010########
##############################
.data
.align 2
A: .asciiz "A\n"
.align 2
B: .asciiz "B\n"
.align 2
C: .asciiz "C\n"
prompt: .asciiz "How many disks?"
.align 2
newline: .asciiz "\n"
.align 2
print:  .asciiz "Move from \n"
.align 2
to: .asciiz " to \n"
.align 2
movet: .asciiz "The total number of moves is: \n"

.text
la $a0,prompt
li $v0,51
syscall
move $t0,$a0

#####t0 - n
#####a1 - "A"
#####a2 - "B"
#####a3 - "C"
la $a1,A
la $a2,B
la $a3,C
jal hanoi
#print totals
la $s1,movet
jal printstr
move $a0,$v1
li $v0,1
syscall
li $v0,10
syscall

li $v1,0

#A hanoi solution in 32 instructions
#(11 print instructions, 1 move count instruction)
#So only 20 algorithmic instructions.
#And only one expensive lw/sw pair per call.
#Beat that.
hanoi:
beq $t0,0,silentreturn
addi $t0,$t0,-1
xor $a2,$a2,$a3
xor $a3,$a2,$a3
xor $a2,$a2,$a3
addi $sp,$sp,-4
sw $ra,0($sp)
jal hanoi
##############non-algoirthmic section
#An implementation detail prevents me from using the printstr syscall on my emulator
#Feel free to replace with the syscall
la $s1, print
jal printstr
move $s1, $a1
jal printstr
la $s1,to
jal printstr
move $s1, $a3
jal printstr
la $a0,newline
la $v0,4
syscall
addi $v1,$v1,1
#############end non-algorithmic section
move $t1,$a3
move $a3,$a1
move $a1,$a2
move $a2,$t1
jal hanoi
xor $a1,$a1,$a3
xor $a3,$a1,$a3
xor $a1,$a1,$a3
lw $ra,0($sp)
addi $sp,$sp,4
addi $t0,$t0,1
silentreturn: jr $ra

printstr: #my hack around a printstr issue on my emulator
ld $s2,($s1)
andi $a0,$s2,255 #select xxxX
li $v0,11
beq $a0,10,ret
syscall
andi $a0,$s2,65280 #select xxXx
srl $a0,$a0,8
beq $a0,10,ret
syscall
andi $a0,$s2,16711680 #select xXxx
srl $a0,$a0,16
beq $a0,10,ret
syscall
andi $a0,$s2,4278190080 #select Xxxx
srl $a0,$a0,24
beq $a0,10,ret
syscall
addi $s1,$s1,4
j printstr
ret: jr $ra

Phonepipe now open source

Phonepipe was one of my random app ideas that really never got the love and attention it deserved. I wrote it in a weekend, and then Monday happened and real work happened and it ended up on the shelf. There never was a terribly big market for it, and it would be too much work for people to run their own server stack just to get one-off notifications when the compile was done.

Well today I’m finally releasing it. Notifo published a new API allowing you to send notifications to yourself. In the space of about an hour, I copy-pasta-ed some old phonepipe code to target the new API.

Phonepipe has changed the way I work. I’m much more apt to go take a walk or get involved in a conversation with someone knowing that I’ll be pinged as soon as the download’s done and it won’t cost me any precious work time. I’ve found myself outside more, more social, and overall more productive. Not bad for a crappy little python script.

Go play with phonepipe. Patches and feedback welcome.

mailComposeDelegate

If you’re trying to talk to an MFMailComposeViewController and are setting the delegate property (you know, like every other class in the iPhone SDK), you’re doing it wrong. You need to set mailComposeDelegate.

Oh, and just to confuse you, delegate is left in, so as not to cause any warnings or compile errors. It just silently fails.

OS X and posix.1b RTS extensions

Why doesn’t OS X support POSIX.1b?  No, really?

I’m working on writing a threadsafe compiler as part of my research project this summer.  The RTS extensions allow you to send an integer or pointer along with a signal (via the sigqueue function).  Unfortunately, sigqueue and much of RTS is missing from OS X Leopard, as it’s an optional part of the SUS / UNIX 03 spec.

The really odd thing is that it implements enough of POSIX.1b to receive integers/pointers from a sending process, but not enough to send them.  WTF?

Any thoughts on portably sending an integer value between process in a high-performance way?  Pipes just don’t seem as clean as a sigqueue call…

Return top