A while ago i started with BTMetafile as a php class that can create BitTorrent metafiles. As of now, it can generate the metafile structure and bencodes single files or directories properly (bencoding is done through a separate BTBencode class). Yet it lacks a class for decoding.
Class BTMetafile can be obtained from http://svn.var.cc/svn/phpbtmc/btmetafile.php (user anonymous, no password)
Usage:
$encoder = new BTBencode();
$opts = array('encoder' => $encoder,
'announceurl' => 'http://var.cc:6969/announce');
$m = new BTMetafile($opts);
$m->makeMetafile('/tmp/test.mp3');
$m->saveMetafile('/tmp/test.mp3.torrent');
I recently found this Article [1] about gz-compressing CSS files before sending them to the browser. Apart from the controversies whether it makes sense to compress CSS for the output at all, and why not use apache's mod_gzip etc., if found the idea quite interesting. To only invoke
ob_start('ob_gzhandler') as mentioned in the article wasn't enough (for what reason ever). The following was working to gz-compress the CSS output of this very blog.
include a phpfile instead of the css
@import url(mycss.php);
//or
<link rel="stylesheet" type="text/css" media="screen" href="mycss.php" />
mycss.php contains the methods nescessary
<?php
// This is the file containing the css definitions
$myrealcss="path/to/mycss.css";
// callback method for ob handler
function mygzhandler($buffer) {
return gzencode($buffer, 9);
}
// init ob handler
ob_start("mygzhandler");
// headers
header("Content-Type: text/css");
header("Content-Encoding: gzip");
@readfile($myrealcss);
// flush output buffer
ob_end_flush();
?>
There's also a class for gzip encoding by Leknor[2] if
gzencode() is inconvenient
[1]
http://www.fiftyfoureleven.com/sandbox/2004/feb/gzipping-your-css-with-php/
[2]
http://leknor.com/code/php/view/class.gzip_encode.php.txtSome settings which help writing
pear coding standards compliant
PHP code with
VIM
Put the following into ~/.vimrc :
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
This basically causes VIM to do 4 space indents with no tabs