Skip to content

Instantly share code, notes, and snippets.

These are my results:
{1: 2.327260809430917,
2: 1.7694565749482591,
3: 1.3241503620006503,
4: 0.7659831585049286,
5: 0.786389897507167,
6: 0.4727930181724931,
7: 0.5592591157981355,
8: 0.5410198394120904,
9: 0.4966728396999276,
in my html:
<script>
angular.module('myApp').value('initData,
{myjson}
)
<script>
in my controller:
type Point = (Int, Int) -- Could have more elements
type Range = (Int, Int)
pointsInRanges :: Range -> Range -> [Point] -> [Point] -- All points where fst p is in the first range and snd p is in the second range.
@reite
reite / gist:5568152
Last active December 17, 2015 06:49
parseInvoices :: L.ByteString -> Either String [Invoice]
parseInvoices s = do
result <- eitherDecode s
flip parseEither result $ \obj -> do
d <- (obj .: "invoices") >>= (.: "invoice")
case d of
Object v -> return [v]
Array v -> return v
@reite
reite / gist:5568677
Last active December 17, 2015 06:49
objToArray :: Value -> Array
objToArray obj@(Object v) = V.singleton obj
--I need a value of type Value for further processing. How can I make the result Array into a Value type?
-- Definitions of types from source of Data.Aeson.Types
-- | A JSON \"object\" (key\/value map).
type Object = HashMap Text Value
arrToListObj :: Maybe Value -> Maybe [Object]
arrToListObj (Just (Array arr@(Object v))) = Just $ V.toList arr
arrToListObj _ = Nothing
@reite
reite / gist:5767455
Last active December 18, 2015 10:19
parseAddresses :: Object -> Parser [[String]]
parseAddresses v = v .: "vout" >>= mapM (.: "scriptPubKey") >>= mapM (.: "addresses")
@reite
reite / gist:7038067
Created October 18, 2013 08:03
How can I write the second function in point free style?
data Foo = Foo1 String
| Foo2 String Int
data Bar = Bar Foo
foo1 :: String -> Bar
foo1 = Bar . Foo1
foo2 :: String -> Int -> Bar
foo2 a b = Bar (Foo2 a b)
root 2907 0.0 0.0 22376 1520 ? S Oct28 0:00 /usr/lib/ghc/lib/runghc -f /usr/lib/ghc/bin/ghc -i=/cube/cube/src -package-db=/cube/cube/cabal-dev/packages-7.6.2.conf /cube/cube/src/Server.hs
root 2908 5.1 37.0 1113172 626432 ? Sl Oct28 1688:32 /usr/lib/ghc/lib/ghc -B/usr/lib/ghc -ignore-dot-ghci -x hs -i=/cube/cube/src -package-db=/cube/cube/cabal-dev/packages-7.6.2.conf -e :set prog "/cube/cube/src/Server.hs" -e :main [] /cube/cube/src/Server.hs
@reite
reite / gist:7753128
Last active December 30, 2015 00:59
import requests
import grequests
import json
url = r'http://hotell.difi.no/api/json/brreg/enhetsregisteret?query=Merisma%20Development%20AS'
def sync():
for _ in xrange(50):