Skip to content

Instantly share code, notes, and snippets.

@jdp
jdp / twitter.php
Created April 2, 2009 08:27
Minimalist Twitter library, inspired by tcdents's
<?php
/*
* twitter.min.php
* Copyright (c) 2009 Justin Poliey <jdp34@njit.edu>
* Licensed under the MIT License
*
* This piece of software was inspired by Travis Dent's php-twitter
* http://github.com/tcdent/php-twitter
*
* Using this is insanely simple. You just need to map methods just
@jdp
jdp / crabbot.py
Created May 9, 2009 08:11
Crab Battle IRC trading card game
from bot import TCGBot
from tcg import Player, Card
import sets
import sys, random, copy, sqlite3, irclib
db = None
def dispatch(irc, nick, address, cmd):
sql = db.cursor()
@jdp
jdp / yui-reset.css
Created May 19, 2009 00:06
YUI's reset, just so I know where it is
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
}
table {
border-collapse:collapse;
border-spacing:0;
}
fieldset,img {
border:0;
@jdp
jdp / example.php
Created May 19, 2009 08:26
Glue API implementation
<?php
// require glue lib
require 'glue.php';
// create a glue object, and look up the neverending story in json format
// $glue->$method->$chain maps to api calls, like method/chain
// you can use any value, but glue will throw errors
$glue = new Glue('username', 'password');
$response = $glue->object->get(array(
'objectId' => 'http://en.wikipedia.org/wiki/The_Neverending_Story',
@jdp
jdp / gist:122882
Created June 3, 2009 08:33
Redisent benchmark
<?php
/*
* TYPICAL RESULT
* Redisent completed in 1.507806 seconds
* Redis completed in 1.575556 seconds
*/
error_reporting('E_ALL | ~E_NOTICE');
require 'redis.php';
@jdp
jdp / gist:123249
Created June 3, 2009 21:02
Attempt at consistent hashing
<?php
function next_highest($needle, $haystack) {
foreach ($haystack as $id => $handful) {
if ($needle < $handful) {
return $haystack[($id == 0) ? count($haystack)-1 : $id-1];
}
}
return $haystack[0];
}
<?php
if ($session->check('Message.auth')) {
$session->flash('auth');
}
echo $form->create('User', array('action'=>'login'));
echo $form->input('email');
echo $form->input('password');
echo $form->end('Login');
?>
@jdp
jdp / .bashrc
Created July 9, 2009 04:22 — forked from defunkt/.bashrc
Tweet function for fish shell
# $ tweet Hi mom!
#
# Put this in ~/.bashrc or wherever.
# If it doesn't work, make sure your ~/.netrc is right
#
# (Thanks to @anildigital and @grundprinzip for curl-fu)
function tweet {
curl -n -d status="$*" https://twitter.com/statuses/update.xml --insecure &> /dev/null
echo "tweet'd"
@jdp
jdp / magneton.php
Created July 9, 2009 11:38
Magneton, the superdense PHP framework
<?php $u=$_GET['u'];$l=$u();extract($l);include("view/{$u}.php");
<?php
require 'tessera.php';
class BasicApp extends Tessera {
function index() {
echo "Deep down, deep down, dadi dadu dadu dadi dada";
}
}
$basic = new BasicApp(array(