WP Meetups

Share on Facebook0Share on LinkedIn0Tweet about this on Twitter

A few months back I noticed we actually have regular WordPress Meetups in Ljubljana, our base town. We attended one in April, where David talked about theming and Emanuel about bringing WordPress into the Public Sector. On the second one, in June, we were active participants: Janez and myself delivered a talk titled Lessons learned running 25k WordPress blogs describing how we scaled Easy Blog Networks to 25k blogs running on several hundred servers.

Both events also had a Lightning Talks section, which is what I normally enjoy the most. So many great ideas packed into such a short timeframe. Looking forward to the next meetup that should happen sometime in Autumn!

img_8157 img_7930 img_7932vlcsnap-2016-09-11-11h59m58s941

Share on Facebook0Share on LinkedIn0Tweet about this on Twitter

Lessons learned from EuroPython 2016

Share on Facebook1Share on LinkedIn0Tweet about this on Twitter

This was my first EuroPython conference and I had high expectations because I heard a lot of good things about it. I must say that overall it didn’t let me down. I learned several new things and met a lot of new people. So lets dive straight into the most important lessons.

On Tuesday I attended “Effective Python for High-Performance Parallel Computing” training session by Michael McKerns. This was by far my favorite training session and I have learned a lot from it. Before Michael started with code examples and code analysis he emphasized two things:

  1. Do not assume what you hear/read/think. Time it and measure it.
  2. Stupid code is fast! Intelligent code is slow!

At this point I knew that the session is going to be amazing. He gave us a github link (https://github.com/mmckerns/tuthpc) where all examples with profiler results were located. He stressed out that we shouldn’t believe him and that we should test them ourselves (lesson #1).

I strongly suggest to clone his github repo (https://github.com/mmckerns/tuthpc) and test those examples yourself. Here are my quick notes (TL; DR):

  • always compile regular expressions
  • use local variables (true = True, local = GLOBAL)
  • if you know how many elements it will be in your list, create it with None elements and then fill it (L = [None] * N)
  • when inserting item on 0 index in a list use append then reverse (O(n) vs O(1))
  • use built-in functions, use built-in functions, use built-in functions!!! (they are written in C layer)
  • when extending list use .extend() and not +
  • searching in set (hash map) is a lot faster then searching in list (O(1) vs O(n))
  • constructing set is much slower then list so you usually don’t want to transform list into set and then search in it because it will be slower. But again you should test it
  • += doesn’t create new instance of an object so use this in loops
  • list comprehension is better than generator. for loop is better then generator and sometimes also than list comprehension (you should test it!)
  • importing is expensive (e.g. numpy is 0.1 sec)
  • switching between python arrays and numpy arrays is very expensive
  • if you start writing intelligente and complex code you should stop and rethink if there is more stupid way of achieving your goal (see lesson #2)
  • optimize the code you want to run in parallel. This is more important than to just run it in parallel.

Threading and multiprocessing:

  • you should always run analysis if/when threading/multiprocessing is faster. If you are using simple functions it will probably be slower
  • in parallel computing you need to catch and log errors
  • in parallel computing you always want your functions to return value
  • in parallel computing you never want your code to “die”. Always try to return reasonable default value even if an exception is raised. Slightly wrong is better than not getting an answer!
  • when using threading/multiprocessing use .map() and if you don’t care about the order use .imap_unordered(). It is the fastest because it returns the first available value.
  • if you have stop condition use .imap_unordered()
  • be aware of random module problems. Random seed gets copied to all processes. Result is “random doesn’t work”. You need to create random_seed function and ensure that you are in different random state.
  • is there any general rule when to use threads and when multiprocessing? Use threads if you have light jobs (i.e. they execute in 0-1 sec)

Another interesting talk was about code review (Another pair of eyes: Reviewing code well by Adam Dangoor). He pointed out that one of the most important things with the process of reviewing the code is to share knowledge. When you review others code you learn a lot especially if you take your time and try to really understand what he/she was trying to achieve. It is also recommended to always say something nice about the code especially when reviewing the code of junior developer. And when you think that the code you are reviewing has a bug, write a test that proves it.

EuroPython 2016 was really an amazing experience that every Python developer/scientist should experience. I’m really looking forward to EuroPython 2017!

Share on Facebook1Share on LinkedIn0Tweet about this on Twitter

Y U NO USE CLIPBOARD MANAGER??!??!11?!oneone

Share on Facebook6Share on LinkedIn0Tweet about this on Twitter

Every time when I am in a pair-programming session and the other person does not use a clipboard manager I am taken aback at how such a thing is even possible. To me, a clipboard manager is such an essential piece of toolkit that I forget it’s there.

What is a clipboard manager? In its simplest form it’s a history of the things you copied. For example, you select text “Foo”, press Ctrl+C (Cmd+C on a Mac), then repeat the same on text “Bar”. The clipboard manager will keep both “Foo” and “Bar” values handy for use when needed.

Screen Shot 2016-06-21 at 23.15.17

My entire clipboard history, searchable, just one keypress away. Priceless.

Simple as that. And so, so effective! Every time you need to copy many things from one window to another, select and copy them one by one, go to the other window, paste them one by one. You save a ton of window switching and clicking around! Good clipboard managers support searching through the history of things you copied and they are smart about the type of content you copied, such as plain text, URLs, images, etc. There are many more reasons why using a clipboard manager makes your day easier.

Personally, I use the clipboard manager that comes with Alfred, the OS X productivity app. But there are literally hundreds of clipboard managers out there, for all major OSes and most of them do their job just fine. Choosing one is mostly about personal preference on keyboard for keyboard shortcuts and styling.

So, what are you waiting for? Get one!

 

Share on Facebook6Share on LinkedIn0Tweet about this on Twitter

Dear Plone, welcome to year 2014

Share on Facebook0Share on LinkedIn0Tweet about this on Twitter

TL;DR: Production-level Plone on free-tier Heroku: https://github.com/niteoweb/heroku-buildpack-plone

First, a bit of history: it was year 2006 and I was realizing that I was not made to be an academic. I made my first strides into entrepreneurship and being in IT, the first logical step was to create a few websites and try to get paid for my work. I did have some programming experience but haven’t done any web development yet. I heard PHP was not the ideal solution so I started looking elsewhere. In my student association I heard about this Plone thingy and gave it a go: I purchased a 20€ per month shared Plone hosting account at Nidelven IT and started hacking. It was the Plone 2.x era and boy was I productive! I threw in content, installed a ready-made theme and did some TTW tweaks. Done! First customer happy! Rinse & repeat, upgrade to a beefier server, rinse & repeat. NiteoWeb Ltd. was born.

Fast forward to a couple of months ago: we used GeckoBoard to drive a wall-mounted dashboard display. GeckoBoard works fine, but they want almost $60 per month if you want to drive more than one display. Sounds quite expensive for a bit of HTML and JavaScript, doesn’t it? So I looked around for alternatives and one of them was the Dashing dashboard from Spotify. I was reluctant to even give it a try as it was a self-hosted Ruby app. And I didn’t know *any* Ruby. But there, in their documentation, I found a short guide on how to deploy your very own version of a sample dashbord to your personal Heroku account. And when I say short, I mean short! I copy/pasted 6 simple commands into my console and that was it! My very own dashboard! After it was running I was motivated enough to read through Dashing’s docs and did a few minor tweaks. One “git push heroku master” later, my changes were again deployed to Heroku and showing up on my dashboard display. Wow, is this developer-friendly or what!

My mind drifted and I thought: Boy wouldn’t it be nice if a non-Plone person could come to a Plone add-on page and create their very own Plone instance with the add-on installed, and they could immediately start using it. Uhm … why not? Why don’t we, as a community, provide “private” demos that people can use? Is there something that prevents us from using Heroku for demos, the same was as Dashing, and many other Ruby products, use it?

Turns out, there isn’t. During the Plone dinner at EuroPython 2014 conference last week, I ordered a few beers and got hacking. Goal: get Plone to run on a free-tier Heroku account.

There have been attempts to run Plone on Heroku before, but they failed because they took the wrong approach. Look, Heroku, by default, supports Python apps that are installed with “pip“. Previous attempts were all focused on fixing Plone so it could be installed with pip. And they failed, Plone’s ecosystem is just too complex.

I decided to take a different approach: buildpacks. Heroku allows you to build *anything* on it. So I created a buildpack that supports zc.buildout. Once I got that done, it was not far from getting Plone installed on Heroku.

The next roadblock came in the form of Heroku’s ephemeral filesystem. Everytime your Heroku “dyno” is restarted, the filesystem is recreated. And you lose your Data.fs. Humpff. Wait, but what about the PostgreSQL that Heroku offers? A production-quality PostgreSQL, for free, with a 10k row limit. That could work! So, add in support for RelStorage and you have a production-ready Plone site running on Heroku. For free. And you are not limited to one, you can have as many as you wish, on the same account. Heroku really is awesome!

So, Plone is suddenly again a viable option for college dropouts starting their businesses! No need for system administration knowledge, how to setup Nginx in front of Plone, how to do proper backups, just a few command-line commands and your site is online!

And, our add-ons can now have demos. If you use Data.fs instead of PostgreSQL, the demo instance’s data will be recreated at least once per day, giving visitors an up-to-date demo instance, displaying what your Plone add-on does and how it looks.

Does this really works? Hell yeah it does! This blog has been running on Heroku since last week! And here’s a Plone 4.3 demo, a Plone 5 demo and a collective.cover demo. Wanna see plone.app.mosaic in action?

Why doesn’t your add-on have a demo yet? Follow instructions on https://github.com/niteoweb/heroku-buildpack-plone and showcase your add-on to the world!

Share on Facebook0Share on LinkedIn0Tweet about this on Twitter