Skip to content

Instantly share code, notes, and snippets.

View jimbaker's full-sized avatar

Jim Baker jimbaker

View GitHub Profile
@jimbaker
jimbaker / gist:5602756
Created May 18, 2013 00:26
Experiment on chained exceptions in Twisted
from twisted.internet.defer import Deferred
# presumably should do some sort of chaining like so
# http://stackoverflow.com/questions/1350671/inner-exception-with-traceback-in-python
# by using methods from twisted.python.failure.Failure
#
# there may also be better support for this in Twisted already :)
def err_handler(failure):
failure.trap(OSError)
@jimbaker
jimbaker / excl.py
Last active December 17, 2015 20:19
Storm code in Jython
import time
from backtype.storm import Config, LocalCluster
from backtype.storm.tuple import Fields, Values
from backtype.storm.topology import TopologyBuilder
from plumbing import ExclamationBolt, WordSpout
def get_topology_builder():
@jimbaker
jimbaker / gist:5671800
Last active August 7, 2018 10:49
Leader election in Cassandra using compare-and-swap support in CQL

CAS (atomic compare-and-swap) support (https://issues.apache.org/jira/browse/CASSANDRA-5062) is now finished in Cassandra for 2.0, along with the earlier corresponding CQL support (https://issues.apache.org/jira/browse/CASSANDRA-5443). Specifically this support was implemented in the context of high latency, much like C* in general.

In their implementation, they chose to do a Paxos implementation; Zookeeper is not used at all.

CAS is a basic building block, much like the ZNode ops in ZK. In particular, here's a first attempt at a recipe to do leader election:

  1. Potential leaders each generate a UUID
  2. Attempt to store the UUID; if the following returns true, this means it's the leader:
@jimbaker
jimbaker / gen-special-proxies.py
Last active December 18, 2015 23:28
Spike on custom proxymaking; I run it like so CLASSPATH="`storm classpath`" jython27 gen-special-proxies.py
import os
import os.path
from java.lang.reflect import Modifier
from org.python.util import CodegenUtils
from org.python.compiler import JavaMaker
class SerializableProxies(JavaMaker):
@jimbaker
jimbaker / clamp.py
Created June 26, 2013 21:18
Example clamp in Python
import java
import os
import os.path
from java.lang.reflect import Modifier
from org.python.util import CodegenUtils
from org.python.compiler import CustomMaker, ProxyCodeHelpers
__all__ = ["PackageProxy", "SerializableProxies"]
@jimbaker
jimbaker / jira.md
Last active December 19, 2015 01:59
New JIRA stories for supporting Storm

Push custom proxymaker support into upstream Jython

Enables arbitrary class resolution, which is important for using the same class definition from ahead-of-time compilation (eg setup.py) This mostly requires writing additional tests, but there is also some required work on doc comments.

Client support for managing web hook calls

Some choices here for managing hooks

@jimbaker
jimbaker / nuke-listener.py
Created July 16, 2013 23:46
This should work based on this blog post (http://www.giantflyingsaucer.com/blog/?p=4078), but apparently some refactoring in the last year, so it doesn't. Illustrative regardless.
import time
from java.util.concurrent import TimeUnit
from org.atomnuke.listener import AtomListener, AtomListenerResult
from org.atomnuke import NukeKernel
from org.atomnuke.source.crawler import FeedCrawlerSourceFactory
from org.atomnuke.task import Task
from org.atomnuke.util import TimeValue
class SimpleListener(AtomListener):
@jimbaker
jimbaker / gist:6024424
Created July 17, 2013 20:57
Example of using proxymaker branch to generate a Java class of desired shape; emitted by javap -v WordSpout.class from https://github.com/jimbaker/jython-storm-starter
Classfile /Users/jbaker/experiments/jython-storm-starter/custom/otter/excl/plumbing/WordSpout.class
Last modified Jun 26, 2013; size 2520 bytes
MD5 checksum d409ee8487af9709bda9e468e820d326
public class otter.excl.plumbing.WordSpout extends backtype.storm.topology.base.BaseRichSpout implements org.python.core.PyProxy,org.python.core.ClassDictInit
RuntimeVisibleAnnotations:
0: #101(#102=I#103)
1: #104(#102=J#105)
minor version: 0
major version: 49
flags: ACC_PUBLIC, ACC_SUPER
@jimbaker
jimbaker / abdera-consumer.py
Last active December 19, 2015 23:49
Spike that uses Apache abdera to follow Atom feeds. This works much better than atomnuke, which is now deprecated.
from array import array
from contextlib import closing
import sys
import time
from javax.net.ssl import SSLContext, TrustManager, X509TrustManager
from java.net import URL
from org.apache.abdera import Abdera
@jimbaker
jimbaker / expose_processor.py
Created July 30, 2013 07:02
Expose annotation processor, in Jython
import os
import os.path
import sys
from org.objectweb.asm import ClassWriter
from org.python.expose.generate import ExposedTypeProcessor
def generate(exposer):
writer = ClassWriter(ClassWriter.COMPUTE_FRAMES)