This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.Vector.FindMax where | |
import Data.Vector (Vector, (!), (!?)) | |
import qualified Data.Vector as V | |
import Data.Maybe (fromMaybe) | |
findMax :: Vector Int -> Maybe Int | |
findMax v | |
| V.null v = Nothing | |
| pivotValue > leftValue && pivotValue > rightValue = Just pivotValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.Integer.EveryOther where | |
genericEveryOther :: Monoid a => [a] -> [a] | |
genericEveryOther [] = [] | |
genericEveryOther xs = zipWith mappend (scanl mappend mempty (init xs)) (scanr mappend mempty (tail xs)) | |
everyOther :: [Int] -> [Int] | |
everyOther [] = [] | |
everyOther xs = zipWith (*) (scanl (*) 1 (init xs)) (scanr (*) 1 (tail xs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: copy me to .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
# Stash unstaged changes and untracked files before running tests | |
git stash -q --keep-index -u | |
# Run non-feature tests | |
rspec --format progress --tag ~type:feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: copy me to .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
# Stash unstaged changes and untracked files before running tests | |
git stash -q --keep-index -u | |
# Run non-feature tests | |
rspec --format progress --tag ~type:feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# from https://github.com/depy/my-git-hooks/blob/master/run-rspec-test-pre-commit | |
# usage: copy me to .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
# Stash unstaged changes before running tests | |
git stash -q --keep-index | |
# Run tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"latitude": 42.3212, | |
"longitude": -71.1103, | |
"timezone": "America\/New_York", | |
"offset": -4, | |
"currently": { | |
"time": 1460238221, | |
"summary": "Mostly Cloudy", | |
"icon": "partly-cloudy-day", | |
"nearestStormDistance": 8, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.List.Permute where | |
permute :: [a] -> [[a]] | |
permute [] = [[]] | |
permute xs = let picks = pick xs | |
f (x, xs') = map (x:) (permute xs') | |
in concatMap f picks | |
pick :: [a] -> [(a, [a])] | |
pick [] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.Tree where | |
import Data.List (sortBy) | |
import Data.Ord (comparing) | |
data Tree a = Tip | Node a (Tree a) (Tree a) | |
deriving (Show, Eq) | |
-- x, y | |
type Coords = (Int, Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ClosestToZero where | |
closestToZero :: [Int] -> Maybe Int | |
closestToZero [] = Nothing | |
closestToZero xs = Just $ foldl1 f xs | |
where f x y = case compare (abs x) (abs y) of | |
LT -> x | |
EQ -> abs x | |
GT -> y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class MapDiff { | |
public static void main(String[] args) { | |
Map<String, Integer> m1 = new HashMap<String, Integer>(); | |
m1.put("a", 1); | |
m1.put("b", 2); | |
m1.put("c", 3); | |
Map<String, Integer> m2 = new HashMap<String, Integer>(); |