Skip to content

Instantly share code, notes, and snippets.

View benkolera's full-sized avatar

Ben Kolera benkolera

  • biza.io
  • Brisbane, Australia
View GitHub Profile
@benkolera
benkolera / cabal.fail.log
Last active August 29, 2015 14:01
Cabal is making me sad today. Can't figure it out and need some guidance.
With this cabal version:
bkolera at Ben-imac in /tmp/barebones
$ cabal --version
cabal-install version 1.20.0.1
using version 1.20.0.0 of the Cabal library
And a cabal file looks like this:
Name: barebones
@benkolera
benkolera / feedback.md
Last active August 29, 2015 14:01
Feedback

James

  • Bigger code on lambda syntax page
  • Need some stuff here (on the slide before lambda typing)
  • Colours on new types page.
  • Missing type param on BiFunction on streams types page.
  • To vs Too on stream oprs page.
  • "Thnigs" on Bad - Inconsistent API page
  • Red on Bad was hard to read - Partial Application Page
  • (Making up Range) on Bad Type inference
  • About 30 minutes
@benkolera
benkolera / Main.hs
Created July 7, 2014 23:06
A thing written at work to do some basic xml & csv munging.
{-# LANGUAGE OverloadedLists, OverloadedStrings, TupleSections #-}
import Prelude hiding (readFile)
import Control.Applicative ((<$>),(<*>))
import Control.Error (Script,left,headMay,note,runScript,scriptIO)
import qualified Data.ByteString.Lazy as B
import Data.Char (isDigit)
import Data.Csv (FromNamedRecord,ToNamedRecord,decodeByName,encodeByName
,namedRecord,parseNamedRecord,toNamedRecord,(.=),(.:))
import Data.Default (def)
use strict;
use warnings;
=head1 NAME
create_dbic.pl
=head1 SYNOPSIS
perl maintenaince/create_dbic.pl --help | <options>
@benkolera
benkolera / makerpm.hs
Last active August 29, 2015 14:05
Installs the current package into a sandbox with its deps and packages /bin and /share as in rpm using the ruby based fpm tool. Deploys to /opt/haskell/apps/<appname>/{bin,share}
module Main where
import Control.Applicative ((<$>))
import Control.Monad (mfilter)
import Data.Char (toLower,isSpace)
import Data.List (dropWhileEnd,intercalate)
import Data.Time.Clock.POSIX
import Data.Version (versionBranch)
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse
@benkolera
benkolera / gist:f14b067f90da24102165
Created September 25, 2014 18:23
For later. Yoneda.
00:34 <edwardk> spacekitteh: not in 30 seconds or less ;)
00:37 <edwardk> but the short version of it is that if you take a category, and look at its hom-sets C^op * C -> Set and fix its second argument, so you are looking at the space of all arrows into an object, these spaces of arrows are what we call presheaves (functors from C^op -> Set) the yoneda embedding Y : C -> [ C^op, Set ] is the functor that takes objects in C to their corresponding presheaves in this way.
00:38 <edwardk> why is that interesting?
00:39 <edwardk> well, if you look the functor category [X, Y] of functors from X to Y with natural transformations between them as your arrows then you can find that this category inherits most of its structure from Y.
00:40 <edwardk> [2, Set] is Set^2, its basically pairs of objects for objects, pairs of arrows for arrows, it is cartesian because Set is cartesian, it is cocartesian because set is cocartesian, etc.
00:40 <edwardk> that suggests that [C^op, Set] acts a lot like Set!
00:40 <benl23> CCC ft
@benkolera
benkolera / gist:3f2aaad7e2ed86026a94
Created October 12, 2014 07:56
Lensy GetOpts, but could be nicer
{-# LANGUAGE OverloadedStrings,TemplateHaskell #-}
module Main (main) where
import Prelude ()
import BasePrelude
import Control.Lens
import Control.Monad.State (State,execState)
import Network.Wai.Handler.Warp
import Rest.Driver.Wai (apiToApplication)
@benkolera
benkolera / cabal-install-sandboxed.sh
Last active August 29, 2015 14:08
Installs a haskell lib into a sandbox and
NAME=$1
SANDBOX_BASE=$HOME/opt/haskell
SANDBOX_CONF=$SANDBOX_BASE/$NAME.sandbox.config
SANDBOX_DIR=$SANDBOX_BASE/$NAME
rm -fr $SANDBOX_DIR
rm -fr $SANDBOX_CONF
cabal --sandbox-config-file $SANDBOX_CONF sandbox init --sandbox $SANDBOX_DIR
cabal --sandbox-config-file $SANDBOX_CONF install $NAME
ln -s $SANDBOX_DIR/bin/* $HOME/bin/
@benkolera
benkolera / persistent.hs
Last active August 29, 2015 14:09
Wat?
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Success
who Text List
what Text
achievements Text List
|]
-- Generates a table with a single varchar for who / achievements without any error or warning.
-- It just gets completely ignored...
hush :: Either e a -> Maybe a
hush = either (const Nothing) Just
toId :: JObject -> Maybe Number
toId o = fromNumber <|> fromString
where
fromNumber = hush $ o .? "id"
fromString = do
s <- hush $ o .? "id"
mfilter (isNan >>> not) Just (readFloat s)