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 Data.List (intersperse, foldl') | |
import Data.List.Split (chunksOf) | |
numbers :: Int -> String | |
numbers c = | |
case c of | |
0 -> "" | |
1 -> "one" | |
2 -> "two" |
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
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-} | |
{-# LANGUAGE FunctionalDependencies, TypeApplications #-} | |
import Data.Proxy | |
data User | |
class MyClass a b | b -> a | |
instance MyClass Char 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
#!/usr/bin/python | |
# sendemail.pl - Sends email based on a conf file or arguments | |
# DOCUMENTATION: | |
# USAGE: | |
# Either: | |
# sendemail.py | |
# - Checks /mnt/sdcard/tmp/mailout.conf by default | |
# sendemail.py <conf file location> | |
# - Specify a conf file location |
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 scala.language.implicitConversions | |
import scala.language.higherKinds | |
/** | |
* A simple typeclass that converts types A to some specific Java type | |
*/ | |
trait AllowedType[A] { | |
type JavaType >: Null <: AnyRef |
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
{-# LANGUAGE TypeOperators #-} | |
import Data.Maybe | |
import Control.Applicative | |
import Control.Category | |
import Prelude hiding ((.)) | |
data a ~> b = | |
Partial (a -> Maybe b) -- a partial function | |
| Defaulted (a ~> b) b -- a partial function with a default value |
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
#!/usr/bin/env bash | |
############ | |
# QuickSBT # | |
############ | |
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim | |
# http://github.com/aloiscochard / https://gist.github.com/4698501 | |
gitroot=$(git rev-parse --show-toplevel);\ |
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
countChg :: Int -> [Int] -> Int | |
countChg 0 _ = 1 -- There is only one way of counting an amount of 0 | |
countChg _ [] = 0 -- There are 0 ways to count for no coins | |
countChg amt coins@(c:cs) | |
| amt < 0 = 0 -- This branch failed, we got something less than 0 | |
| otherwise = countChg amt cs + countChg (amt - c) coins -- Branch out into a branch with one less coin and | |
-- a branch with the same number of coins but one coin | |
-- reduced from the amount |
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
trait TypeclassA[A] { } | |
trait TypeclassB[A] { } | |
trait TypeclassC[A] { | |
implicit val typeAInstance: TypeclassA[A] | |
implicit val typeBInstance: TypeclassB[A] | |
} | |
object TypeclassC { |
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
findLowest :: [Int] -> [Int] -> Int | |
findLowest as bs = findLowest' (sort as) (sort bs) | |
where | |
findLowest' _ [] = -1 | |
findLowest' [] _ = -1 | |
findLowest' (a:ta) (b:tb) | |
| a == b = a | |
| b < a = findLowest' (a:ta) (tb) | |
| otherwise = findLowest' ta (b:tb) |
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
{-# LANGUAGE MultiWayIf #-} | |
-- http://codercareer.blogspot.com/2013/03/no-46-nodes-with-sum-in-binary-search.html | |
data Tree a = Leaf a | Branch a (Tree a) (Tree a) | |
deriving Show | |
getValue (Leaf v) = v | |
getValue (Branch v _ _) = v |
NewerOlder