Skip to content

Instantly share code, notes, and snippets.

View purcell's full-sized avatar

Steve Purcell purcell

View GitHub Profile
module Main where
import Text.Parsec
import Text.Parsec.String
main :: IO ()
main = do
input <- getLine
@purcell
purcell / Classifier.hs
Created October 21, 2015 08:06
naive bayes
module Classifier
( Classifier(..)
, empty
, update
, union
, classify
, singleton
, scaled
, test
) where
module Puzzle where
valid :: Integer -> Bool
valid abcde = divisibleBy bcde && divisibleBy cde && divisibleBy de && divisibleBy e
where divisibleBy n = n /= 0 && ((abcde `mod` n) == 0)
bcde = abcde `mod` 10000
cde = bcde `mod` 1000
de = cde `mod` 100
e = de `mod` 10
@purcell
purcell / FizzBuzz.hs
Created October 30, 2014 12:18
fizzbuzz
module FizzBuzz where
fizzbuzz :: (Show a, Integral a) => a -> String
fizzbuzz n = case (n `rem` 3, n `rem` 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
_ -> show n
main = mapM_ (putStrLn . fizzbuzz) [1..50]
@purcell
purcell / FizzBuzz.hs
Created October 30, 2014 11:22
fizzbuzz
module FizzBuzz where
import Data.Maybe
data FizzBuzz = Fizz | Buzz deriving Show
whenDivisible :: Integral a => a -> b -> a -> Maybe b
whenDivisible d x n = if n `rem` d == 0 then Just x else Nothing
fizzbuzz :: (Show a, Integral a) => a -> String
fizzbuzz n = if null tags then show n else concatMap show tags
@purcell
purcell / FizzBuzz.hs
Created October 29, 2014 22:49
fizzbuzz
module FizzBuzz where
data FizzBuzz = Fizz | Buzz | FizzBuzz deriving Show
fizzbuzz :: Integral a => a -> Either FizzBuzz a
fizzbuzz n = case (n `rem` 3, n `rem` 5) of
(0, 0) -> Left FizzBuzz
(0, _) -> Left Fizz
(_, 0) -> Left Buzz
_ -> Right n
@purcell
purcell / console.log
Created April 11, 2014 09:55
iStat Menus breakage - console log
11/04/2014 10:49:11.070 SystemUIServer[10295]: Could not load menu extra NSBundle </Library/Application Support/iStat Menus 4/extras/iStatMenusMemory.menu> (not yet loaded) for Class (null)
11/04/2014 10:49:11.071 SystemUIServer[10295]: Cannot find executable for CFBundle 0x7f9bf255df80 </Library/Application Support/iStat Menus 4/extras/iStatMenusDrives.menu> (not loaded)
11/04/2014 10:49:11.071 SystemUIServer[10295]: Could not load menu extra NSBundle </Library/Application Support/iStat Menus 4/extras/iStatMenusDrives.menu> (not yet loaded) for Class (null)
11/04/2014 10:49:11.463 iStatMenusAgent[10329]: Loading istat menus agent
11/04/2014 10:49:11.463 iStatMenusAgent[10329]: iStat Menus Agent version 4.21 (450)
11/04/2014 10:49:11.514 iStatMenusAgent[10329]: iStat Menus Agent - Update checker enabled
11/04/2014 10:49:54.681 SystemUIServer[160]: Cannot find executable for CFBundle 0x7f8dca5181d0 </Library/Application Support/iStat Menus 4/extras/MenuCracker.menu> (not loaded)
11/04/2014 10:49:54.682 SystemU
@purcell
purcell / .slate
Last active February 7, 2018 20:57
Slate config
# See https://github.com/jigish/slate#readme
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config focusPreferSameApp false
config focusCheckWidthMax 3000
config checkDefaultsOnLoad true
config windowHintsShowIcons true
config windowHintsSpread true
@purcell
purcell / SpotifyPack.hs
Created February 13, 2014 13:16
Parsing spotify json in Haskell
{-# LANGUAGE OverloadedStrings #-}
module SpotifyPack
where
import qualified Network.URI as URI
import Network.HTTP (simpleHTTP, getRequest, getResponseBody)
import Data.Aeson (FromJSON, parseJSON, decode, (.:))
import qualified Data.Aeson.Types as T
import qualified Data.ByteString.Lazy.Char8 as BSL
import Control.Applicative ((<$>), (<*>))
import Control.Monad (mzero)
@purcell
purcell / nginx.conf
Created January 30, 2014 14:27
nginx gzip snippet
gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 3;
gzip_buffers 16 8k;
gzip_min_length 150;
gzip_proxied any;
gzip_types text/plain text/xhtml text/css text/js text/csv application/javascript application/x-javascript application/json application/xml text/xml application/atom+xml application/rss+xml;