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 / 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
@robinp
robinp / Poller.cpp
Created January 7, 2011 16:08
jzmq-crash
/*
Copyright (c) 2007-2010 iMatix Corporation
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the Lesser GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@robinp
robinp / Main.java
Created January 7, 2011 18:31
jzmq bug reproduce
package zmqbugtest;
import org.zeromq.ZMQ;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
@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 / IOTesting.scala
Created May 16, 2012 11:00
How to close safely using Scalaz IO
import java.io.{IOException, InputStream, OutputStream}
import org.mockito.Mockito
import scalaz._
import Scalaz._
import scalaz.effects._
trait Closable[A] {
def close(a: A): IO[Unit]
def closeOrKeep(a: A): IO[Option[A]] =
@robinp
robinp / Futureapplicative.scala
Created June 27, 2012 18:03
Akka Future Applicative typeclass for scalaz-seven
package akkaz
import akka.actor._
import akka.util.duration._
import akka.util.Timeout
import akka.dispatch.{ExecutionContext, Future}
object Futureapplicative extends App {
val system = ActorSystem("Futureapplicative")
@robinp
robinp / rc.local
Created July 10, 2012 19:34
Ubuntu 12.04 for Acer Aspire TimelineX 5820TG
# for SSD
echo deadline > /sys/block/sda/queue/scheduler
echo 0 > /proc/sys/vm/swappiness
# turn off Radeon by default so it doesn't consume battery
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
# turn off bluetooth by default
rfkill block bluetooth
@robinp
robinp / Bakery1.java
Created July 27, 2012 08:31
bakery model using template method
abstract class Bakery1 {
public void produceBread() {
Ingredients ingredients = prepareIngredients();
Bread bread = bakeTheBread(ingredients);
if (checkQuality(bread)) {
putBreadOnDisplay(bread);
}
}
@robinp
robinp / PostprocessingBakery1.java
Created July 27, 2012 08:50
complex bakery model using template methods
abstract class PosprocessingBakery1 {
public void produceBread() {
Ingredients ingredients = prepareIngredients();
Bread bread = bakeTheBread(ingredients);
if (checkQuality(bread)) {
putBreadOnDisplay(postprocess(bread));
}
}
@robinp
robinp / Bakery2.java
Created July 27, 2012 08:37
bakery model using injection
interface BakeBreadStrategy {
Bread bake(Ingredients ingredients);
}
class Bakery2 {
public Bakery2(BakeBreadStrategy bakeStrategy) {
// ...
}