This file contains 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
import time | |
input = ['a', 'b', 'c', 'd', 'e', 'f'] | |
iterations = 1000000 | |
start = time.time() | |
for i in xrange(iterations): | |
s = dict([(x.lower(), i) for i, x in enumerate(input)]) | |
end = time.time() | |
print "First thing took %s seconds" % (end - start) |
This file contains 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
feed_insights=# explain select count(distinct(user_id)) from interests where keywords in (select keywords from interests group by keywords having count(*) > 30); | |
QUERY PLAN | |
--------------------------------------------------------------------------------------------------- | |
Aggregate (cost=2232807.48..2232807.49 rows=1 width=4) | |
-> Hash Join (cost=1780566.44..2221413.32 rows=4557663 width=4) | |
Hash Cond: (public.interests.keywords = public.interests.keywords) | |
-> Seq Scan on interests (cost=0.00..172441.36 rows=9188836 width=19) | |
-> Hash (cost=1778239.13..1778239.13 rows=133865 width=15) | |
-> GroupAggregate (cost=1706310.89..1776900.48 rows=133865 width=15) | |
Filter: (count(*) > 30) |
This file contains 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 greets(function): | |
... def greets_wrapper(*args, **kwargs): | |
... print "hi there, ", function | |
... return function(*args, **kwargs) | |
... return greets_wrapper | |
... | |
>>> @greets | |
... def add(num1, num2): | |
... return num1 + num2 | |
... |
This file contains 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
(** | |
* OCaml for the Curious | |
An Introductory tutorial in OCaml | |
Compiled by Prasad Rao (raoprasadv AT gmail DOT com) | |
Compiled together from various sources. | |
As this material is introductory | |
_None_ of this material is likely to be original. I thank |
This file contains 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
package httptimeout | |
import ( | |
"net/http" | |
"time" | |
"fmt" | |
) | |
type TimeoutTransport struct { | |
http.Transport |
This file contains 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
2014-05-31 19:24:29,346 WARN : org.graylog2.rest.resources.search.SearchResource - Unable to execute search: Failed to execute phase [query], all shards failed; shardFailures {[QuBZzG4dRFK2NpQkn3BFlg][graylog2_0][0]: RemoteTransportException[[Leap-Frog][inet[/10.102.144.101:9300]][search/phase/query]]; nested: SearchParseException[[graylog2_0][0]: from[0],size[100]: Parse Failure [Failed to parse source [{"from":0,"size":100,"query":{"query_string":{"query":"column \\\"product_id\\\" of relation \\\"cart_records\\\" does not exist\" P:\"61\"","allow_leading_wildcard":false}},"post_filter":{"bool":{"must":{"range":{"timestamp":{"from":"2014-05-31 18:24:29.330","to":"2014-05-31 19:24:29.330","include_lower":true,"include_upper":true}}}}},"sort":[{"timestamp":{"order":"desc"}}]}]]]; nested: QueryParsingException[[graylog2_0] Failed to parse query [column \"product_id\" of relation \"cart_records\" does not exist" P:"61"]]; nested: ParseException[Cannot parse 'column \"product_id\" of relation \"cart_records\" do |
This file contains 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
import re | |
def lex(s): | |
return re.findall("(\(|\)|[\w\*\+\-]+)", s) | |
def get_ast(tokens): | |
ast = [] | |
while tokens: | |
t = tokens.pop(0) | |
if t == '(': |
This file contains 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
module Bear (main, findMinSubStr) where | |
import qualified Data.Map.Strict as Map | |
import qualified Data.List as List | |
import qualified Data.ByteString as BS | |
import Data.Maybe (fromMaybe) | |
import Data.ByteString.Char8 (readInt) | |
import GHC.Word (Word8) | |
type CharFreq = Map.Map Word8 Int |
This file contains 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
dim mat = (length mat, length (head mat)) | |
subMats mat (height, width) = | |
[trimmed | r <- [0..rows] | |
, c <- [0..columns] | |
, let vertTrimmed = take height (drop r mat) | |
trimmed = map (take width . drop c) vertTrimmed | |
, length trimmed == height | |
, length (head trimmed) == width] | |
where (rows, columns) = dim mat |
This file contains 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
{-# LANGUAGE ScopedTypeVariables #-} | |
module BinarySearch where | |
import Data.Array | |
binarySearch :: (Ord a1) => Array Int a1 -> a1 -> Int -> Int -> Maybe Int | |
binarySearch haystack needle lo hi | |
| hi < lo = Nothing | |
| pivot > needle = binarySearch haystack needle lo (mid-1) |
OlderNewer