Skip to content

Instantly share code, notes, and snippets.

View 3noch's full-sized avatar
🕯️

Elliot Cameron 3noch

🕯️
  • Indiana
View GitHub Profile
import Shelly
import Prelude hiding (FilePath)
sudo_ com args = run_ "sudo" (com:args)
main = shelly $ verbosely $ do
apt_get "update" []
apt_get "install" ["haskell-platform"]
where
apt_get mode more = sudo_ "apt-get" (["-y", "-q", mode] ++ more)
@3noch
3noch / gist:2354444
Created April 10, 2012 21:01
Palindrome Checker in Haskell
import Data.Char
import IO
main = do
fileName <- putStr "Enter the name of the file: " >> getLine
contents <- readFile fileName
mapM_ printOutput (lines contents)
where
getOutputMessage line = line ++ if isPalindrome line
then " is a palindrome!"
@3noch
3noch / Either.h
Last active July 9, 2020 15:27
An implementation of Haskell's "Either" type C++
#pragma once
#include <boost/optional.hpp>
/**
* Wraps any value with a context of Left for the Either class.
*
* By convention, Left represents some sort of less-desired condition.
*/
@3noch
3noch / align.hs
Last active January 3, 2016 11:48
Aligns a "|" delimited file
module Main where
import Data.Functor ((<$>))
import Data.List (intercalate, transpose)
import Data.List.Split (splitOn)
(<$$>) = fmap . fmap
main = interact $ unlines . (intercalate "|" <$>) . go . (splitOn "|" <$>) . lines
where
def match(fns):
def inner(x):
for cls, fn in fns:
if isinstance(x, cls):
return fn(x)
return inner
doformat = match(
[ (Literal, lambda x: x)
module Rules where
Schema ( "time" =: timestamp
, "enabled" =: bool )
data Value = VInt Int
| VString String
| VBool Bool
| VList [Value]
| VSchema [(String, Value)]
@3noch
3noch / Main.hs
Created August 20, 2014 18:19
TMQueue vs Chan
module Main where
import Control.Applicative
import Control.Concurrent (yield)
import Control.Concurrent.Async
import Control.Concurrent.Chan
import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TMQueue
import Control.Monad (replicateM, forM_, forever)
import Data.Function (fix)
@3noch
3noch / Boxed.h
Last active August 29, 2015 14:06
Boxed
#pragma once
#include <cassert>
#include <memory>
/*
* A non-null shared pointer to some value (i.e. a shared reference).
*
@3noch
3noch / Atomic.hpp
Last active August 29, 2015 14:21
Atomic Variables in C++ (akin to Haskell's MVar)
#pragma once
#include <memory>
#include <boost/thread.hpp>
#include <boost/utility.hpp>
#include <CeFunctional.h>
#include <CeMemory.h>
#include <FunctionObject.h>
@3noch
3noch / alliteration.irclog
Last active August 29, 2015 14:21
Alliteration
(8:51:32 AM) matt_ribeiro: elliot1: I don't think we met, and have you seen elliot?
(8:54:01 AM) jared_burkeen: matt_ribeiro, check your email, elliot1 is a new hire that started this week
(8:54:10 AM) jared_burkeen: he's the anti-haskell elliot
(8:55:55 AM) matt_ribeiro: oh then.... PLEASED to meet you. :-)
(8:57:36 AM) jared_burkeen: he will greet you in return, he's just a little shy
(9:02:16 AM) matt_ribeiro: Unfortunately, I ran into some haskell woes last night, so I really need elliot, instead of elliot1.
(9:10:27 AM) jared_burkeen: I think he's off today
(9:10:31 AM) jared_burkeen: no that was yesterday
(9:10:41 AM) jared_burkeen: but it's usually tomorrow that he's off
(9:14:08 AM) matt_ribeiro: If yesterday was tomorrow, what does that make today?