Skip to content

Instantly share code, notes, and snippets.

View pete-murphy's full-sized avatar

Pete Murphy pete-murphy

View GitHub Profile
@pete-murphy
pete-murphy / moneyParseFormat.js
Last active November 27, 2017 20:56
BofA Money Input: Parse & Format Functions
const format = num =>
(num / 100).toLocaleString("en-US", { style: "currency", currency: "USD" })
const parse = str => +str.replace(/[^0-9.]/, "") * 100
const rEFormat = num => {
const formattedNum =
num.toString().length < 3
? `000${num.toString()}`.slice(-3)
: num.toString()
return `$${formattedNum
module PhoneExercise where
import Data.Char
import Data.List (elemIndex)
import Data.Maybe (fromJust)
data DaPhone = DaPhone [(Digit, String)] deriving (Eq, Show)
type Digit = Char
type Presses = Int
@pete-murphy
pete-murphy / SemigroupExercises.hs
Created May 10, 2018 12:00
Haskell Book 15.15 Exercise 9
{-# LANGUAGE DeriveGeneric #-}
module SemigroupExercises where
import Data.Semigroup
import Test.QuickCheck
import GHC.Generics
-- ...
@pete-murphy
pete-murphy / 08-Mem.hs
Created May 12, 2018 00:26
Ch 15.15 (Monoid Exercises)
module Mem where
import Data.Monoid hiding ((<>))
import Data.Semigroup
newtype Mem s a =
Mem {
runMem :: s -> (a,s)
}
@pete-murphy
pete-murphy / Semigroup.purs
Created October 8, 2018 04:21
See lines 59--79: I'm trying not to write my own parser library, just want a `Parser` that fails with type `ValidationError` instead of `ParseError`
module Semigroup where
import Prelude
import Control.Alt ((<|>))
import Control.Plus (class Plus, class Alt)
import Data.Array as Array
import Data.Bifunctor as Bifunctor
import Data.Either as Either
import Data.Foldable as Foldable
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{"type":"Topology","arcs":[[[2787,3051],[15,-108]],[[2802,2943],[-118,-16],[-27,-20],[-72,1],[-2,22]],[[2583,2930],[2,51],[51,101]],[[2636,3082],[151,-31]],[[1757,3274],[120,-33]],[[1877,3241],[42,-12],[6,-35]],[[1925,3194],[14,-67],[-19,-55],[14,-41],[-3,-78]],[[1931,2953],[-413,4]],[[1518,2957],[25,149],[-33,215]],[[1510,3321],[247,-47]],[[4888,2903],[-228,3]],[[4660,2906],[-16,42],[6,54],[19,4],[-2,90]],[[4667,3096],[147,63]],[[4814,3159],[74,-256]],[[4347,3084],[11,-104],[-11,-65]],[[4347,2915],[-306,7]],[[4041,2922],[72,110],[23,49],[38,40],[32,108]],[[4206,3229],[38,12],[5,-37],[83,-27],[15,-93]],[[7441,6095],[83,-14],[109,-81],[94,42],[1,-133],[13,-59],[-80,8],[-77,-29],[-32,42],[-78,43]],[[7474,5914],[9,36],[-42,145]],[[8965,1854],[60,-9],[193,-8],[24,-29],[-16,-25],[-64,26],[-95,-16],[39,-26],[-20,-34],[39,17],[134,-8],[37,15],[16,-24]],[[9312,1733],[8,-56],[-41,-158]],[[9279,1519],[2,-65],[-50,13],[-76,-38],[-70,41],[-48,-6],[-44,-33],[5,-41],[-83,-30],[20,68],[-33,55],[-14,-35],[-65,-35],[-5,-42],[
module Main where
removePlus :: String -> String
removePlus = filter (/= '+')
toInts :: String -> [Int]
toInts = map ((read :: String -> Int) . removePlus) . lines
solve :: [Int] -> Int
solve xs = go [0] xs
@pete-murphy
pete-murphy / Main.hs
Last active December 3, 2018 02:36
Interview Coding Challenge
module Main where
import Data.List
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (listToMaybe, maybe)
import Data.Ord (comparing)
import System.Environment (getArgs)
data ReportEntry = ReportEntry