This file contains hidden or 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
| ''' | |
| Maya Python Github project bootstrapping script | |
| Makes particular Maya Python Github project releases available in Maya via the | |
| user script dir. Pass user, project, and release strings to getGithubRelease, | |
| which will download the zip file to the user script dir, and unzip it in there | |
| (if it doesn't yet exist). Returns the full path to the unzipped project | |
| folder, which can be used to modify sys.path[1], circumventing installation. | |
| Note: you still need to ensure all tools deal with one version of the project, |
This file contains hidden or 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 stack | |
| {- stack --resolver lts-7.13 --install-ghc runghc -} | |
| import Data.Maybe (mapMaybe) | |
| import System.Environment (getArgs) | |
| song :: Int -> Maybe String | |
| song 1 = Just "A Shandy Too Far" | |
| song 2 = Just "Adult Contemporary" | |
| song 3 = Just "Air Guitar" |
This file contains hidden or 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
| -- Clojure -> Haskell port of: https://gist.github.com/nasser/1db446782cf7f3587283 | |
| import System.Random (getStdRandom, randomR) | |
| pick :: [a] -> IO a | |
| pick xs = do | |
| n <- getStdRandom $ randomR (0, length xs - 1) | |
| return $ xs !! n | |
| adjs = ["people's", "brave", "invincible", "unstoppable", "righteous", "just", "honorable", "terrifying", "peaceful"] |
This file contains hidden or 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
| newtype MaybeIO a = MaybeIO (IO (Maybe a)) | |
| runMaybeIO :: MaybeIO a -> IO (Maybe a) | |
| runMaybeIO (MaybeIO x) = x | |
| hole = undefined | |
| data Hole = Hole | |
| instance Monad MaybeIO where | |
| return x = MaybeIO (return (Just x)) |
This file contains hidden or 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
| data MyState s a = MyState (s -> (a, s)) | |
| get :: MyState s s | |
| get = undefined | |
| put :: s -> MyState s () | |
| put = undefined | |
| modify :: (s -> s) -> MyState s () | |
| modify = undefined |
This file contains hidden or 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
| bottles :: Int -> String | |
| bottles x | x == 0 = "No more bottles" | |
| | x == 1 = "1 more bottle" | |
| | x < 13 = show x ++ " more bottles" | |
| | otherwise = show x ++ " bottles" | |
| verse :: Int -> String | |
| verse x = line1 ++ "\n" ++ line2 ++ "\n\n" | |
| where line1 = bottles x ++ obotw ++ " " ++ bottles x ++ ob | |
| line2 = todpia ++ bottles (x-1) ++ obotw |
This file contains hidden or 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 (sortBy) | |
| import Data.Ord (comparing) | |
| import qualified Data.Map as M (Map, fromList) | |
| data Freq a = V Int a | B Int (Freq a) (Freq a) deriving (Show) | |
| size :: Freq a -> Int | |
| size (V n _) = n | |
| size (B n _ _) = n |
This file contains hidden or 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 Control.Applicative ((<|>)) | |
| type Bonus = Int | |
| data Frame = Roll Int | Frame Int Int | Spare Int | Strike deriving (Show) | |
| badnum :: Int -> Bool | |
| badnum n = n < 0 || n > 10 | |
| strike, spare, frame :: [Int] -> Maybe (Frame, Bonus, [Int]) |
This file contains hidden or 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
| Here's a purely-functional take on collecting rolls (no scoring yet) | |
| First a data type to represent the 4 states a frame can be in: | |
| > data Frame = Roll Int | Open Int Int | Spare Int | Strike deriving (Show) | |
| This just simplifies bounds-checks on input roll values: | |
| > badnum :: Int -> Bool | |
| > badnum n = n < 0 || n > 10 |
This file contains hidden or 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 ( transpose ) | |
| import Data.Monoid ( Monoid, mempty, mappend ) | |
| import System.IO ( BufferMode(NoBuffering) | |
| , hSetBuffering, hSetEcho | |
| , stdin, stdout, getChar | |
| ) | |
| import Control.Monad ( forM_ ) | |
| newtype StdVal = StdVal Int deriving (Eq) | |
| type Board a = [[a]] |