Skip to content

Instantly share code, notes, and snippets.

View v6ak's full-sized avatar

Vít Šesták v6ak

View GitHub Profile
@v6ak
v6ak / add-cropmarkers.scala
Created November 8, 2012 11:31
Skript na přidání ořezových značek v SVG. Hodí se v původním obrázku přesáhnout okraje. Omlouvám se za magické konstanty, někde jsem to kdyi vyčetl a nejsem tiskař (a bohužel jsem si to nepoznamenal).
import xml._
trait Rect[+T]{
def x: T
def y: T
def fun(name: String) = name+"("+x+","+y+")"
}
final case class OrientedRect[+T](vertical: T, horizontal: T) extends Rect[T]{
def width = horizontal
def height = vertical
@v6ak
v6ak / ts-finished
Last active April 15, 2025 12:11
A handler for Task spooler
#!/bin/bash
# Copyright (C) 2012 Vít Šesták <v6ak.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
# This utility notifies about completed messages of Task spooler (see http://viric.name/soft/ts/).
# Just add the path to this utility to $TS_ONFINISH.
@v6ak
v6ak / HelloWorld.java
Last active December 15, 2015 22:19
How many method calls are done during a simple Java HelloWorld console application?
package com.v6ak;
public class HelloWorld{
public static void main(String[] args) throws InterruptedException, ClassNotFoundException{
System.out.println("Hello world");
}
}
@v6ak
v6ak / short.scala
Created April 8, 2013 07:51
Trigram frequencies in Scala. Can you make it even shorted?
io.Source.fromFile("/tmp/text").mkString.split("""[\?\.\!",\- \s]+""").sliding(3).toSeq.groupBy(_.toSeq).toSeq.map{x=>x._2.size->x._1.mkString(" ")}.sorted.reverse
case object BoolType extends Type with StandardType{
def getCommonSuperType(other: Type) = other match {
case BoolType => BoolType
case _ => combineWith(other)
}
def getSimpleStringRepresentation = "Boolean"
def getClasses = Nil
}
@v6ak
v6ak / tabsmell
Last active December 17, 2015 17:19
#!/bin/bash
# Copyright © 2013 Vít Šesták <http://contact.v6ak.com>
# This work is free. It comes without any warranty, to the extent
# permitted by applicable law. You can redistribute it and/or modify it
# under the terms of the Do What The Fuck You Want To Public License,
# Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for
# more details.
########################################################################
# Looks for bad usage of tab characters.
#
// Prakticky neupravená verze. (Stejná logika jako původní Javový kód, proto imperativní.)
def partitionBy[T, K](inputList: Iterable[T], partitionFunc: T=>K) = {
val multimap = HashMultimap[K, T]()
for (t <- inputList) {
multimap(partitionFunc(t)) = t
}
multimap
}
// Funkcionální verze
@v6ak
v6ak / gist:5704291
Last active December 18, 2015 01:29 — forked from rarous/gist:5686814
public OrderableService GetById(int id)
{
return (
from service in SourceSet
where service.ID == id
select service
).FirstOrDefault();
}
@v6ak
v6ak / gist:6022072
Last active December 19, 2015 21:39
trait ICalculatingStrategy {
def calculate(a: Int, b: Int): Int
}
object AdderStrategy extends ICalculatingStrategy{
override def calculate(a: Int, b: Int) = a + b
}
object MultiplierStrategy extends ICalculatingStrategy{
override def calculate(a: Int, b: Int) = a * b
val CalculatingOperations = Map[String, (Int, Int)=>Int](
"add" -> (_+_),
"multiply" -> (_*_)
)
CalculatingOperations("multiply")(3, 2)