Skip to content

Instantly share code, notes, and snippets.

# U Suck At Coding Exercise: Tree Comparison
# Feb 28 2012
# @loganlinn
class TreeNode
attr_accessor :value, :left, :right
def initialize v
@value = v
end
@loganlinn
loganlinn / bust.js
Created March 5, 2012 18:58
snippet embedded in twitter.com
function bust () {
document.write = "";
window.top.location = window.self.location;
setTimeout(function() {
document.body.innerHTML = '';
}, 0);
window.self.onload = function(evt) {
document.body.innerHTML = '';
};
}
@loganlinn
loganlinn / mytodos.sh
Created March 19, 2012 16:00
Finds todos that you have committed
# not finished
ack -i --flush --nocolor --nogroup '[^\w]?todo[^\w]' | awk -F\: '{print "-L " $2 "," $2 " -- " $1}' | xargs -L 1 git blame | grep -i `git config --get user.name`
@loganlinn
loganlinn / do.sh
Created March 22, 2012 23:00
PHP strcmp+strtolower VS strcasecmp Benchmark
for i in 50 100 250 500; do echo "String length: $i"; php strcmpbench.php $i; php strcasecmpbench.php $i; echo "\n"; done
# Example run:
#
# String length: 50
# ************************
# * strcomp + strtolower *
# ************************
# Time: 0.000082
# Memory: 1456
<?php
class Foo {
const NUM_FOOS = 42;
}
class Bar {
public $foo;
function __construct() {
@loganlinn
loganlinn / shortstat_today.sh
Created June 7, 2012 21:59
git shortstat for self in last 24 hours
git log --author=`git config user.name` --shortstat --since=yesterday | grep 'files changed' | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "", files, "files changed,", inserted, "insertions(+),", deleted, "deletions(-)"}'
@loganlinn
loganlinn / index.md
Created July 26, 2012 05:35
The Elements of Programming

The Elements of Programming

primitive expressions

which represent the simplest entities the language is concerned with,

means of combination

by which compound elements are built from simpler ones, and

@loganlinn
loganlinn / old_branches.sh
Created August 14, 2012 20:46
Git branch cleanup - older than 1 year, not matching 'release' or 'master'
git branch -r --merged master | sed 's/ *origin\///' | grep -v -E '(release|master$)' | xargs -I_ git log -1 --format='_ %ct' origin/_ | awk '{ if ($2 < '$(date -v-1y +%s)') print $1 }'
<?php
$a = array(
'foo' => 'asdf',
'bar' => 'fdsa',
'baz' => 'test'
);
end($a);
echo "Last key: " . key($a) . "\n";
@loganlinn
loganlinn / php_ternary_shorthand_magic_property_test.php
Created November 20, 2012 21:12
Testing PHP ternary shorthand & magic properties
<?php
class Test {
public $concrete = "concrete";
public function __get($prop) {
printf("%s(%s)\n", __FUNCTION__, $prop);
if ($prop == "magic") {
return $prop;
}