A Dutch techie in China
13 Apr
@kofai asked me to share my Fanfou to Twitter sync script. It’s not art, but it works, so here goes:
<?php define(STATUS_PATH, '/home/www/twitbridg/status/'); include_once('password.php'); $since_id = file_get_contents(STATUS_PATH.$twitter_username.'.last') OR $since_id = '1'; // The twitter API address $url = 'https://twitter.com/statuses/user_timeline/'.$twitter_username.'.xml?since_id='.$since_id; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_GET, 1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)) die('failed to get tweets: '.$since_id."\n"); $xml = new SimpleXMLElement($buffer); $i = sizeof($xml->status)-1; if($i<0) exit; while($i >= 0) { // Update FanFou $url = 'http://api.fanfou.com/statuses/update.xml'; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "source=".urlencode("<a href=\"http://twitter.com/".$twitter_username."\">Twitter</a>")."&status=".urlencode($xml->status[$i]->text)); curl_setopt($curl_handle, CURLOPT_USERPWD, "$fanfou_username:$fanfou_password"); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $i--; } $last_id = $xml->status[0]->id; $fp = fopen(STATUS_PATH.$twitter_username.'.last', 'w'); fwrite($fp, $last_id); fclose($fp); ?>
As you can see it includes a password.php. This sets a few login variables. You can just insert them at the top of the above PHP file, but as I edit my code in public places I prefer not to do that.
<?php $twitter_username = 'nielspeen'; $fanfou_username = 'nielspeen'; $fanfou_password = '123xyz'; ?>
Enjoy!
12 Mar
The Chinese like to share their movies in RMVB (RealMedia) format as opposed to Xvid or DivX. Not sure why it got to be so popular (I would prefer the more open Xvid), but the file sizes and quality it produces are quite good.
A problem I ran into is that mplayer/vlc don’t seem to play these files without a bit of tinkering. I found a lot of how-to’s that tell you how to make it work, but non really straight forward on a 64-bit system.
Mplayer supports a number of codec libraries though, and more than one may get you result.
Where many how-to’s told me to install the RV40 codec (which I couldn’t find in 64-bit), I used the RV3040 that comes with Ubuntu by default instead. This fixes video.
For sound, the often mentioned solution was to install the w32codecs and use the cook codec. In my case however this resulted in choppy sound. Instead I use the ffcook codec (found in libmad) instead (also in Ubuntu by default.)
Finally my command line looks like:
mplayer -vc rv3040 -ac ffcook movie.rmvb
3 Feb
AliPay is the Paypal of China and hard to ignore if you want to use websites like TaoBao (the Chinese eBay.) Unlike Paypal however, it requires ActiveX components or Firefox plugins to function. Getting this to work on Linux can be a pain if you don’t read Chinese. So here’s in English:
Download http://blog.alipay.com/wp-content/2008/10/aliedit.tar.gz
Extract it into /usr/lib/mozilla/plugins (as root) or into ~/.mozilla/plugins (if you care about the current user only.) Restart Firefox and things should work! (Select Tools, Add-ons, Plugins to verify that Aliedit has been installed.)
Plugins directory may vary on other distributions.