Skip to content

Instantly share code, notes, and snippets.

<?
include("toro.php");
// Domain object, not included, just for following along
include("domain/user.php");
class V1UserCreateHandler extends ToroHandler {
private function fail($error_type="") {
echo json_encode(array("success" => false, "error_type" => $error_type));
exit;
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
// Invert the color spectrum
Surface::Iter iter(newSurface.getIter());
while(iter.line()) {
while(iter.pixel()) {
iter.r() = 255 - iter.r();
iter.g() = 255 - iter.g();
iter.b() = 255 - iter.b();
}
}
@anandkunal
anandkunal / gist:963138
Created May 9, 2011 18:59
OBL Spam Letter
Just got the following spam message. Pretty entertaining.
-----
My name is Captain Matthew Stamford of the US Marine corps (special) stationed in Pakistan,
I found some money ($2,000,000.00) after the death of Osama Bin Laden. I need someone to help me move it to a safer place,
please have it in mind that there is no danger involved. You may contact me on matt.stam57@yahoo.com.hk so that I can provide you with details
@anandkunal
anandkunal / gist:946649
Created April 28, 2011 16:04
Some random routing idea...
<?
class ToroRoute {
function __construct($route, $patterns) {
}
public function matches_url($url) {
}
@anandkunal
anandkunal / gist:946646
Created April 28, 2011 16:03
seppuku.php
<?
function seppuku() {
header("HTTP/1.1 500 Internal Server Error");
ob_clean();
}
register_shutdown_function("seppuku");
@anandkunal
anandkunal / patterned_route_sketch.php
Created February 5, 2011 15:29
Scratching a route idea in PHP
<?
function prepare_named_routes($matches) {
return "([a-zA-Z0-9-_]+)";
}
// Have a URL
$url = "/user/dude/rug";
// Prepare the route
$route = "user/:username/:action";
<?php
ToroHook::add('before_request', function() { echo 'Before Request'; });
ToroHook::add('after_request', function() { echo 'After Request'; });
class SomeHandler extends ToroHandler {
public function __construct() {
ToroHook::add('before_handler', function() { echo 'Before Handler'; });
ToroHook::add('after_handler', function() { echo 'After Handler'; });
}
<?php
require_once 'toro.php';
$blog_posts = array(
array('title' => 'Evening Plans', 'body' => "I'm staying in to work on my law blog."),
array('title' => "You don't need double talk; you need Bob Loblaw", 'body' => 'True.'),
array('title' => "Why should you go to jail for a crime someone else noticed?", 'body' => "You shouldn't."),
);
function display_snippet($pos) {
<?php
class MainHandler {
function get() {
echo "Hello, world";
}
}
Toro::serve(array(
"/" => "MainHandler",