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 / Lib.hs
Created January 15, 2017 12:30
Free error when building x
{-# LANGUAGE QuasiQuotes #-}
module Lib where
import NeatInterpolation
renderXmlRequest = [text|apple|]
@robinp
robinp / save-screen-to-gif.sh
Created August 29, 2016 17:54
How to save a screen region to gif.
# Need to install ffcast, and advisedly also xrectsel (on arch can do from AUR)
# Below command will let you select a region with the mouse, than stream it to ffmpeg.
# Many args magic (taken from SO), but allegedly it saves as lossless.
ffcast -s % ffmpeg -f x11grab -show_region 1 -framerate 20 -video_size %s -i %D+%c -codec:v huffyuv -vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" out.avi
# Use ImageMagick to covert to gif - works great!
convert -set delay 5 -layers Optimize out.avi out.gif
@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)