Skip to content

Instantly share code, notes, and snippets.

View robinp's full-sized avatar

Robin Palotai robinp

  • Budapest, Hungary
View GitHub Profile
@robinp
robinp / Lista.hs
Last active August 16, 2016 20:15
data Lista = Megtobb Int Lista | Vege
uresLista :: Lista
uresLista = Vege
egyKetHa :: Lista
egyKetHa = Megtobb 1 (Megtobb 2 (Megtobb 3 Vege))
hossz :: Lista -> Int
hossz Vege = 0
@robinp
robinp / FreeNotAsInBeer.hs
Created February 2, 2016 11:32
Example for writing a small interpreted language using Free monads
{-
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@robinp
robinp / smaller.sh
Created September 29, 2015 10:01
Convert color image pdf to black and white pdf.
#!/bin/bash
INPDF=$1
OUTDIR=$2
ROT=$3
CONVOPTS=$4
INBASE=$(basename ${INPDF} .pdf)
TMP=$(mktemp -d)
pdfimages -j ${INPDF} ${TMP}/${INBASE} # emits ppm,pbm or jpg
for i in $(ls ${TMP}/${INBASE}-*.*)
do
@robinp
robinp / CountHunText.hs
Last active August 29, 2015 14:09
Throw-away script for text stats for rows where the rightmost column contains Hungarian text.
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import qualified Data.ByteString.Lazy as BL
import Data.Csv
import Data.Char (ord)
import Data.Monoid
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.Foldable (foldMap)
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.Encoding as T
function initGL() {
var canvas = document.getElementById("canvas");
canvas.width = 320;
canvas.height = 480;
gl = canvas.getContext('experimental-webgl');
gl.disable(gl.DEPTH_TEST);
gl.clearColor(0.5, 0.5, 0.5, 1.0);
var vs = "attribute vec2 a_position;";
vs += "uniform vec2 u_resolution;";
isBlank x = ' ' == x
f (lastBlank, res) ch =
if isBlank ch
then (True, if lastBlank then res else ' ':res)
else (False, ch:res)
g s = reverse $ snd $ foldl f (False, []) s
main = print $ g "x y zzz ff dd e"
@robinp
robinp / FirstWhereM.hs
Created February 11, 2013 15:21
Playing around with flattening nested if-then-else
module Main where
import System.FilePath
import System.Directory
main = firstWhereM check ["a", "x", "b"] >>= print
where check = doesFileExist . (</>"z"</>"y")
firstWhereM :: (Monad m) => (a -> m Bool) -> [a] -> m (Maybe a)
firstWhereM pred ins = case ins of
@robinp
robinp / Stomp.hs
Created February 11, 2013 15:08
Stomp request sending to HornetQ (error handling might be incomplete in timeoutE, todo)
import Network
import System.IO
import Data.Char (chr, ord)
import Control.Exception (IOException)
import Control.Concurrent (forkIO, threadDelay, killThread)
import Control.Concurrent.MVar
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Either
import Control.Monad (liftM)
@robinp
robinp / Main.hs
Last active December 12, 2015 06:39
do-notation works for Fay
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE CPP #-}
module Main where
import Prelude
#ifndef FAY
-- Fake stuff for RebindableSyntax
@robinp
robinp / ManualLens.hs
Created January 31, 2013 13:49
Constructing lens manually
{-# LANGUAGE ExistentialQuantification, Rank2Types #-}
import Control.Monad.Identity
import qualified Control.Monad.State as S
-- with guidance from http://hackage.haskell.org/package/lens "Minimizing dependencies"
type Lens c d a b = forall f . (Functor f) => (a -> f b) -> c -> f d
get :: c -> Lens c d a () -> a