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 / google-reader-subscriptions.php
Created August 5, 2011 15:31
List subscriptions from Google Reader API
<?php
$email = 'example@gmail.com';
$password = 'secret';
$url = "https://www.google.com/accounts/ClientLogin?service=reader&Email={$email}&Passwd={$password}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
@hjr3
hjr3 / gearmand-exception
Created August 20, 2011 09:36
gearmand exception handling
INFO [ main ] Accepted connection from 127.0.0.1:38684
INFO [ 2 ] Received CON wakeup event
DEBUG [ 2 ] Received OPTION_REQ 127.0.0.1:525643377 -> libgearman-server/thread.c:294
DEBUG [ proc ] 'exceptions' -> libgearman-server/server.c:360
DEBUG [ 2 ] Received RUN wakeup event -> libgearman-server/gearmand_thread.cc:409
DEBUG [ 2 ] Sent OPTION_RES to 127.0.0.1:525643377 -> libgearman-server/thread.c:339
DEBUG [ 2 ] Received CAN_DO 127.0.0.1:525643377 -> libgearman-server/thread.c:294
DEBUG [ 2 ] Received GEARMAN_COMMAND_GRAB_JOB_ALL 127.0.0.1:525643377 -> libgearman-server/thread.c:294
DEBUG [ proc ] Jobs available 0 -> libgearman-server/job.c:462
DEBUG [ 2 ] Received RUN wakeup event -> libgearman-server/gearmand_thread.cc:409
@hjr3
hjr3 / gearman-client-exception-callback.php
Created August 20, 2011 21:35
pecl/gearman client exception callback example
<?php
$gmc= new GearmanClient();
$gmc->addServer();
$gmc->setExceptionCallback(function(GearmanTask $task) {
$m = $task->data();
echo "Exception: {$m}\n";
@hjr3
hjr3 / gearman-worker-exception.php
Created August 20, 2011 21:38
pecl/gearman worker exception
<?php
$gmw = new GearmanWorker();
$gmw->addServer();
$gmw->addFunction('test', function(GearmanJob $job) {
throw new Exception('Boom');
});
while(1) $gmw->work();
@hjr3
hjr3 / gearman-client-batch-example.php
Created August 20, 2011 22:27
Gearman client batch job example
<?php
$complete = 0;
$fail = 0;
$gmc = new GearmanClient;
$gmc->addServer();
$gmc->setCompleteCallback(function() use (&$complete) {
$complete++;
@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";
@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 / 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 / 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 / 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: {