June 11, 2010

Ode to an Orange

A whiff of citrus – vibrant,
shiny, dimpled and thick,
your fingers move, probing
textural ecstacy,
as your tastes await
the sweet tartness within.
Peel away the layers
softly, envelop a piece,
let your tongue steep
in a myriad of flavors,
with the lingering scent
of summer under a blue sky,
look around,
and all is well again.

--

If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.

June 04, 2010

Stack implementation in Clojure II - A functional approach

My last post on the topic was creating a stack implementation using Clojure protocols and records – except, it used atoms internally and wasn’t inherently “functional”.

Here’s my take on a new implementation that builds on the existing protocol and internally, always returns a new stack keeping the original one unmodified. Comments welcome!

(ns viksit-stack (:refer-clojure :exclude )) (defprotocol PStack "A stack protocol" (push "Push element in") (pop "Pop element from stack") (top "Get top element from stack")) ; A functional stack record that uses immutable semantics ; It returns a copy of the datastructure while ensuring the original ; is not affected. (defrecord FStack PStack (push "Return the stack with the new element inserted" (FStack. (conj coll val))) (pop "Return the stack without the top element" (FStack. (rest coll))) (top "Return the top value of the stack" (first coll))) ; The funtional stack can be used in conjunction with a ref or atom viksit-stack> (def s2 (atom (FStack. '()))) #'viksit-stack/s2 viksit-stack> s2 #<atom> viksit-stack> (swap! s2 push 10) #:viksit-stack.FStack{:coll (10)} viksit-stack> (swap! s2 push 20) #:viksit-stack.FStack{:coll (20 10)} viksit-stack> (swap! s2 pop) #:viksit-stack.FStack{:coll (10)} viksit-stack> (top @s2) 10 </atom>

--

If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.

June 03, 2010

Resolving Chrome's SSL Error

I recently started getting a number of SSL related errors on accessing https links with Google Chrome on Ubuntu. One looks like,

107 (net::ERR_SSL_PROTOCOL_ERROR)

The top link on Google’s search results is pretty fuzzy, so here’s the solution that works for me.

Go to Settings -> Options -> Under the hood, and enable both SSL 2.0 and SSL 3.0. This should allow Chrome to talk to the server with either protocol.

There’s also a DEFLATE bug that got fixed to solve this issue in release 340 something. http://codereview.chromium.org/1585041

--

If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.

June 02, 2010

Stack implementation in Clojure using Protocols and Records

I was trying to experiment with Clojure Protocols and Records recently, and came up with a toy example to clarify my understanding of their usage in the context of developing a simple Stack Abstract Data Type.

For an excellent tutorial on utilizing protocols and records in Clojure btw – check out (http://kotka.de/blog/2010/03/memoize_done_right.html#protocols).

;; Stack example abstract data type using Clojure protocols and records ;; viksit at gmail dot com ;; 2010 (ns viksit.stack (:refer-clojure :exclude )) (defprotocol PStack "A stack protocol" (push "Push element into the stack") (pop "Pop element from stack") (top "Get top element from stack")) (defrecord Stack PStack (push (swap! coll conj val)) (pop (let (swap! coll rest) ret)) (top (first @coll))) ;; Testing stack> (def s (Stack. (atom '()))) #'stack/s stack> (push s 10) (10) stack> (push s 20) (20 10) stack> (top s) 20 stack> s #:stack.Stack{:coll #<atom>} stack> (pop s) 20 </atom>

More tutorial links on Protocols,

\ http://blog.higher-order.net/2010/05/05/circuitbreaker-clojure-1-2/
\ http://freegeek.in/blog/2010/05/clojure-protocols-datatypes-a-sneak-peek/
\ http://groups.google.com/group/clojure/browse\_thread/thread/b8620db0b7424712

--

If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.

May 21, 2010

PyCassa vs Lazyboy (updated)

Update

As Hans points out in the comment below, it appears pycassa natively supports authentication with org.apache.cassandra.auth.SimpleAuthenticator. Lazyboy on the other hand doesn’t by default.

It’s not too hard to do it though. Intuitively, we could do something like this.

NB: Untested code!! I might create a patch for this when I get the time, so this is just an outline.

# Add this to lazyboy's connection package from cassandra.ttypes import AuthenticationRequest

And in lazyboy’s _connect() function, add another parameter called logins, that is a dict of keyspaces and credentials which looks like the following.

# logins format {'Keyspace1' : {'username':'myuser', 'password':'mypass'}} def _connect(self, logins): """Connect to Cassandra if not connected.""" client = self._get_server() if client.transport.isOpen() and self._recycle: if (client.connect_time + self._recycle) > time.time(): return client else: client.transport.close() elif client.transport.isOpen(): return client try: client.transport.open() # Login code # Remember that client is an instance of Cassandra.Client(protocol) if logins is not None: for keyspace, credentials in logins.iteritems(): request = AuthenticationRequest(credentials=credentials) client.login(keyspace, request) client.connect_time = time.time() except thrift.transport.TTransport.TTransportException, ex: client.transport.close() raise exc.ErrorThriftMessage( ex.message, self._servers)

Original Post
I’ve been looking to answer which Python library is currently more fully featured to use to communicate with Cassandra.

From Reddit,

API-wise, both look like they are pretty much basic wrappers around the Cassandra Thrift bindings. I’d prefer lazyboy over pycassa though, given that firstly, it’s being used in production right now at Digg, and because it looks like lazyboy’s connection code is more featured than pycassa.

and

The connection code (Lazyboy) seems to be much more suited for use in production (use of auto pooling, auto load balancing, integrated failover/retry, etc.) (than PyCassa)

Thanks to GitHub, I was able to do some analysis of their traffic and commits,

Traffic Data

!(http://chart.apis.google.com/chart?chd=s:LMMeDMGFJFDEBECGCAEEEFFGKHEHOMEGBCDFGQEDDGIFEMCDEEEGBKDFDNCEODCJCFWLHJushZOQn9VgRbMMeVsn0i&chs=460x100&cht=lc&chxl=0:%7C2009-12-14%7C2010-01-13%7C2010-02-12%7C2010-03-14%7C1:%7C0%7C80%7C101%7C134%7C202%7C404&chm=B,EBF5FB,0,0,0&chco=008Cd6&chls=3,1,0&chg=8.3,20,1,4&chxt=x,y)

**LazyBoy**
!(http://chart.apis.google.com/chart?chd=s:AAAAAAAAJGGDCABCBAADADADHACAEFADABHDCAABNGFCCJCCDCDCCCGFDCACBACDCAFCDANVNIHLWcfUILOLVUZh9Z&chs=460x100&cht=lc&chxl=0:%7C2009-12-14%7C2010-01-13%7C2010-02-12%7C2010-03-14%7C1:%7C0%7C46%7C57%7C77%7C115%7C231&chm=B,EBF5FB,0,0,0&chco=008Cd6&chls=3,1,0&chg=8.3,20,1,4&chxt=x,y)
**Pycassa**
### Commit Data

!(http://chart.apis.google.com/chart?chs=400x150&chds=-1,24,-1,7,0,13&chf=bg,s,efefef&chd=t:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10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,0,0,0,0,0,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0&chxt=x,y&chm=o,333333,1,1.0,25.0&chxl=0:%7C%7C12am%7C1%7C2%7C3%7C4%7C5%7C6%7C7%7C8%7C9%7C10%7C11%7C12pm%7C1%7C2%7C3%7C4%7C5%7C6%7C7%7C8%7C9%7C10%7C11%7C%7C1:%7C%7CSun%7CMon%7CTue%7CWed%7CThr%7CFri%7CSat%7C&cht=s)

**LazyBoy**
!(http://chart.apis.google.com/chart?chs=400x150&chds=-1,24,-1,7,0,10&chf=bg,s,efefef&chd=t:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23%7C0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7%7C0,0,0,0,0,0,0,1,0,5,0,0,0,0,0,1,1,0,0,2,1,4,1,0,0,0,0,0,0,2,3,2,2,0,6,0,0,2,0,0,0,0,0,0,0,0,0,2,10,1,0,0,1,0,2,1,0,2,0,0,0,1,0,1,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,1,2,1,2,1,6,0,2,3,1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0&chxt=x,y&chm=o,333333,1,1.0,25.0&chxl=0:%7C%7C12am%7C1%7C2%7C3%7C4%7C5%7C6%7C7%7C8%7C9%7C10%7C11%7C12pm%7C1%7C2%7C3%7C4%7C5%7C6%7C7%7C8%7C9%7C10%7C11%7C%7C1:%7C%7CSun%7CMon%7CTue%7CWed%7CThr%7CFri%7CSat%7C&cht=s)
**Pycassa**
A larger number of people know about LazyBoy but code commits on it are currently on a stand still. Pycassa on the other hand seems to be growing at a pretty fast rate.

It looks like LazyBoy is probably a better library to start with, for now. I’ll talk about my experiences with both in another post.

--

If you have any questions or thoughts, don't hesitate to reach out. You can find me as @viksit on Twitter.