Skip to content

Instantly share code, notes, and snippets.

// Diary action creators
export class Diary {
static RECEIVE = 'DIARY_RECEIVE'
static actions = {
fetchByDate: (date) => {
const done = (dispatch, json) => dispatch(replace(`/diary/${json.id.toString()}`))
return post('/api/diary', Diary.RECEIVE, { date }, done)
},
fetchById: (logId) => {
@nurpax
nurpax / char-rnn.hs
Last active November 9, 2017 15:50
Some char-rnn generated Haskell based on training with the GHC HEAD source code
-- buildPatSynDetails, so this is a mempty, even the type
-- we generate the same location here.
hsConDeclDetails _ = pprPanic "tcLHsBindsCtOrigin" (ppr val_val_binds)
--------------------
zonkForeignCall :: FlexibleInfo -> CoreBind
-> Maybe FreeVars -- True <=> supplied EndBinds
-> RecFlag
-> Cts -> ForeignOpt Id
import Data.Maybe
import System.IO (readFile)
-- Open a file and process its contents with action, or return the default value 'deflt'
maybeWithFile :: Maybe FilePath -> b -> (String -> b) -> IO b
maybeWithFile fname deflt action = maybe (return deflt) (fmap action . readFile) fname
main :: IO ()
main = do
let inactiveWhitelist = Just "whitelist.txt"
@nurpax
nurpax / CMakeLists.txt
Last active December 20, 2018 03:14
cmake c++11 project
cmake_minimum_required (VERSION 2.6)
project (example)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable(example main.cpp)
@nurpax
nurpax / sqlite-simple-test.cabal
Last active August 29, 2015 14:23
sqlite-simple sample
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import qualified Data.Text as T
import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow
data TestField = TestField Int T.Text deriving (Show)
instance FromRow TestField where
all:
gcc -g main.c b.c -o test
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
import Data.Aeson
import Data.Time (UTCTime)
main = do
let Just (t :: [UTCTime]) = decode' "[\"2014-04-28T05:05:05.000Z\"]"
print t
let Just (t :: [UTCTime]) = decode' "[\"2014-04-28T05:05:05Z\"]"
print t
-- The below examples do not parse with aeson 0.7.0.3
@nurpax
nurpax / Test.hs
Created April 15, 2014 22:40
proof that Control.Lens rules
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data A = A {
_aId :: Int
, _bs :: [B]
} deriving (Show)
data B = B {
@nurpax
nurpax / Test.hs
Last active August 29, 2015 13:56
cabal sandbox example
import qualified Data.Text as T
main :: IO ()
main = putStrLn (T.unpack . T.pack $ "hello")
@nurpax
nurpax / gist:6840820
Last active December 24, 2015 18:09
unsigned int to float
#include <stdio.h>
static inline float uintToFloat(unsigned int v)
{
union {
unsigned int ui;
float f;
} c;
c.ui = v;
return c.f;