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 / 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 / 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 / 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 / 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 / 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 / linkedin-api-invite
Created November 22, 2011 16:11
Simple example of using the LinkedIn JavaScript SDK to send an invite
<!DOCTYPE html>
<html>
<head>
<script>
function invite() {
var url = '/people/~/mailbox',
body = {
recipients: {
values: [{
person: {
@hjr3
hjr3 / package.sh
Created September 20, 2011 21:59
Javascript/CSS packaing script
#!/bin/bash
##
# Package multiple javascript/css files into a single file.
#
# This script will search a file for @PACKAGE-START and @PACKAGE-END annotations
# and merge all references files between those annotations into a single file.
# The first file in the list will be treated as the master file. References to
# the subsequent files will be removed.
@hjr3
hjr3 / gist:1201989
Created September 7, 2011 22:27
gearman-manager-callbacks
<?php
/**
* Manage responses from gearman workers and pass data along to the report
*/
class Status
{
protected $id;
protected $status;
@hjr3
hjr3 / gearman-worker-addTask.php
Created September 3, 2011 21:05
Gearman worker addTasks example
// macro.php
<?php
$gmw = new GearmanWorker();
$gmw->addServer();
$gmw->addFunction('macro', function(GearmanJob $job) {
$gmc = new GearmanClient;
@hjr3
hjr3 / gearman-complete
Created August 24, 2011 21:49
Complete Gearman example
<?php
// client
$gmc= new GearmanClient();
$gmc->addServer();
$gmc->setExceptionCallback(function(GearmanTask $task) {
$m = $task->data();
echo "Exception: {$m}\n";