Skip to content

Instantly share code, notes, and snippets.

View minrk's full-sized avatar

Min RK minrk

View GitHub Profile
from IPython.core.display import display
class YouTubeVideo(object):
"""Class for embedding a YouTube Video in an IPython session, based on its video id.
e.g. to embed the video on this page:
http://www.youtube.com/watch?v=foo
you would do:
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main (void)
{
int rc;
void *context = zmq_init(1);
zmq_msg_t msg;
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main (void)
{
int rc;
char data[5] = "hello";
zmq_msg_t msg;
#--------------------------------------------------------------------------
#
# Copyright (C) 2007-2008 by Arlindo da Silva <dasilva@opengrads.org>
# All Rights Reserved.
#
# This program is free software# you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation# using version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
#include <stdio.h>
#include <stdarg.h>
#include "zmq.h"
#include <assert.h>
int serve ()
{
// The server simply prints received multipart messages, one message to a line
// it should only print one line per client send, but this is not what happens
// instead, the IDENT prefix is received as its own message, and printed separately.
@minrk
minrk / mux.py
Created September 16, 2011 19:26
import zmq
ctx = zmq.Context.instance()
mux_input = 'tcp://127.0.0.1:5555'
mux_output = 'tcp://127.0.0.1:6666'
ins = ctx.socket(zmq.ROUTER)
outs = ctx.socket(zmq.ROUTER)
ins.bind(mux_input)
outs.bind(mux_output)
@minrk
minrk / ipdev.sh
Created September 21, 2011 03:34
Script for user-only installs of Cython, PyZMQ, IPython, and tornado from git
#!/bin/bash
prefix="$HOME/.local"
# This script will install everything you need to use current git versions of Cython, PyZMQ, and IPython
# for this user.
# We assume you have things set up for a typical python `--user` environment
# which installs user-only things in ~/.local. e.g. adding the following lines
# to your bashrc or profile:
@minrk
minrk / client.py
Created September 28, 2011 21:35
pyzmq Multiplexer with libzmq-4.0 ROUTER
"""connect a couple of clients to the MUX, and issue various requests."""
import sys
import string
import zmq
def print_reply(s):
prefix, msg = s.recv_multipart()
worker = prefix[0]
stdout,stderr = msg
@minrk
minrk / ident.py
Created September 28, 2011 23:11
import time
import zmq
ctx = zmq.Context()
router = ctx.socket(zmq.ROUTER)
router.bind('tcp://127.0.0.1:5555')
a = ctx.socket(zmq.REP)
# you must set ident before connecting:
a.setsockopt(zmq.IDENTITY, 'a')
a.connect('tcp://127.0.0.1:5555')
ip = get_ipython()
fmt = ip.display_formatter.formatters['text/plain']
# show currently registered type printers:
fmt.type_printers
# register a new formatter for `type` objects, that is just the repr
fmt.for_type(type, lambda obj,p,cycle: p.text(repr(obj)))
# or just unregister the printer for type, which results in repr as the default:
fmt.type_printers.pop(type)
# register a custom printer for your own objects: