Skip to content

Instantly share code, notes, and snippets.

View hjr3's full-sized avatar

Herman J. Radtke III hjr3

View GitHub Profile
@hjr3
hjr3 / data.php
Created December 15, 2011 21:59
SPL FilterIterator example
$items = array(
array(
'name' => 'Pants',
'available' => 1,
'sold' => 1,
),
array(
'name' => 'Shoes',
'available' => 1,
'sold' => 0,
@hjr3
hjr3 / worker.php
Created January 24, 2012 23:38
Simple Gearman worker example using anonymous functions
<?php
$gmw = new GearmanWorker();
$gmw->addServer();
$processor = new Processor;
$gmw->addFunction("process", function(GearmanJob $job) {
$data = json_decode($job->workload());
$processor->process($data);
});
@hjr3
hjr3 / client.sh
Created January 25, 2012 18:09
Examples of using the gearman tool to create boilerplate clients and workers
# gearman client that sends no data to the "ping" function
gearman -f ping -s
# gearman client that sends the string "pong" to the "ping" function
echo "pong" | gearman -f ping
# gearman client that sends a json string to the "process" function
echo '{"order":4985343}' | gearman -f process
# gearman client that reads data from a order.json file
@hjr3
hjr3 / PushMessage.php
Created January 30, 2012 21:32
A simple irc async push message script for Phergie IRC Bot
<?php
class Phergie_Plugin_PushMessage extends Phergie_Plugin_Cron
{
public function onLoad()
{
$settings = $this->config['push_message.listen'];
foreach ($settings as $listen) {
$host = $listen['host'];
@hjr3
hjr3 / whiskey-milita.sh
Created January 30, 2012 23:30
Because cleansnipe.com has nothing on me...
#!/bin/bash
LOCK=/home/user/wm.lock
if [ -f $LOCK ]; then
exit 0
fi
PAGE=$(curl -s http://www.whiskeymilitia.com/)
FOUND=0
@hjr3
hjr3 / decode.c
Created March 3, 2012 08:52
TopCoder.com SRM Problem 300
// gcc -g -Wall -Werror -o decode decode.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
const int RESULT_LEN = 2;
/**
* Transforms a string of numerics in an array of ints.
@hjr3
hjr3 / debugger.py
Created March 8, 2012 06:28
XML response output from DBGP for PHP arrays
def xml_on_element(self, node):
if node.nodeName == 'property':
self.type = node.getAttribute('type')
name = node.getAttribute('name')
fullname = node.getAttribute('fullname')
if name == '':
name = 'EVAL_RESULT'
if fullname == '':
fullname = 'EVAL_RESULT'
@hjr3
hjr3 / primes.c
Created March 12, 2012 06:26
Find all prime numbers in a given range using Sieve of Eratosthenes
// gcc -std=c99 -Wall -Werror -g -o primes primes.c -lm
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
void primes(int length)
{
unsigned int bits_per_int = (sizeof(unsigned int) * CHAR_BIT);
unsigned int mask_size = 0;
@hjr3
hjr3 / e-commerce.md
Created April 3, 2012 05:35
Examples of RESTful API calls for E-commerce platforms

Examples of RESTful API calls for E-commerce platforms

These examples are type 3 RESTful API requests and responses. The JSON-HAL specification is used to implement HATEOAS.

Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

Relevant links

@hjr3
hjr3 / Vagrantfile
Created August 24, 2012 23:40
Standard PHP vagrant setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "centos64-min"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://dl.dropbox.com/u/9227672/CentOS-6.0-x86_64-netboot-4.1.6.box"