Skip to content

Instantly share code, notes, and snippets.

View tobsn's full-sized avatar

Tobsn tobsn

  • US/EU/SEA
View GitHub Profile
@tobsn
tobsn / oneLineReddit.php
Created February 5, 2010 00:49
reddit clone in one line
<?/*shell: touch s;chmod 777 s;*/$w=array('type','text','value','name','input');function c($x,$v,$s=''){return $x->createElement($v,$s);}function a($x,$v){return $x->appendChild($v);}function s($x,$v,$s=''){return $x->setAttribute($v,$s);}$g=$_GET;$p=$_POST;if($p['l']&&$p['t']){file_put_contents('s',implode('§§',array(0,time(),strip_tags($p['l']),strip_tags($p['t'])))."\n",FILE_APPEND);}$d=new DOMDocument();$h=c($d,'head');a($h,c($d,'title','r'));$m=c($d,'html');a($m,$h);$b=c($d,'body');$f=c($d,'form');s($f,'method','post');$i=c($d,$w[4]);s($i,$w[0],$w[1]);s($i,$w[3],'t');s($i,$w[2],'title');a($f,$i);$i=c($d,$w[4]);s($i,$w[0],$w[1]);s($i,$w[3],'l');s($i,$w[2],'link');a($f,$i);$i=c($d,$w[4]);s($i,$w[0],'submit');a($f,$i);a($b,$f);$z=file_get_contents('s');if($z){$u=c($d,'ul');$z=explode("\n",$z);$z=array_reverse($z,true);foreach($z as $i => $y){if(!$y){continue;}$y=explode('§§',$y);$l=c($d,'li');$a=c($d,'a','^');s($a,'href','?u='.$i);a($l,$a);a($l,$d->createTextNode(' '.$y[0].' '));$a=c($d,'a','v');s($a,'href'
@tobsn
tobsn / BlitzView.php
Created December 16, 2010 01:58
blitz template engine view class for slim framework
<?php
// extended blitz class for better block handling (load assoc arrays correctly, one level)
class xBlitz extends Blitz{function xblock($k,$a){foreach($a as $v){$this->block('/'.$k,$v,true);}}}
class BlitzView extends View {
private $blitzEnvironment = null;
public function render( $template ) {
$env = $this->getEnvironment( $template );
@tobsn
tobsn / loader.plugin.php
Created December 17, 2010 01:25
controller loader for slim framework
<?php
Slim::hook('slim.before.dispatch', function () {
list( $type, $controller_name, $controller_action ) = array_merge( explode( '.', Slim::router()->current()->getName() ), array( null,null,null ) );
if( $type == 'controller' ) {
$file = './controllers/'.$controller_name.'.controller.class.php';
if( !is_readable( $file ) ) { return false; }
require_once( './controllers/base.controller.class.php' );
require_once( $file );
$class = $controller_name.'Controller';
db.coll.group({
key:{domain:true},
reduce:function(obj,prev){
prev.items.push(obj);
},
initial:{items:[]}
});
$list_pattern = 'SELECT
%5$s AS zip,
%6$s AS name,
SQRT( (
( %2$d - %8$s ) *
( %2$d - %8$s )
) + (
( %1$d - %7$s ) *
( %1$d - %7$s )
) ) AS distance
@tobsn
tobsn / gist:910241
Created April 8, 2011 16:42
Sizzle Closure Compiled - Sizzle() becomes A()
var l=null;
(function(){function z(a,b){for(var c,d=[],f="",e=b.nodeType?[b]:b;c=j.match.c.exec(a);)f+=c[0],a=a.replace(j.match.c,"");a=j.b[a]?a+"*":a;c=0;for(var h=e.length;c<h;c++)i(a,e[c],d);return i.filter(f,d)}function n(a,b){a=Array.prototype.slice.call(a,0);if(b)return b.push.apply(b,a),b;return a}function F(a,b){return"\\"+(b-0+1)}function i(a,b,c,d){var c=c||[],f=b=b||document;if(b.nodeType!==1&&b.nodeType!==9)return[];if(!a||typeof a!=="string")return c;var e,h,g,m,t,o=!0,p=i.i(b),k=[],q=a;do if(x.exec(""),
e=x.exec(q))if(q=e[3],k.push(e[1]),e[2]){m=e[3];break}while(e);if(k.length>1&&G.exec(a))if(k.length===2&&j.b[k[0]])h=z(k[0]+k[1],b);else for(h=j.b[k[0]]?[b]:i(k.shift(),b);k.length;)a=k.shift(),j.b[a]&&(a+=k.shift()),h=z(a,h);else if(!d&&k.length>1&&b.nodeType===9&&!p&&j.match.a.test(k[0])&&!j.match.a.test(k[k.length-1])&&(e=i.find(k.shift(),b,p),b=e.d?i.filter(e.d,e.set)[0]:e.set[0]),b){e=d?{d:k.pop(),set:n(d)}:i.find(k.pop(),k.length===1&&(k[0]==="~"||k[0]==="+")&&b.parentNode?b.parentNode:b,p)
@tobsn
tobsn / log.js
Created May 3, 2011 12:09
node.js pipe for lighttpd logs to mongodb
#!/usr/local/bin/node
var fs = require('fs'),
useragent = require('/www/utils/node_modules/useragent'),
zoneinfo = require('/www/utils/node_modules/zoneinfo'),
TZDate = zoneinfo.TZDate,
countrycodes = require('/www/utils/node_modules/zoneinfo/lib/countrycodes');
mongo = require('/www/utils/node_modules/mongoq'),
db = mongo('mongodb:\/\/localhost/logs'),
access = db.collection( 'access' );
@tobsn
tobsn / pixel.php
Created May 6, 2011 01:25
one transparent or colored gif pixel
<?php
header( 'Content-type: image/gif' );
header( 'Expires: Wed, 11 Nov 1998 11:11:11 GMT' );
header( 'Cache-Control: no-cache' );
header( 'Cache-Control: must-revalidate' );
if( !empty( $_GET['c'] ) ) {
$rgb = preg_replace( '/[^0-9a-z]/i', '', $_GET['c'] );
die( sprintf(
@tobsn
tobsn / gist:963466
Created May 9, 2011 21:34
setting up a db template on rackspace cloud debian
1. system upgrade (lenny to squeeze)
================
apt-get update
apt-get upgrade
// keep old configs - hit [enter]
nano /etc/apt/source.list
// replace lenny with squeeze
apt-get update
apt-get upgrade
// keep old - keep hitting [enter]
@tobsn
tobsn / simple_request.js
Created May 20, 2011 01:10 — forked from chjj/simple_request.js
simple request
var parse = require('url').parse,
http = require('http'),
StringDecoder = require('string_decoder').StringDecoder;
var request = function(url, body, func) {
if (typeof url !== 'object') {
url = parse(url);
}
if (!func) {