SVN to Twitter

I’ve been really getting into developing my KickTweet project and set up a Twitter account for it at http://twitter.com/KickTweet. I wanted to feed in my subversion commits so I did some searching.

What I found was twitvn a monstrous (50-ish ‘real lines) Python script that sends commits to Twitter. I find that ridiculous. So here is my version, it drops right into the post-commit script and could be reduced to 2-3 active lines.

1
2
3
4
5
6
#!/bin/bash
REPOS="$1"
REV="$2"
 
TWEET="SVN Log (r$REV): $(svnlook log $REPOS -r $REV)"
curl -u KickTweet:mySecretPassword -d status="${TWEET:0:139}" http://twitter.com/statuses/update.xml

Note that the use of the ‘${TWEET:0:139}’ is a definite bashism, and not portable.

Update (2008-09-22)
Little tidbit to add into the script right before the curl call. If you want ellipses on commit messages over 140 characters, use this version.

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
REPOS="$1"
REV="$2"
 
TWEET="SVN Log (r$REV): $(svnlook log $REPOS -r $REV)"
 
if [ "${#TWEET}" -gt 140 ]; then
  TWEET="${TWEET:0:137}..."
fi
 
curl -u KickTweet:mySecretPassword -d status="${TWEET:0:139}" http://twitter.com/statuses/update.xml

Posted September 19th, 2008 - Permalink
Categories: BASH - Internet - KickTweet - Snippets
No Comments »
 
Javascript Countdown Timer

I wrote a little countdown timer for my wedding while waiting for stuff to compile today. It uses PHP to get itself initialized, and should be accurate as long as the server has the correct date set. Below is the basic guts of the script. You would call refreshClock() onload.

<?php
  $now = time();
  $wedding = strtotime('August 23, 2008 4:00 pm');
  print 'end = '.$wedding.";\n// Used to fix lag, if any.\n";
  print 'now_p = '.$now.";\n";
?>
now_j = new Date();
diff = Math.ceil(now_j.valueOf()/1000) - now_p;
function refreshClock () {
  now_r = new Date();
  seconds = end - Math.ceil(now_r.valueOf()/1000) + diff;
  document.getElementById('days').innerHTML = Math.floor(seconds/60/60/24);
  document.getElementById('hours').innerHTML = Math.floor((seconds/60/60)%24);
  document.getElementById('minutes').innerHTML = Math.floor((seconds/60)%60);
  document.getElementById('seconds').innerHTML = seconds%60;
  setTimeout("refreshClock()",1000);
}

Posted May 20th, 2008 - Permalink
Categories: JavaScript - PHP - Programming - Snippets
No Comments »
 
Easy Makefiles

Here’s a handy g++ option that will let you make up accurate makefiles in a jiffy, -MM.

g++ -MM *.cpp

Run that on your source directory and you’ll get a makefile style list of includes. If it doesn’t work, make sure you add in your compile time defines (like -D_x86 -D_LINUX). This won’t actually check that you need the files you have included, it just makes a list of the ones you have included.

I like to add a sed line to make breaks between source files, like so.

g++ -MM *.cpp | sed 's/^\([a-zA-Z]\)/\n\1/'

It’s very literal though, so if you do “../StaticDevice.h” type includes, watch out for double entries.

$ g++ -MM -D_x86 -D_LINUX devices/*.cpp | sed 's/^\([a-zA-Z]\)/\n\1/'
 
BaseDevice.o: devices/BaseDevice.cpp devices/BaseDevice.h devices/Enums.h
 
BaseStream.o: devices/BaseStream.cpp devices/BaseStream.h
 
CameraTest.o: devices/CameraTest.cpp devices/../camera.h \
  devices/../devices/Nikon/NikonDevice.h \
  devices/../devices/Nikon/../StaticDevice.h \
  devices/../devices/StaticDevice.h \
  devices/../devices/Panasonic/PanasonicDevice.h \
  devices/../devices/Panasonic/../StaticDevice.h \
  devices/../devices/BaseDevice.h devices/../devices/Enums.h \
  devices/../devices/Prosilica/ProsilicaStaticDevice.h \
  devices/../devices/Prosilica/ProsilicaDevice.h \
  devices/../devices/Prosilica/../BaseDevice.h \
  devices/../devices/Prosilica/ProsilicaDeviceConfigurator.h \
  devices/../devices/Prosilica/../inc-pc/PvApi.h \
  devices/../devices/Prosilica/../Enums.h \
  devices/../devices/Prosilica/../StaticDevice.h
$

Posted October 8th, 2007 - Permalink
Categories: Linux - Programming - Snippets - Uncategorized
No Comments »
 
C++ String Strip Whitespace

I was at work today and had the hardest time trying to find a function that could strip out whitespace from a string. There isn’t one built into C++, and I can’t just add on libraries (e.g. boost) just for this sort of one-time use item. I couldn’t find an easy drop in on the web either, so I wrote my own based on a templating system I had made.

1
2
3
4
5
6
7
8
9
10
11
12
13
string trimstring (string toTrim) {
 
	size_t found;
	found = toTrim.find(" ");
 
	while(toTrim.length() != 0 && found != string::npos) {
		toTrim.erase(found,1);		
		found = toTrim.find(" ");
	}
 
	return toTrim;
 
}

Very brute-force, but easy to understand right?

Posted August 6th, 2007 - Permalink
Categories: C++ - Programming - Snippets - Work
No Comments »
 
JavaScript Class Definitions

I had a hard time understanding basic classes in JavaScript and the tutorials I found all got way to bogged down in useless fluff, so I thought I’d put up this no-nonsense example of a JavaScript class. Expect a version using Base.js once I learn that way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function myClass () {
  var privateVariable = 'Private';
  this.publicVariable = 'Public';
 
  this.getPrivate =
    function () {
      return privateVariable;
    }
}
 
myCopy = new myClass();
alert(myCopy.publicVariable);
alert(myCopy.getPrivate());
alert(myCopy.privateVariable);

Output (In Alerts)
Public
Private
undefined

Posted May 24th, 2007 - Permalink
Categories: JavaScript - Programming - Snippets
No Comments »
 
More Posts
« Older
Newer »