Skip to content

Instantly share code, notes, and snippets.

@ianbarber
ianbarber / multiprocess.php
Created December 5, 2010 12:59
Distribute work across subprocesses using 0MQ
<?php
$num_workers = 5;
$pid = 1;
for($i = 0; $i < $num_workers; $i++) {
$pid = pcntl_fork();
if($pid == 0) {
break;
}
}
@ianbarber
ianbarber / gist:805688
Created February 1, 2011 10:41
pubsub identity bug
<?php
$context = new ZMQContext();
$pub = $context->getSocket(ZMQ::SOCKET_PUB);
$pub->bind('tcp://*:5566');
$sub = makesock($context);
$sub2 = makesock($context);
$pub->send(rand(0,10));
function makesock($context) {
@ianbarber
ianbarber / gist:805701
Created February 1, 2011 10:53
Dual Identity Assert
#include <zmq.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
@ianbarber
ianbarber / gist:816533
Created February 8, 2011 14:51
EPGM SUB
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
int main () {
void *context = zmq_init (1);
printf("Creating Sockets \n");
int64_t rate = 1000;
@ianbarber
ianbarber / xapianmlt.php
Created April 19, 2011 21:09
Xapian More Like This
<?php
$posting = $database->postlist_begin( $search_id );
$enquire = new XapianEnquire( $database );
$rset = new XapianRset();
$rset->add_document( $posting->get_docid() );
$eset = $enquire->get_eset(20, $rset);
$i = $eset->begin();
$terms = array();
@ianbarber
ianbarber / gist:2370348
Created April 12, 2012 19:28
Binary tree validator thingy
(defn is-valid?
[node left-val right-val]
(if (= node nil)
true
(if
(and
(> (:key node) left-val)
(<= (:key node) right-val)
(is-valid? (:left node) left-val (:key node))
(is-valid? (:right node) (:key node) right-val)
static NSString * const kClientId = @"123456789.apps.googleusercontent.com";
+ (NSString *) clientId
{
return kClientId;
}
#import "AppDelegate.h"
@implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *clientId = [AppDelegate clientId];
share = [[GooglePlusShare alloc] initWithClientID:clientId];
}
- (IBAction) didPressShare: (id)sender {
[[[[share shareDialog]
setURLToShare:[NSURL URLWithString:@"http://www.riskcompletefailure.com"]]
setPrefillText:@"This is the blog which I am reading!"] open];
}
- (void)finishedSharing:(BOOL)shared {
NSString *text = shared ? @"Shared!" : @"Cancelled!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result"
message:text
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}