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
// Playground - noun: a place where people can play | |
import UIKit | |
func $(s1 : String) -> [String] { | |
return ["selector: " + s1] | |
} | |
func css(s1 : String) -> [String] -> [String] { | |
return { (data: [String]) -> [String] in |
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
-- | Generate list permutations in Haskell | |
-- >>> permutateList [[1,2], [3,4]] | |
-- [[1,3],[1,4],[2,3],[2,4]] | |
permutateList :: [[a]] -> [[a]] | |
permutateList = foldl (liftA2 (++)) [[]] . map (map (: [])) |
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
-- | commentBlockStart | |
-- >>> parse stripCommentBlock "fail" "hello world /* fo /*meow face */o */ bar * / * / /* poop /* zz **/*/ end" | |
-- Right "hello world bar * / * / end" | |
stripCommentBlock :: GenParser Char st String | |
stripCommentBlock = do | |
first <- many (noneOf "/") | |
rest <- (eof >> return "") <|> (commentBlock >> stripCommentBlock) <|> ((++) <$> string "/" <*> stripCommentBlock) | |
return (first ++ rest) | |
-- | commentBlock |
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
/* @TODO this query is slow because OFFSET is slow! */ | |
with data as ( | |
/* your query */ | |
), sample_size as (select generate_series(1, /* sample size */)) | |
select t.* | |
from (select trunc(random() * (select count(*) from data)) as offset_index from sample_size) sample | |
left join data t on t.id = (select id from data limit 1 offset sample.offset_index); |
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
select sort(array_agg(select id from data where ts_rank(name_vector, name) > 0.8) || id) as bucket | |
from data | |
group by bucket |
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
/* build recursive category */ | |
create table category ( | |
id uuid primary key default uuid_generate_v4(), | |
name text not null, | |
parent uuid, | |
foreign key (parent) references category(id) | |
); | |
insert into category values (default, 'food', null); | |
insert into category values (default, 'snacks', (select id from category where name = 'food')); |
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
In [3]: def foo(): yield 1; yield 2; return | |
In [4]: def foo(): yield 1; yield 2; return 3 | |
File "<ipython-input-4-e56b14727cad>", line 1 | |
def foo(): yield 1; yield 2; return 3 | |
SyntaxError: 'return' with argument inside generator |
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
@property | |
@memoize | |
def db_connection(): | |
return DBConnection() |
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 MyState where | |
import Control.Monad.State.Lazy | |
data MyState s a = MyState { state :: s, carry :: a } deriving Show | |
data MyMonadState s a = MyMonadState (s -> (MyState s a)) | |
myGet :: MyMonadState s s | |
myGet = MyMonadState (\s -> (MyState s s)) |
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
#!/usr/bin/env python | |
from logentries import LogentriesHandler | |
import logging | |
import time | |
handler = LogentriesHandler(LOGENTRIES_TOKEN) | |
log = logging.getLogger('logentries') | |
log.addHandler(handler) |