Skip to content

Instantly share code, notes, and snippets.

View ruedesign's full-sized avatar

Toru Otaki ruedesign

View GitHub Profile
@ruedesign
ruedesign / JsonBuilder.groovy
Created June 26, 2013 02:36
Build JSON in Grails using groovy.json.JsonBuilder(Groovy API)
def code = null
def message = "error message"
def builder = new JsonBuilder()
def root = builder {
error(
code: code ?: "",
message: message ?: ""
)
@ruedesign
ruedesign / pub-sub_cli.py
Created March 22, 2013 06:49
ZeroMQ Subscriber sample (Publish-Subscribe Model)
import zmq
context = zmq.Context()
sub = context.socket(zmq.SUB)
sub.setsockopt(zmq.SUBSCRIBE, "")
sub.connect("tcp://127.0.0.1:5555")
while True:
print "recv:", sub.recv()
@ruedesign
ruedesign / pub-sub_srv.py
Created March 22, 2013 06:49
ZeroMQ Publisher sample (Publish-Subscribe Model)
import zmq
import time
context = zmq.Context()
pub = context.socket(zmq.PUB)
pub.bind("tcp://127.0.0.1:5555")
c = 0
while True:
msg = "[" + str(c) + "]"
@ruedesign
ruedesign / req-res_cli.py
Created March 22, 2013 06:44
ZeroMQ Request sample (Request-Reply Model)
import zmq
context = zmq.Context()
req = context.socket(zmq.REQ)
req.connect("tcp://127.0.0.1:5555")
while True:
c += 1
msg = "%s" % c
@ruedesign
ruedesign / req-rep_srv.py
Created March 22, 2013 06:43
ZeroMQ Reply sample (Request-Reply Model)
import zmq
import time
context = zmq.Context()
rep = context.socket(zmq.REP)
rep.bind("tcp://127.0.0.1:5555")
while True:
request = rep.recv()
print "recieved request: [%s]" % request
@ruedesign
ruedesign / s2c.rb
Created March 22, 2013 01:19
Space to comma
line = ""
f1 = open(ARGV[0])
f2 = open(ARGV[0] + ".csv", "w")
f1.gets
f1.gets
while l = f1.gets
if l != ""
l.gsub!(/\s+/, ",")
@ruedesign
ruedesign / thread.py
Last active July 29, 2023 22:12
Python thread sample with handling Ctrl-C
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, time, threading, abc
from optparse import OptionParser
def parse_options():
parser = OptionParser()
parser.add_option("-t", action="store", type="int", dest="threadNum", default=1,
help="thread count [1]")