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.Function ((&)) | |
| -------------------------------------------------------------------------------- | |
| import qualified Data.List as List | |
| -------------------------------------------------------------------------------- | |
| main :: IO () | |
| main = | |
| [3, 1, 4, 1, 5, 9, 2, 6, 5, 3] & quickSort & show & putStrLn | |
| -- | FP implementation of QuickSort. Intended as an exercise in a high-level |
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
| -------------------------------------------------------------------------------- | |
| {-# LANGUAGE NamedFieldPuns #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| -------------------------------------------------------------------------------- | |
| module Main | |
| ( main | |
| ) where | |
| -------------------------------------------------------------------------------- | |
| import qualified Control.Concurrent as Concurrent | |
| import qualified Control.Concurrent.Async as Async |
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
| ;; Rewriting the example of a Finite State Machine using Clojure and | |
| ;; Haskell-inspired type annotations. Why mix the two languages? Firstly, I like | |
| ;; LISPs. Secondly, Haskell type-annotations help me organize my thoughts. | |
| ;; | |
| ;; This example was sourced from page 91 of Game Programming Patterns by Robert | |
| ;; Nystrom. | |
| ;; type State = Ducking | |
| ;; | Standing | |
| ;; | Jumping |
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
| (|>) :: a -> (a -> b) -> b | |
| (|>) x f = f x | |
| m n | |
| | n > 100 = n - 10 | |
| | n <= 100 = n + 11 |> m |> m | |
| main = do | |
| m 101 |> show |> putStrLn | |
| m 102 |> show |> putStrLn |
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
| ;; This macro hopefully provides a more ergonomic way to add mode-specific hooks before buffer save events. | |
| ;; | |
| ;; In ELisp you might see docs that tell you to write the following: | |
| ;; (add-hook 'reason-mode-hook (lambda () (add-hook 'before-save-hook #'refmt-before-save))) | |
| ;; | |
| ;; Instead of writing this, use this macro to write: | |
| ;; (add-hook-before-save 'reason-mode-hook #'refmt-before-save) | |
| (defmacro add-hook-before-save | |
| (mode f) |
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
| ################################################################################ | |
| # 8-bit colors | |
| ################################################################################ | |
| black='\u001b[30m' | |
| red='\u001b[31m' | |
| green='\u001b[32m' | |
| yellow='\u001b[33m' | |
| blue='\u001b[34m' | |
| magenta='\u001b[35m' |
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
| runc() { | |
| # Compile and run $1. Pass $1 as file.c. | |
| # This is modelled after the `runhaskell` command. | |
| # Deletes the compiled binary after executing it. | |
| # | |
| # depends gcc | |
| gcc "$1" -o "${1%.c}" && "./${1%.c}" && rm "${1%.c}" | |
| } |
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
| runrust() { | |
| # Compile and run $1. Pass $1 as file.rs. | |
| # This is modelled after the `runhaskell` command. | |
| # Deletes the compiled binary after executing it. | |
| # | |
| # depends rustc | |
| rustc "$1" && "./${1%.rs}" && rm "${1%.rs}" | |
| } |
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 python3 | |
| import random | |
| sample_size = 9000000 | |
| numbers = list(range(0, 10000000)) | |
| random.shuffle(numbers) | |
| with open('numbers.txt', 'w') as f: | |
| for i in numbers[0:sample_size]: | |
| print('{}'.format(i)) |
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
| // Example implementation of a vector rotation from the book, "Programming Pearls". | |
| // | |
| // The algorithm can be explained using your hands: | |
| // | |
| // +----------------+---------------+---------------+---------------+ | |
| // | Stack left over| Flip left hand| Flip right | Turn both | | |
| // | right with | over. | hand over. | hands over | | |
| // | palms facing | | | right-over- | | |
| // | towards you | | | left. | | |
| // +----------------+---------------+---------------+---------------+ |