Skip to content

Instantly share code, notes, and snippets.

{-# 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
all:
gcc -g main.c b.c -o test
@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
@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)
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 / 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
// 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 / bits.js
Created February 18, 2018 21:05
jsx
// NOTE only up to 5 bit numbers are supported
function makeFormula (bits) {
const superscripts = ['\u2070', '\u00B9', '\u00B2', '\u00B3', '\u2074']
const nbits = bits.length
const parts = bits.map((b,idx) => {
const boffs = nbits - idx - 1
return b.toString() + '\u22C5' + '2' + superscripts[boffs]
})
return parts.join(' + ')
}
// Diary action creators
export class Diary {
static RECEIVE = 'DIARY_RECEIVE'
static actions = {
fetchByDate: (date) => {
return function (dispatch, getState) {
const urls = [
'/api/food',
'/api/recipe',
renderSaveCancel = () => {
return (
<Fragment>
<button onClick={this.handleSave}
style={{width: '50%'}}
disabled={!this.state.amount}
className='button is-primary'>
Save
</button>
<button onClick={this.handleCancel}