Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
@bxt
bxt / fix-typo-in-php-files.sh
Created February 26, 2011 15:44
Replaces all occurrences of Databese with Database in *.php files
perl -pi -w -e 's/Databese/Database/g;' *.php
@bxt
bxt / trashable-jQuery.js
Created February 26, 2011 15:45
jQuery to set href arrtibute of the 5th link to "#"
var _=["a","eq","href","attr","#",4];
$(_[0])[_[1]](_[5])[_[3]](_[2],_[_[5]]);
@bxt
bxt / public-dir.sh
Created February 26, 2011 15:47
Command to share a folder "/srv/share" with the group "sharer"
chgrp -R sharer /srv/share; find /srv/share/* -type d -exec chmod g+srw {} \;
@bxt
bxt / gist:845320
Created February 26, 2011 15:49
Get rid of PHP short tags with these regexp
replace "<\?=\$(.*)\?>" to "<?php echo \$\1; ?>"
and then "<\?(?!php)" to "<?php"
@bxt
bxt / fgrep.sh
Created February 26, 2011 15:51
look for "foo" through all non-binary files in pwd
fgrep -niIR "foo" .
@bxt
bxt / this-in-setTimeout-call.js
Created February 26, 2011 15:56
When using setTimeout inside Objects, making this availible in callback
setTimeout(function (obj){(function(){
/*here goes the callback code*/
}).apply(obj)},time,this);
@bxt
bxt / amp-converter.php
Created February 26, 2011 20:21
rexep to convert unpaired ampersands to &amp;
<?php $text=preg_replace ('/&(?!amp;|quot;|nbsp;|gt;|lt;|laquo;|raquo;|copy;|reg;|#[0-9]{1,5};|#x[0-9A-F]{1,4};)/','&amp;', $text);
@bxt
bxt / formatXml.php
Created February 27, 2011 12:25
PHP-Script to auto-format (valid) XML using PHP's DOM
#!/usr/bin/php5
<?php
if (!isset($argv)||$argc!=2||$argv[1]=='-h'||$argv[1]=='--help') {
echo <<<EOH
usage :
formatXMLNicely.php unformated.xml > formated.xml
EOH;
} else {
@bxt
bxt / gist:846141
Created February 27, 2011 12:27
PHP-Script to calculate various hash sums
#!/usr/bin/php
<?php
$silent=false;
if($argc>2&&$argv[2]=="-") {
$silent=true;
} else {
fputs(STDOUT,"Enter text:");
@bxt
bxt / kopeteHistXml2Html.php
Created February 27, 2011 12:29
Exporting Kopete chatlog history XML-files to HTML (CLI-Version)
#!/usr/bin/php
<?php
//echo "kopeteHistXml2Html.php - Exporting Kopete history xml-files to html (CLI-Version)";
$doc=simplexml_load_file($argv[1]);
//var_dump($doc);
$new_msgs=array();