Skip to content

Instantly share code, notes, and snippets.

View ivanperez-keera's full-sized avatar
🚀
Exploring

Ivan Perez, PhD ivanperez-keera

🚀
Exploring
View GitHub Profile
@ivanperez-keera
ivanperez-keera / SDLDummyLoop.hs
Last active August 29, 2015 14:07
A dummy loop in SDL
module Main where
import Data.Word (Word32)
import Data.IORef (newIORef, readIORef, writeIORef, IORef)
import Graphics.UI.SDL as SDL
main = withInit [InitEverything] $ do
screen <- setVideoMode 640 480 0 [HWSurface, DoubleBuf] -- , ASyncBlit
-- hello <- loadBMP "hello.bmp"
@ivanperez-keera
ivanperez-keera / XOR.hs
Created February 6, 2015 14:03
XOR two files (Haskell)
import Data.Bits (xor)
import qualified Data.ByteString.Lazy as B
import System.Environment (getArgs)
main :: IO()
main = do
args <- getArgs
if length args < 2
then putStrLn "I need at least two filenames"
else do (b:bs) <- mapM B.readFile args
@ivanperez-keera
ivanperez-keera / verbose-sourcegraph.patch
Created March 31, 2015 11:06
A Patch for Haskell SourceGraph to produce detailed error messages when parsing fails
Only in SourceGraph-mine/: dist
diff -ur SourceGraph-0.7.0.6/Main.hs SourceGraph-mine/Main.hs
--- SourceGraph-0.7.0.6/Main.hs 2015-03-31 11:57:58.753791179 +0100
+++ SourceGraph-mine/Main.hs 2015-03-31 12:04:25.533790366 +0100
@@ -57,6 +57,7 @@
import Control.Arrow(second)
import Control.Monad(liftM)
import Control.Exception(SomeException(..), try)
+import Language.Haskell.Exts(SrcLoc(..))
@ivanperez-keera
ivanperez-keera / shortener.hs
Created April 18, 2015 10:18
Static (read-only) Happstack URL shortening service displaying incorrect behaviour (not refreshing data changed by concurrent connection to mysql)
module Main where
import Control.Concurrent
import Control.Monad
import Control.Monad.Trans
import Database.HDBC
import Database.HDBC.MySQL
import Data.Maybe
import Happstack.Server
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Text as T
@ivanperez-keera
ivanperez-keera / ControlCenter.hs
Last active September 25, 2015 12:03
A Haskell yesod website that reports free disk space and memory
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Applicative
import Control.Arrow
import Control.Concurrent
import Control.Concurrent.MVar
import Control.Exception hiding (Handler)
@ivanperez-keera
ivanperez-keera / AAA-PlaySoundWithSDLMixer.md
Last active November 4, 2015 11:14
Play a sound in SDL-mixer

This is a trivial example that plays a sound in SDL mixer.

It includes arbitrary Template Haskell to check that everything links properly.

Do not copy this to your own project. Use these functions or check out the Haskell Game Programming wiki instead.

@ivanperez-keera
ivanperez-keera / Test.hs
Last active December 2, 2015 16:55
Strange MultiWayIf indentation problem in Haskell
{-# LANGUAGE MultiWayIf #-}
test1 :: Maybe String -> String
test1 x =
case () of
_ | True
-> "Good morning"
test2 :: Maybe String -> String
test2 x =
if | True -> "Good morning"
@ivanperez-keera
ivanperez-keera / SDL.hs
Created April 6, 2017 11:02
Yampa SDL 1.2 Back-end using monadic Signals/Sinks
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module FRP.Yampa.Backends.SDL where
import Data.IORef
import FRP.Yampa.Signal as Yampa
@ivanperez-keera
ivanperez-keera / vi
Created September 17, 2017 01:26
A wrapper around vim to open files in existing vim sessions using ConqueTerm
#!/bin/bash
# matryoshka-vim
# ==============
#
# A wrapper around vim to open files in existing vim sessions using ConqueTerm.
#
# AUTHOR: Ivan Perez Dominguez
# LICENCE: GPL-3
#
@ivanperez-keera
ivanperez-keera / Example.tex
Created October 1, 2017 10:12
Example of haskell code formatted as in "Beautiful code, compelling evidence"
\definecolor{mygreen}{rgb}{0,0.6,0}
\lstset{
commentstyle=\color{mygreen},
keywordstyle=\color{blue}, % keyword style
breaklines=true
}
\begin{minipage}{\linewidth}
\hspace*{.1\linewidth}%
\begin{minipage}{.7\linewidth}
\begin{lstlisting}[frame=l,basicstyle=\small\ttfamily,language=Haskell,