This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prettify(value): | |
decimal, integer = math.modf(value) | |
decimal = '%0.2f' % decimal | |
decimal = decimal[decimal.index('.'):] | |
sign = '' if integer >= 0 else '-' | |
integer = abs(int(integer)) | |
result = (',' if integer > 1000 else '') + str(integer % 1000) | |
while integer / 1000 > 1: | |
integer /= 1000 | |
result = (',' if integer > 1000 else '') + str(integer % 1000) + result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* PROMPT | |
* You are given an array named data that represents posts in proper sorted | |
* order. Each element in the array represent post data, and is itself an | |
* array. The first element for the post array represents the post id, the | |
* second element is the parent post id, and the third is the message. If | |
* the parent post id is 0, it's a top level comment. Construct a simple | |
* HTML representation of our comment thread using <ul> and <li> elements | |
* from this array of posts making sure to keep track of proper depth. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for site, sns in _map.iteritems(): | |
counts_total = [0] * 5 | |
for sn in sns: | |
counts = [[int(c) for c in l.split('\t')[1:]] for l in website_map[sn]] | |
for count in counts: | |
counts_total = [sum(c) for c in zip(counts_total, count)] | |
print '%s\t%s' % (site.strip(), '\t'.join([str(c) for c in counts_total])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_last_line(fd): | |
""" | |
Efficiently read the last line of a file by seeking to the | |
end of the file and looping backwards until the first linefeed | |
character is encountered. Ignores trailing newlines at the EOF | |
""" | |
# seek to the end of the file | |
fd.seek(0, 2) | |
size = fd.tell() | |
if size == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This will allow you to rebalance the Cassandra ring | |
# Accepts hosts from stdin and automatically rebalances | |
# tokens in your ring. | |
# | |
# $ echo "one two three" | ./rebalance.sh | |
RING_SIZE=$(echo "2^127" | bc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns | |
Compress 1K bytes with Zippy 3,000 ns | |
Send 2K bytes over 1 Gbps network 20,000 ns | |
Read 1 MB sequentially from memory 250,000 ns | |
Round trip within same datacenter 500,000 ns | |
Disk seek 10,000,000 ns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RollingMean(object): | |
count = 0 | |
average = 0 | |
@property | |
def val(self): | |
return self.average | |
def add(self, value): | |
self.average = (value + self.count * self.average) / (self.count + 1) | |
self.count += 1 | |
return self.average |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example.storm.clj.spout.kafka-spout | |
(:import ; [example.storm.spout UnreliableKafkaSpout] | |
[storm.kafka HostPort KafkaSpout SpoutConfig StringScheme])) | |
(def ^:dynamic *kafka-hosts* ["kafka-1.example.net" | |
"kafka-2.example.net" | |
"kafka-3.example.net"]) | |
(def ^:dynamic *kafka-ports* [9093 | |
9094 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defbolt split-category ["category" "event"] | |
[tuple collector] | |
(let [event (.getString tuple 0) | |
category "testing_category2"] | |
(comment | |
(emit-bolt! collector [category event] :anchor tuple) | |
) | |
(emit-bolt! collector [category event] :anchor tuple :stream "3") | |
(ack! collector tuple))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get foo | |
set foo foo | |
get bar, via property | |
set bar bar |