Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
@bxt
bxt / RingBuffer.class.php
Created September 7, 2011 13:15
One-pointer Circular Buffer w/o overflow check and FIFO, using SplFixedArray
<?php
/**
* One-pointer Circular Buffer
*
* This comes without any overwrite
* checks or FIFO functionality.
* You'll need SPL.
*
* @author Bernhard Häussner
* @date 2011-09-07
@bxt
bxt / speedtest.out
Created September 3, 2011 12:25
Sed speed test -n option and printin vs negated adress vs quitting
02:16 bernhard@horst:~> time for i in {1..10000}; do sed -n -e '1p' edt.txt > /dev/null;done
real 1m23.424s
user 0m44.611s
sys 0m8.801s
02:18 bernhard@horst:~> time for i in {1..10000}; do sed -e '1!d' edt.txt > /dev/null;done
real 1m23.036s
user 0m45.827s
sys 0m10.609s
@bxt
bxt / README-PHP-Namespace-test-file.mkd
Created July 20, 2011 12:51
PHP Namespace test file

README for PHP Namespace test file

This is just a little script, which can tell you if your hoster/php verion supports namespaces. Upload to your htdocs/webroot and naviagte your browser to the page. It might tell you "Namespaces seem to work!" or something like "Parse error: syntax error, unexpected T_STRING in /var/www/httpdocs/nst.php on line 1"

@bxt
bxt / iceWMdual.mkd
Created July 18, 2011 17:15
IceWM Dual Screen expanding howto (very basic)

Step 1: Make sure xrandr works fine

Check your screen's names by typing:

xrandr -q

Step 2: Expand your screen

Then disable one of them: (notice VGA-1 is the name of the screen, will differ, e.g. HDMI-1 if the screen is connected via HDMI)

@bxt
bxt / array-pointr-arithmetic.cpp
Created May 27, 2011 11:50
Arrays access translates to pointer arithmetic in C/C++
int a[1];
a[0]=1;
if(0[a]==a[0]==1);
// a[b] == *(a+b) == *(b+a) == b[a]
@bxt
bxt / boolean2arithmetic.js
Created April 30, 2011 20:33
Boolean operators ! & | xor rewritten as arithmetic ones (+ * - on numeric input 0/1) in JS
/*
* Just for fun :) AND, OR and XOR with only "+ * - 2", plus "( ) 1" for NOT
*/
function not(a) {
return (a-1)*(a-1);
return a*(a-1)+(a+1)-2*a;
return (a-2)*a+1;
return and(a-1,a-1);
}
@bxt
bxt / sketch_apr15b.pde
Created April 15, 2011 13:50
Processing sketch (Java-like) to display and experiment with various gradient methods
int barWidth=50;
GradientI[] grads=new GradientI[4];
void setup() {
size(1600, 300);
colorMode(HSB, 360, 100, 1.0);
noStroke();
background(0);
grads[0]=new LiearGradient(); /* lin */
grads[1]=new LiearGradient(1.1); /* clip_a */
@bxt
bxt / sorting-jquery.js
Created April 11, 2011 23:04
Sorting HTML-Tables (or anything) using jQuery and Javascript's native Array.prototype.sort
var tableRows=$("tr").detach();
Array.prototype.sort.call(tableRows,function(a,b){
// Compare two table rows by the numeric value of their first <td>
return a.firstChild.firstChild.nodeValue*1 < b.firstChild.firstChild.nodeValue*1
});
$("table").append(tableRows);
// Tested in Firefox 4
@bxt
bxt / blender-render.sh
Created April 1, 2011 23:41
Blender from Command Line CLI sample call to render animation
for i in {1..61}; do echo rframe $i; time blender -b rotation1-mats.blend -f $i -o //rotation1_####.png -F PNG; done
# render frames 1 to 61, echo time for each frame and save them with specified filename
@bxt
bxt / ArrayObject.php
Created March 31, 2011 17:54
Access PHP-objects' getters and setter like an array
<?php
namespace bxt\Util;
class ArrayObject implements \ArrayAccess, \Iterator, \Countable {
private $object;
private $iterator=0;
private $offsetMethodMap=array();
private $offsetMethodMapSetters=array();
public function __construct($obj) {
$this->object=$obj;