Skip to main content


Showing posts from September, 2012

RateLimiter - discovering Google Guava

RateLimiter class was recently added to Guava libraries (since 13.0) and it is already among my favourite tools. Have a look what the JavaDoc says:
[...] rate limiter distributes permits at a configurable rate. Each acquire() blocks if necessary until a permit is available [...] Rate limiters are often used to restrict the rate at which some physical or logical resource is accessed Basically this small utility class can be used e.g. to limit the number of requests per second your API wishes to handle or to throttle your own client code, avoiding denial of service of someone else's API if we are hitting it too often.
Let's start from a simple example. Say we have a long running process that needs to broadcast its progress to supplied listener:
def longRunning(listener: Listener) { var processed = 0 for(item <- items) { // work... processed += 1 listener.progressChanged(100.0 * processed / items.size) } } trait Listener { def progre…

Confitura 2012 - podziękowanie i uwagi

As an exception, this article is written in Polish as it is related to my talk at Confitura 2012 conference in Warsaw. It was chosen second best talk according to attendees votes - I would like to thank for that and relate to some of the comments. Kilka miesięcy temu miałem ogromną przyjemność poprowadzić wykład "Uwolnić się od if" podczas Confitury 2012. Frekwencja na mojej prezentacji w szacownych murach Uniwersytetu Warszawskiego oraz jej pozytywne przyjęcie były dla mnie ogromnym zaskoczeniem. Nagranie dostępne jest poniżej (oraz na Parleys ze slajdami):

Jeszcze większym zaskoczeniem były wyniki pokonferencyjnej ankiety. Jak się okazuje, w oczach uczestników, lepsza od mojej prezentacji okazała się jedynie ta prowadzona przez Sławomira Sobótkę - gratulacje dla niego za znakomity wykład i zasłużone zwycięstwo! Tak prezentuje się podium:
4,55: Ścisły przewodnik po aspektach miękkich dla ekspertów IT - Sławomir Sobótka4,22: Uwolnić się od "if" - Tomasz Nurkiewicz4…

Accessing clipboard in Linux terminal

On a day-to-day basis I am using Ubuntu, which means constantly switching between terminal window and ordinary graphical application like IDE, editors, etc. Often I need to copy a bit of text from IDE to terminal or back. At least in Ubuntu using inconsistent Ctrl + Shift + C (or V) key combination and mouse to select area in terminal is a bit painful. Life would be so much simpler if there was a command line utility to print current clipboard contents to standard terminal output and a second one to take standard input and put it into the clipboard. Life can be much simpler, have a look at xclip!
Without diving into details, start by defining the following aliases in your system (put them in ~/.bash_aliases right now, you'll love them):
alias ctrlc='xclip -selection c' alias ctrlv='xclip -selection c -o' ctrlc and ctrlv, sounds familiar? Of course aliases are completely arbitrary. Now run any bash command but pipe its output to ctrlc:
$ ps | ctrlc Nothing happened?…