Skip to content

Instantly share code, notes, and snippets.

@abhinavsingh
abhinavsingh / worker.log
Created February 10, 2019 18:26
ConnectionRefusedError during proxy.py Worker process setup
Process Worker-2:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "./proxy.py", line 738, in run
operation, payload = self.client_queue.get(True, 1)
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/queues.py", line 113, in get
return _ForkingPickler.loads(res)
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/reduction.py", line 242, in _rebuild_socket
fd = df.detach()
@abhinavsingh
abhinavsingh / friends.c
Last active September 9, 2015 07:56
What's the real order? Order in which friend threads were spawned or the ticket id that they came back with?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static int ticketid = 0;
pthread_mutex_t lock;
// buyticket function remote dial a central store to obtain ticket id
void * buyticket() {
int *id = (int *)malloc(sizeof(int));
@abhinavsingh
abhinavsingh / for_range.h
Created May 12, 2015 08:15
Python style range function in C as macro
#include <setjmp.h>
void generator();
jmp_buf buf;
#define YIELD(i) longjmp(buf, i)
#define FOR_RANGE(v,n) { \
int v=0; \
while(v!=n) { \
@abhinavsingh
abhinavsingh / gist:ea78b466969a2c896ef9
Created August 3, 2014 06:00
golang v1.3 panic runtime park signal loop on darwin/amd64 mac osx
panic: Show me the stacks
goroutine 16 [running]:
runtime.panic(0x29fb00, 0xc208001f10)
/Users/abhinavsingh/Dev/go/src/pkg/runtime/panic.c:279 +0xf5
main.main()
/Users/abhinavsingh/Dev/....:31 +0x280
goroutine 19 [finalizer wait]:
runtime.park(0x14840, 0x3f0da0, 0x3ef8a9)
@abhinavsingh
abhinavsingh / forwarder.py
Created August 29, 2013 13:29
Tornado websockets and ZMQ pubsub
import zmq
def main():
try:
context = zmq.Context(1)
frontend = context.socket(zmq.SUB)
frontend.bind('tcp://*:5559')
frontend.setsockopt(zmq.SUBSCRIBE, '')
@abhinavsingh
abhinavsingh / run_tests.py
Created July 15, 2013 16:39
Run test suite prepared using various test files
# -*- coding: utf-8 -*-
"""
run_tests
~~~~~~~~~
Run test suite prepared using various test files
"""
import os
import glob
import unittest
@abhinavsingh
abhinavsingh / gist:3708233
Created September 12, 2012 17:10
JAXLXml chaining api methods example
$ ./jaxlctl shell
jaxl 1> $xml_obj = new JAXLXml('message', array('to'=>'1@a.z', 'from'=>'2@b.c'));
jaxl 2> $xml_obj->c('body')->attrs(array('xml:lang'=>'en'))->t('Hello World!')->up()
....... ->c('thread')->t('id-1234')->up()
....... ->c('nested-stuff')
....... ->c('nest')->t('nest1')->up()
....... ->c('nest')->t('nest2')->up()
....... ->c('nest')->t('nest3')->up()->up()
....... ->c('c')->attrs(array('hash'=>'84jsdmnskd'));
jaxl 3> echo $xml_obj->to_string();
@abhinavsingh
abhinavsingh / gist:3708124
Created September 12, 2012 17:00
JAXLXml example for top() and up() api
$ ./jaxlctl shell
jaxl 1> $xml_obj = new JAXLXml('message', 'jabber:client', array('to'=>'friend@domain.tld'));
jaxl 2> echo $xml_obj->to_string();
<message xmlns="jabber:client" to="friend@domain.tld"></message>
jaxl 3>
jaxl 3> // after this operation rover will point to `body` child node
jaxl 3> $xml_obj->c('body');
jaxl 4> echo $xml_obj->to_string();
<message xmlns="jabber:client" to="friend@domain.tld"><body></body></message>
jaxl 5>
@abhinavsingh
abhinavsingh / gist:3708041
Created September 12, 2012 16:49
JAXLXml example for appending a child node using cnode($node) api
$ ./jaxlctl shell
jaxl 1> $xml_obj = new JAXLXml('message', 'jabber:client', array('to'=>'myfriend@gmail.com'));
jaxl 2> echo $xml_obj->to_string();
<message xmlns="jabber:client" to="myfriend@gmail.com"></message>
jaxl 3>
jaxl 3> $child = new JAXLXml('body', null, array(), 'Hello World!');
jaxl 4> echo $child->to_string();
<body>Hello World!</body>
jaxl 5>
jaxl 5> $xml_obj->cnode($child);
@abhinavsingh
abhinavsingh / gist:3707985
Created September 12, 2012 16:41
JAXLXml example for adding a child node using c($name, $ns, $attrs, $text) api
$ ./jaxlctl shell
jaxl 1> $xml_obj = new JAXLXml('message', 'jabber:client', array('to'=>'myfriend@gmail.com'));
jaxl 2> echo $xml_obj->to_string();
<message xmlns="jabber:client" to="myfriend@gmail.com"></message>
jaxl 3>
jaxl 3> $xml_obj->c('body', null, array(), 'Hello World!');
jaxl 4> echo $xml_obj->to_string();
<message xmlns="jabber:client" to="myfriend@gmail.com"><body>Hello World!</body></message>
jaxl 5>
jaxl 5> quit