Skip to content

Instantly share code, notes, and snippets.

View mengzhuo's full-sized avatar

Meng Zhuo mengzhuo

View GitHub Profile
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
#!/usr/bin/env python
# encoding: utf-8
"""
Base57 Module For Encode and Decode
{A..Z} {a..z} {1..9} without
'O o 0 1 l I'which chars easily mistype
"""
# WARNING DON'T CHANGE the BASE
@mengzhuo
mengzhuo / fib.py
Created May 23, 2014 02:30
Fib generator
def fib():
x, y = 0,1
while True:
yield x
x, y = y,x+y
fibgen=fib()
print [fibgen.next() for x in xrange(40)]
@mengzhuo
mengzhuo / .zshrc
Created April 15, 2014 02:24
My ZSH settings
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="agnoster"
# Example aliases
@mengzhuo
mengzhuo / .tmux.conf
Last active May 12, 2019 13:16
My tmux configure with Vi mode and color-settings
# vi:syntax=conf
set-window-option -g mode-keys vi
set -g history-limit 10000
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
set-option -g default-shell /bin/zsh
import zmq
def main():
try:
context = zmq.Context(1)
# Socket facing clients
frontend = context.socket(zmq.PULL)
frontend.bind("tcp://*:5559")
@mengzhuo
mengzhuo / forwarder_device.py
Created April 10, 2014 10:07
forwarder_device.py
import zmq
def main():
try:
context = zmq.Context(1)
# Socket facing clients
frontend = context.socket(zmq.SUB)
frontend.bind("tcp://*:5559")
@mengzhuo
mengzhuo / queue_client.py
Created April 10, 2014 10:04
ZeroMQ Queue Devices Tutorial
import zmq
import sys
import random
port = "5559"
context = zmq.Context()
print "Connecting to server..."
socket = context.socket(zmq.REQ)
socket.connect ("tcp://localhost:%s" % port)
client_id = random.randrange(1,10005)
import asyncore
import socket
class EchoHandler(asyncore.dispatcher_with_send):
def handle_read(self):
data = self.recv(8192)
if data:
self.send(data)
import socket,asyncore
class forwarder(asyncore.dispatcher):
def __init__(self, ip, port, remoteip,remoteport,backlog=5):
asyncore.dispatcher.__init__(self)
self.remoteip=remoteip
self.remoteport=remoteport
self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind((ip,port))