Skip to content

Instantly share code, notes, and snippets.

@sbisbee
sbisbee / scrabble-ai.patch
Created June 3, 2009 22:26
A patch for the Debian scrabble package (v1.9) that has the computer play itself. Was refused by package maintainer for "usefulness" issues.
--- scrabble 2005-10-18 16:14:08.599699208 -0400
+++ scrabble-aipatch 2005-10-18 16:29:27.212048904 -0400
@@ -3,11 +3,15 @@
#
# Scrabble -- a crossword game
#
-# Version: 1.9
+# Version: 1.9 (AI patch)
#
# Written by Brian White <bcwhite@pobox.com>
@sbisbee
sbisbee / memory_show_usage.php
Created November 22, 2010 15:19
A useful function to show progressive memory diffs when benchmarking.
function memory_show_usage()
{
$base = null;
if(is_null($base))
{
$base = 1;
$base = memory_get_usage;
}
@sbisbee
sbisbee / couchdb-csrfTokens
Created February 8, 2011 23:04
Proposal on how to prevent CSRF attacks against CouchDB with tokens.
Proposal to Prevent CSRF Attacks on CouchDB with Tokens
=======================================================
This is a draft for commentary from the community.
Goals
-----
1. Establish a mechanism that would defeat CSRF attacks against CouchDB by
leveraging the standard provided by OWASP at
From d7b26202e965fec47cb42fdc5a6113820de2c47b Mon Sep 17 00:00:00 2001
From: Sam Bisbee <sam@sbisbee.com>
Date: Fri, 11 Feb 2011 13:47:05 -0500
Subject: [PATCH] Moving the config check to Sag's constructor, and updating tests.
---
src/Sag.php | 6 +++---
tests/SagConfigurationCheckTest.php | 18 +++++++++---------
2 files changed, 12 insertions(+), 12 deletions(-)
@sbisbee
sbisbee / php2json.php
Created February 23, 2011 19:53
A dirty piece of duct tape that converts a class into JSON.
#!/usr/bin/php
<?php
/*
* php2json
* by Sam Bisbee <sam@sbisbee.com>
* on 2011-02-23
*
* Takes in a class file, instantiates it, and then spits out its JSON.
*
* Example Usage: ./php2json.php UserVO.php
<?php
/*
* A real quick example to get and update a doc.
*/
require_once('./src/Sag.php');
$sag = new Sag('127.0.0.1', '5984');
// Select the database that holds our blog's data.
$sag->setDatabase('blog');
@sbisbee
sbisbee / ValueObject.php
Created March 19, 2011 22:18
The boiler plate Value Object that I've been using on projects for a few years now.
<?php
abstract class ValueObject
{
public function __construct($src = null)
{
if($src)
self::populate($src);
}
/**
@sbisbee
sbisbee / SuperCouchSessionStore.php
Created April 6, 2011 20:51
An example for a blog article.
<?php
require_once 'CouchSessionStore.php';
class SuperCouchSessionStore extends CouchSessionStore
{
public static function setSag($sag)
{
//use CouchSessionStore to set everything up, so our $this->sag == $sag
parent::setSag($sag);
@sbisbee
sbisbee / bwah.php
Created August 11, 2011 17:45
For Sag debugging purposes.
#!/usr/bin/php
<?php
require('Sag.php');
$sag = new Sag();
$sag->setDatabase('bwah');
for($i = 0; $i < 1000; $i++) {
echo "$i\n";
if(!$sag->post(array('hi' => 'there'))->body->ok) {
echo "\t!!!!!!FAIL!!!!!!\n";
@sbisbee
sbisbee / gist:1174685
Created August 26, 2011 23:27
Another script for Sag v0.5.1 connection pooling debugging purposes.
#!/usr/bin/php
<?php
require('Sag.php');
$sag = new Sag();
$sag->setDatabase('bwah', true);
// Send a temp view
var_dump($sag->post(array( 'map' => 'function(doc) { emit(null, null); }'), '/_temp_view'));
// Send a doc