This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-------------------------------------------------------------------------- | |
# | |
# 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |