Skip to content

Instantly share code, notes, and snippets.

@hintjens
hintjens / git bash prompt
Created March 11, 2011 16:24
git bash prompt, by Pieter Hintjens
export PROMPT_COMMAND=__git_prompt
__git_prompt ()
{
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
export PROMPT_COMMAND=__git_prompt
__git_prompt ()
{
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
@hintjens
hintjens / mdworker.c
Created March 3, 2011 21:12
Example of worker API usage
//
// Majordomo Protocol worker example
// Uses the mdwrk API to hide all MDP aspects
//
// Lets us 'build mdworker' and 'build all'
#include "mdwrkapi.c"
int main (void)
{
mdwrk_t *session = mdwrk_new ("tcp://localhost:5555", "echo", 1);
@hintjens
hintjens / hwserver.c
Created February 26, 2011 11:29
Tries to reconnect to server
//
// Hello World server
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
// Changes for 2.1:
// - added socket close before terminating
//
#include <zmq.h>
#include <stdio.h>
@hintjens
hintjens / piclient.c
Created February 26, 2011 11:06
Hangs on zmq_term even when socket is properly closed
//
// Client-side pirate
// Use zmq_poll to do a safe request-reply
// To run, start hwserver and then randomly kill/restart it
//
#include "zhelpers.h"
#define REQUEST_TIMEOUT 2500 // msecs
#define REQUEST_RETRIES 3 // Before we abandon
@hintjens
hintjens / sockleak.c
Created February 25, 2011 13:39
Runs out of file handles
//
// Socket leak test case
//
#include "zhelpers.h"
int main () {
void *context = zmq_init (1);
// Open socket, send message, close socket
@hintjens
hintjens / issue171.c
Created February 25, 2011 13:27
Simplified C version of issue171
//
// Leak example using PUB/SUB pattern
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each task has its own
// context and conceptually acts as a separate process.
#include "zhelpers.h"
#include "zmsg.c"
@hintjens
hintjens / pubbugz.c
Created February 24, 2011 16:37
Leaker does not leak
//
// Leak example using PUB/SUB pattern
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each task has its own
// context and conceptually acts as a separate process.
#include "zhelpers.h"
#include "zmsg.c"
@hintjens
hintjens / mtrelay.c
Created February 21, 2011 19:36
mtrelay.c for 0MQ/2.1
//
// Multithreaded relay
//
// Changes for 2.1:
// - added version assertion
// - pass context & thread to child threads
// - create socket pair for inproc communications
// - close sockets in each child thread
//
#include "zhelpers.h"
@hintjens
hintjens / syncpub.c
Created February 21, 2011 16:12
Comments on test case
//
// Synchronized publisher
//
// Changes for 2.1:
// - added version assertion
// - close syncservice socket in main thread
// - removed sleep(1) at end of main thread
//
#include "zhelpers.h"