Skip to content

Instantly share code, notes, and snippets.

// 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
-- | 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 (: []))
@munro
munro / StripBlockComment.hs
Created November 11, 2014 23:05
Strip block comments using Haskell Parsec
-- | 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
/* @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);
select sort(array_agg(select id from data where ts_rank(name_vector, name) > 0.8) || id) as bucket
from data
group by bucket
/* 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'));
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
@property
@memoize
def db_connection():
return DBConnection()
@munro
munro / MyState.hs
Last active August 29, 2015 14:20
Monads with no built in functions or type classes
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))
#!/usr/bin/env python
from logentries import LogentriesHandler
import logging
import time
handler = LogentriesHandler(LOGENTRIES_TOKEN)
log = logging.getLogger('logentries')
log.addHandler(handler)