Samstag, 26. Juli 2014

Coffee machine code kata

Code a bean-to-cup coffee machine. You can decide how much capacity the watertank has and how much half a cup / a cup is. (Aside: Why? Because I've always wanted to do it.)

Lights 

  • brewing
  • heating up
  • clean waste container
  • refill water
  • no beans

Featues (grinding + brewing = duration until cup is finished)

  • grinding (how much coffee)
    • strong: 7 seconds
    • normal: 5 seconds
    • mild: 3 seconds
  • brew half a cup, 15 seconds
  • brew a cup, 30 seconds
  • hot steam to preheat cups (blocks brewing and visa versa)

Buttons

  • on / off (starts heating, heating always takes 20 seconds)
  • half a cup / cup (default: half a cup)
  • grinding
    • pressed once: thin
    • pressed twice: normal (default)
    • pressed thrice: strong
  • steam
  • start
So if you turn it on and the heating light shows that it's heated up and you press the start button it would brew half a cup normal coffee. It would take: 20 seconds (heatup) + 5 seconds (grinding) + 15 seconds (brewing) = 40 seconds.


Imagine it as something like the thing shown below:



If you like to improve this kata, fork it on github and make a pullrequest.

Mittwoch, 20. März 2013

Query wordpress posts by id and return array of entire post objects

Caused me some headache. I had to query posts inside a wordpress extension by their id and return an array of the corresponding post objects. At the moment this is the best solution I found for the problem, even if the code doesn't clearly state what I am doing:

    query_posts(array('post__in' => $this->postids, 'post_type'=> ''));
    $posts = array();

    while (have_posts()) {
        the_post();
        $posts[] = get_post(get_the_ID());
    }

    wp_reset_query();
    return $posts;

So first we query the posts by id. Then we start with the loop and use get_post() to get the post. get_post() sadly doesn't return the current post by default, so we have to pass it the id of the current post (this is so stupid). Once we pass the id it returns a post object which we store inside the $posts array which is returned at the end of the method.

Check http://codex.wordpress.org/Function_Reference/get_post, you might also return the posts as an numeric / associative array instead of an object if you like.


Donnerstag, 20. Dezember 2012

Number of pages inside a pdf

$ grep -o "'Page[0-9]*'" your.pdf | tail -1 | grep -o "[0-9]*"

Freitag, 9. November 2012

wildcard && brace expansion -eq <3

mplayer *s05e0{1,2,3}*

Queues the following files:
xyz.s05e01.someformat
abc.s05e02.someotherformat
123.s05e03.format
...

Check http://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html

Montag, 22. Oktober 2012

undefined symbol: apr_reslist_maintain after upgrading httpd on Slackware 13.37

After upgrading apache to the latest patch (ftp://ftp.slackware.com/pub/slackware/slackware-13.37/patches/packages/) you get that error: "/usr/sbin/httpd: symbol lookup error: /usr/sbin/httpd: undefined symbol: apr_reslist_maintain" when starting httpd / apache.

In order to resolve it you have to update apr (Apache Portable Runtime, makes sense, huh? ;)) and apr-util to the latest patched versions (get them here ftp://ftp.slackware.com/pub/slackware/slackware-13.37/patches/packages/).

Donnerstag, 18. Oktober 2012

Dienstag, 25. September 2012

Show single image with xlock

Took me a while to figure out how to simply show an image when locking with xlock:

$ xlock -mode image -bitmap image.xpm -count 1

-mode image: sets the mode to only display random sun images
-bitmap image.xpm: replace the random sun images with image.xpm (*)
-count 1: sets the amount of images that shall be shown at the screen at once to 1

* use ImageMagicks 'convert' method to convert to xpm: $ convert input.jpg output.xpm

Have fun!