Skip to content

Instantly share code, notes, and snippets.

@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)
@reite
reite / gist:5767455
Last active December 18, 2015 10:19
parseAddresses :: Object -> Parser [[String]]
parseAddresses v = v .: "vout" >>= mapM (.: "scriptPubKey") >>= mapM (.: "addresses")
arrToListObj :: Maybe Value -> Maybe [Object]
arrToListObj (Just (Array arr@(Object v))) = Just $ V.toList arr
arrToListObj _ = Nothing
@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
@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
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.
in my html:
<script>
angular.module('myApp').value('initData,
{myjson}
)
<script>
in my controller:
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,