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 Numeric.LinearAlgebra | |
import Control.Monad (replicateM) | |
import System.Random (randomIO) | |
import Graphics.Gnuplot.Simple (plotFunc) | |
-- Test 100 random lines for convexity. | |
main = replicateM 100 $ do | |
-- Two 5x5 symmetric positive definite matrices that determine the line. | |
a <- randomSnPD 5 | |
v <- randomSnPD 5 |
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
module Numeric.Units.Dimensional.ConstantArithmetic where | |
import qualified Prelude | |
import qualified Numeric.Units.Dimensional | |
import Numeric.Units.Dimensional.Prelude | |
a *. b = a * (b *~ one) | |
a .* b = (a *~ one) * b | |
a .*. b = (a *~ one) * (b *~ one) |
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 qualified Data.ByteString.Char8 as B | |
import Criterion.Main | |
import Data.IORef | |
import Data.Vector | |
import Data.ByteString.Char8 (ByteString) | |
import Control.Monad (forever) | |
import Pipes | |
import qualified Pipes.Prelude as P | |
import Data.Char (intToDigit) | |
import qualified Data.ByteString.Builder as Builder |
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 qualified Data.ByteString.Char8 as B | |
import System.Hardware.Serialport (SerialPort, recv) | |
recvLn :: SerialPort -> IO B.ByteString | |
recvLn s = do | |
-- Receive one byte at a time. | |
first <- recv s 1 | |
rest <- if first == B.singleton '\n' | |
then return $ B.empty | |
else recvLn s |
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
-- Imports for serial port | |
import qualified Data.ByteString.Char8 as B | |
import System.Hardware.Serialport | |
(openSerial, recv, closeSerial, defaultSerialSettings) | |
-- Imports for threading and stuff | |
import Control.Monad (void, forever, mapM_) | |
import Control.Concurrent (forkIO, killThread) | |
import Control.Concurrent.Chan | |
(Chan, newChan, dupChan, writeChan, getChanContents) |
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.Monad (forever) | |
import Control.Concurrent (forkIO, killThread) | |
import qualified Data.ByteString.Char8 as B | |
import System.Hardware.Serialport | |
(openSerial, recv, closeSerial, defaultSerialSettings) | |
port = "COM1" -- Windows | |
--port = "/dev/ttyUSB0" -- Unix | |
main = do |
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
-- http://hackage.haskell.org/package/atom | |
-- http://hackage.haskell.org/package/atom-msp430 | |
module Main where | |
import Data.Word | |
import Data.Bits | |
import Language.Atom.MSP430 | |
main = mspCompile "g2231" $ mspProgram { |
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
module Main where | |
import Control.Monad (liftM) | |
import Numeric.LinearAlgebra (readMatrix, multiply, rank, cols, rows, fromBlocks) | |
main = do | |
putStrLn "Enter matrix A (in format \"1 2 3; 4 5 6; 7 8 9\")" | |
a <- getMatrix | |
putStrLn "Enter matrix B (in format \"1; 2; 3\")" |
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
module Main where | |
import Filesystem (getWorkingDirectory) | |
import Filesystem.Path (extensions) | |
import System.FSNotify | |
import System.Exit | |
import System.Environment | |
import System.Cmd | |
import Control.Concurrent | |
import Control.Monad |
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
module Main where | |
import Graphics.Gnuplot.Simple | |
-- Calculates the scaling factor for an object at distance 'dist'. The object | |
-- will be at scale 1 until 'max'/2, and then will be exponentially scaled down | |
-- as it increases. As 'dist' approaches infinity, 'dist * factor max dist' | |
-- approaches 'max'. See http://goo.gl/xLzrv | |
factor max dist = if dist < max / 2 | |
then 1 | |
else (1 - 1 / 2**(f+1)) / f |