Search This Blog

Posts

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) {
//..do work...
processed += 1
listener.progressChanged(100.0 * processed / items.size)
}
}
trait Listener {
def progre…

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):

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?…