Skip to content

Instantly share code, notes, and snippets.

@prufrock
prufrock / ViewHelperSkeleton.php
Created April 7, 2011 02:46
A Skeleton of a Zend_View_Helper should be placed in application/views/helpers/ViewHelperSkeleton.php.
<?php
class Zend_View_Helper_ViewHelperSkeleton extends Zend_View_Helper_Abstract
{
public $view;
/**
* Allows the view to be passed into the helper for later use.
*/
public function setView(Zend_View_Interface $view)
{
@prufrock
prufrock / simpleform.js
Created August 14, 2011 02:40
JSON object of objects
var simpleForm = { "elements":
{ "verb" :
{ "label" : "verb",
"id" : "verb",
"type" : "text",
"size" : "50" ,
"element" : "input"
},
"url" :
{ "label" : "url",
@prufrock
prufrock / OpenTest.vim
Created September 1, 2011 05:02
A vim function that tries to guess where a PHP unit test is at.
function! OpenUnitTest()
let file = expand("%:p")
let words = split(getline(search('^class ')))
let words = split(words[1],"_")
let paths = matchlist(file, '\([A-Za-z0-9/].*\)/application')
let head = paths[1]
let path = "/tests"
let counter = 0
for word in words
if counter < 2
@prufrock
prufrock / appendWordToAnkiQuestion.pl
Created February 4, 2012 07:07
a quick script I threw together to append the word "perl" to my deck of anki cards
#!/usr/bin/perl
use DBI;
use Data::Dumper;
# Configuration Information
my $EOL = "\n";
my $dbFile = "perl.anki";
my $scriptStarting = "starting$EOL";
my $scriptComplete = "done$EOL";
my $sqlSelectAllCards = "SELECT * FROM cards";
@prufrock
prufrock / queuesNstuff.php
Created February 22, 2012 02:12
Use the AWS sdk for PHP to retreive a single record by ID or by scanning based the value of an attribute
<?php
require_once('aws-sdk-for-php/sdk.class.php');
$table_name = "queuesNStuff";
function outputArray($output)
{
print_r(nl2br(print_r($output->body->to_array(), TRUE)));
}
function outputJson($output)
{
@prufrock
prufrock / createProjectsDomain.php
Created March 3, 2012 22:53
create a simpleDB domain named projects
<?php
$sdb = new AmazonSDB("accessKey", "secretKey");
$sdb->setRegion(AmazonSDB::REGION_US_E1);
$response = $sdb->create_domain("projects");
print_r($response);
@prufrock
prufrock / betweenQuery.php
Created April 7, 2012 21:57
Performing a between query on an Amazon DynamoDB database.
<?php
//much of this borrowed from the amazon documentation
//http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/LowLevelPHPTableOperationsExample.html
require_once('include.php');
$response = $dynamoDB->query(array(
'TableName' => $properties["table"]["TableName"]
, 'HashKeyValue' => array(
$properties["table"]["KeySchema"]["HashKeyElement"]["AttributeType"]
=> $hashKey )
@prufrock
prufrock / installphpamqp.sh
Created May 5, 2012 00:24
install the php amqp install
cd /tmp/
hg clone http://hg.rabbitmq.com/rabbitmq-c/ rabbitmq-c
cd rabbitmq-c
hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen
autoreconf -i && ./configure && make && sudo make install
cd /tmp/
lynx http://pecl.php.net/package/amqp #Download latest
tar -xvf amqp-1.0.1.tgz
cd amqp-1.0.1
phpize && ./configure --with-amqp && make && sudo make install
@prufrock
prufrock / .htaccess
Created May 8, 2012 02:34
.htaccess file for cross-origin resource sharing
Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type"
Header set Access-Control-Allow-Methods "PUT, POST, GET, OPTIONS, DELETE"
@prufrock
prufrock / removeSingularKeys.php
Created May 22, 2012 21:46
Makes XML and JSON play nice when being rendered from the same associate array.
<?php
function removeSingularKeys($array, $parent="")
{
$result = array();
$result = $array;
foreach($array as $key => $value){
if(keyIsTheSingularFormOf($key, $parent)){
return $value;
}
if(is_array($value)){