Skip to content

Instantly share code, notes, and snippets.

-- 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)
@caiorss
caiorss / recvLn.hs
Last active August 29, 2015 14:23 — forked from crabmusket/recvLn.hs
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
-- 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 {
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
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\")"
;; Scratch
;; This program helps keep a record of ideas.
;; Last edit: 2012-07-05
;; Every time (scratch) is called a new buffer is opened. Title
;; is today's date appended before a user inputed title.
;Needed features
;* An interactive shell that shows me a list of entries
; from a certain time period.
(defun local-path (path)
"Return the local portion of a path.
If PATH is local, return it unaltered.
If PATH is remote, return the remote diretory portion of the path."
(if (tramp-tramp-file-p path)
(elt (tramp-dissect-file-name path) 3)
path))
(defun python-find-python-command (&optional root)
;;; how to use
;; (add-hook 'html-mode-hook 'django-kyr-tag-mode)
;;(util-macro-install "dkt:")
;;; how to use
;; (add-hook 'html-mode-hook 'django-kyr-tag-mode)
;;(util-macro-install "dkt:")
(eval-when-compile (require 'cl))
@caiorss
caiorss / run-python.el
Last active August 29, 2015 14:24 — forked from ieure/run-python.el
(defun python-find-python-command (&optional root)
"Return the python interpreter to use for ROOT."
(let ((env-root (local-path
(locate-dominating-file
(or root default-directory) "bin/python"))))
(or (when env-root (concat env-root "bin/python"))
python-python-command)))
(defun python-find-project-root (&optional start)
;; This macro creates new compilation commands
(defmacro ff/add-compilation-command (name &optional key)
(let ((buffer-name (concat "*" name "*"))
(compile-symbol (intern name))
(recompile-symbol (intern (concat "re" name))))
(when (fboundp compile-symbol)
(warn "redefining command `%s'" name))
(when (fboundp recompile-symbol)
(warn "redefining command `re%s'" name))
`(progn