Adomas Mažeikis personal site Just another WordPress site


Python regular expression examples (grab some html)

Python is a powerful helper in any developers day to day job. However, documentation is sometimes not reflecting real life examples.

I did hit the wall of bricks at one point with regular expressions in Python. My experience with simple ones did not help while creating some
more advanced regex'es, because flags to be defined are passed quite strangely in Python and performance comparisons between different regex functions in Python did also influence choises. So, here's my approach to using regex'es in Python:
1) Try to build regex in one of ultimate tools like: with a test case.
2) Analyze how often will regex be used. If usage is less than 100 times - search or match function is enough without compiling regex (althoug even solitary usage is faster with compiled one).
3) Use the code:
import re
regex = re.compile(YOUR_REGULAR_EXPRESSION) for example:
regex = re.compile('(?ims)<div id="boo".*?>(.*)</div')

Note that flags are given in the beginning like (?ims)
Use compiled regex:
neededText = regex.findall(bigBigStringToSearchIn)

Result is returned as list...access results like neededText[0] etc.

Or just use regex quickly:
neededText ='(?ims)<div id="boo".*?>(.*)</div',bigBigStringToSearchIn)

Access results as: ----that is including regex defined string or to get just the capture group.

That's it folks! It's that easy :)


Populate/fill select with options using AngularJS (multiple hierarchical select example)

So, how do one populate select with options from any array available in AngularJS?
That's quite easy. Here's what you have to do in HTML:
<select ng-model="selFruit" ng-disabled='true'
ng-options="fruit as for fruit in colours track by fruit.fId"
ng-init="selFruit={'fId':'?', 'name':'Select fruit'}">
ng-disabled here will disable the select (pretty cool when needed).
ng-options will populate the select with options from array of objects which you can create by for example:
angular.forEach(Object.getOwnPropertyNames(data.fruits), function(value, key)
$scope.fruits.push({ fId: value, name: data.fruits[value].name });
ng-init will make sure any needed value is chosen initially.

Moreover, you can write watch function to populate other selects or do whatever is needed when this one changes:
function( newValue, oldValue ) {
// Ignore initial setup.
if ( newValue === oldValue ) {
//Fill colours select================

$scope.colours = [{"cId":"?", "name":"Select colour"}];
angular.forEach(Object.getOwnPropertyNames(data.fruits[newValue.fId].colours), function(value, key)
$scope.colours.push({ cId: value, name: data.fruits[newValue.fId] });


Where colours select would look like:
<select ng-model="selColour"
ng-options="colour as for colour in colours track by colour.cId"
ng-init="selColour={'cId':'?', 'name':'Select colour'}">


Steps for recovering lost Android phone (for example Samsung Galaxy S4)

The sad part here is that no guarantee about getting your phone back, but here's what you can do:

Before anything happens:

Don't wait until something happens - react immediately and install Prey App, configure it.

Enable remote control over Android device manager or Google settings and location history.

My personal recommendation is not to use any lock for device unless some sensitive information is in it (of course Google or FB account open and passwords remembered in browser is serious enough). Then you can try to contact the stolen/lost phone for some period.

Keep the phone charged and connected to mobile internet if possible otherwise none of remote methods will work.

Note phone's IMEI code somewhere as it might be needed.

At the first notice of disappeared phone:

Try to phone it and use Google's Android device manager to see current position. Maybe activate lock and or remote ringing.

Samsung offers phone locating service at with some remote control as well. Use them.

Use Prey app to indicate phone is missing and get information about it.

Create a fact chain to trace the events and call the police if theft might have happened.

If transport used - check all transport companies, they typically have lost&found departments.

Check Lost&Found office which is typically managed by Police or local government.

Check local Lost&Found Facebook groups.

Scan classifieds periodically - not only lost and found but selling section as well.

After some sane period block the phone by contacting operator, but you'll need IMEI code for that.

Transfer your phone number to another SIM card.

...and if you catch the thief - kick bastards ass so hard that he/she would forget about stealing for a long time.

No image under this post...just a sad face :(

5Jan/150 car sharing service (delebil) in Copenhagen

I've always wondered how car pooling/sharing works and LetsGo seems to be the perfect example. It fits perfectly if your journey doesn't reach 200 km (as otherwise it might be cheaper to take another rental car) or you don't need the car constantly.

Why is LetsGo better than any other service? It has a huge amount of different cars. Want a baby electric car - here you go! A huge van for moving which still matches your driving licence - here it is.

  1. The procedure is ultra simple - register online at (you'll need drivers licence number for registration and there was a limited offer for a price of registration as 0 DKK with Rejsekort card).
  2. Go to one of offices with your licence and photo ID and get a key with RFID brick.
  3. Now you are activated as a member and ready to get a car. Reserve a car online choosing a type and a place.
  4. Get to the place on the reserved time (5-10 minutes earlier might be a good choice to walk around the car and see the damages if any and clean the snow from windows so that you can drive when reservation time comes not to waste it).
  5. Use the brick or the key to get into the car (car keys are typically in one of glove boxes...if the car has several storage compartments - check all of them before panicking that keys are gone...remember where the keys were so that you can return them to the exact point later).
  6. Report any damages that are not marked in the list in glove box.
  7. Use the car cautiously...some of the cars are different size than you will be used to...some of them have a very different clutch than others (clutch switches off quicker than expected, so if you're not releasing it softly or have just a tiny gap before the obstacle - you'll get a bump). By cautiously - I mean use it as if it was your own, because from what I've seen up til now - the cars are nearly ruined when they have finished as low as 15.000 km which is a very sad fact. Of course, they are still usable but far far away from new at that point which makes you think what the hell happened to them?
  8. Child seats are not provided, so bring your own if needed.
  9. Before returning the car - make sure that fuel level is higher than 1/4 of tank and that you have more than plenty of time, as sometimes unexpected stuff can cost you overtime tax (traffic jams, difficulties finding returning place etc.)
  10. Clean up after yourself! Mess like broken glass is not funny at all.

As easy as that :)

Adding a photo of travelling doesn't make your car a UFO, but cheers everyone a bit for sure.

Alien sticky attached to car dashboard

Alien sticky attached to car dashboard


Opel Astra H and J generation user experience comparison

My wife was a proud owner of a perfect condition Opel Astra H (2007, 1.6 l Gasoline). I did drive that quite much as well (at the same point I had Ford Probe I Gen GT 2.2 Turbo, but it was mostly standing in garage for improvements...). My Feeling about the car was that it is just perfect. Everything about it. We've traveled all over Europe back and forth, a lot of times to Poland from Vilnius, have loaded the car till the complete limit in some of the trips - it was just going perfect. Only one minor issue with speedometer which was fixed by authorized dealer quickly and financially not that painfully. However, we did sell it (maybe it was a good time to do that before it got to the point where all repairs start). Average fuel consumption did not exceed 6.2 l/100km...which is quite astonishing for gasoline. I did squeeze as little as 5.3 l/100km in some trips.
Recently had an opportunity to rent Astra J SW Diesel. Damn that car. Absolute fuel monster at 6.7 l/100km. Everything seems to be fine as the car is still new at 11.000 km, but from the first moment I do hear clutch switching with low frequency boom. It might depend on previous drivers, but still...Foggy windshield seems to be a bit of the problem even on days when it is not raining. A/C solves that quickly but it disturbs driving while switching it on or off on occasion. Chassis seems to be a bit too low. Speed bumps have to be passed over really slowly. Engine sound also seams a bit too loud with specific fissssssing. Otherwise - nice enough to drive and huge cargo space might surprise anyone. Specific feature I liked a lot - number of cup holders exceed passenger capacity.


A bug or a feature

Working with different APIs got me to the point where some decisions have to be made:
1) What is the right thing to do when you stumble upon a bug in a third party API? Report it and waste API providers and your own time if the bug is not crucial? Consideration here is that as I myself do know most of my code flaws - API provider might well know his own as well, so why waste time on sharing information which is already known. From now on I'm just reporting bugs that are crucial like no results returned when it should be at least something or some obvious error which makes API unusable.
2) A bug might well be a feature. If you're sending an empty array of users that are to be updated and update function just wipes all of them from DB - maybe it is a very comfortable way of wiping DB when needed instead of removing users one by one or sending a list to delete function? Or maybe an error that connection is not made (although it obviously works) might be a great heartbeat of process and if these messages do stop - it might mean that the process is dead.

However, it might be a good idea to document these things.

And as's a nice photo from Skagen where ships follow the same path in a row. A, so called, bottleneck :)

Ships in Skagen

Ships in Skagen


NetBeans vs. plain text editors

I've almost always been a person who used good old plain text editor or the hardcore vi in terminal to do programming or fixing stuff. Gedit is my favorite GUI text editor and Nano is pretty fine for terminal (although not so many fun features as vi). However, finding the right file and color scheme absence sometimes did push me a bit back. Also used Eclipse for Java projects and XCode for iOS app making. Colleague offered to taste NetBeans and damn it! this nice piece of software has changed much from some early editions. I've tried it quite a lot of years ago (can't even remember exactly). It was slow, bulky and annoying with crashes, bugs etc. But it has grown a lot from that point.
Full support of version specific functions in PHP and nice functions as find all usage etc. works more than just fine. Autocomplete is still a bit annoying, but it is not hard to switch it off.
However, there still were some crashes and the most annoying point is when you do get to open a huge file. XML > 1MB + replace something - NetBeans are dead.

Anyway, it seems that I'll be sticking with this IDE for some time.

And just as a's a pic from commuting trip taken near Vangede station.

Sunrise near Vangede st. Copenhagen

Sunrise near Vangede st. Copenhagen



Filed under: Programming No Comments

What’s it like to be an IT guy

I'm not specifically writing  - what's it like to be a programmer, because the idea is more general.

First things first - being good at IT typically means that there's less time for sleep, family, social interactions etc. I know that new generation has a big hype on being geek and there are a lot of punks who put huge glasses and already do feel as geeks (sometimes they even learn to write a pair lines of code!), but whenever you tell them "just put this function in kernel and recompile it" it sounds like a huge boo!

So, my SleepBot App tells me that my sleep debt is waaaay beyond 100 hours in the last month and that the average sleep is 5.2 hours. It is achieved over a short night time sleep and a nap. The app that I use to track my food intake, tells that I do drink a pair of coffee cups in weekend and holiday days, but I do have 5 cups on average during the working days.

Laptop usage statistics are also quite unusual for non IT person - 14 hours per day eyes are locked on screen.

Then there's a huge drawback while being an IT guy is that a lot of people ask for help (which is still not the worst). That is not a huge problem until they start sharing their "expertise" you shouldn't disable this because the PC will crash - and you clearly know that exactly this enabled feature IS the problem. Then there's another class of people who think that IT is just a freaking easy bullshit and you're basically doing nothing. They even feel scolded if you're telling that you have more important tasks than looking at their cat photos or helping them to search some elementary stuff on Google.

Moreover, IT means that you will be learning new stuff all the time at your own expenses. If you do consider this is fun - then it is fine, but most people fell that it is "a waste of time".

But don't be afraid, join us - the IT and you'll find a brand new world of possibilities...just try not to ask questions. 99.99% of answers are in Google. Use it wisely.


Come to the dark side - we have cookies (and Darth Vader with light sword)

Come to the dark side - we have cookies (and Darth Vader with light sword)


Filed under: Uncategorized No Comments

Real reasons of lack of IT engineers, specialists and just plain programmers

In the end of every June or at the beggining of July I like to take a big mug of coffee and try to solve Lithuanian secondary school exam tasks. Just for fun and to keep my brain mechanics working as well as testing self in all these fields like IT, maths, chemistry, physics.

My observation is that tasks are getting easier. To be exact, pupils need less hard algorithms, but a bit more information stuffed in their heads. The most fun thing is how future students of universities are whining about everything except their own fault.

So, back to IT. The first thought when I saw exam tasks was is that IT exam or secretary preparation test? Programming tasks were interesting, but all others were rubbish.

I'm not contemplating that it was a super easy exam, because I myself am and IT person, but I missed basic testing of computer architecture knowledge.

And then the statistics of exam results came...quite frightening for a country which sees itself as knowledge economy in the future. There were approx. 2630 who took the exam. 92% passed, so that's roughly 2400 students interested in IT and able to pass minimum requirements. It was enough to know test tasks and not even try to solve programming ones to pass. So, I have a feeling that only 800 from those who passed are able to write a working program. I'm sure that half of them won't try to study IT, so that leaves 400 students who are able to perform minimal tasks before being accepted to university. My experience tells me that the rate of people who begin their higher education and those who work as real IT specialists after finishing university is not more than 20% (optimistically). So, that makes approx. 80 really tough IT guys overall who can crunch networks and make non trivial programs. Hopefully, bigger part of them will stay in the country.

So, numbers are frightening and with such a high need in the field, lack of IT guys might be catastrophic. You say Philippines, Bangladesh and India? :) I don't want to be rude, but try to work with these guys and just make a small research of what universities are there as well as what courses and their content. Make conclusions yourself then, I won't be telling much about that here.

And if someone from CEO's or other executives are reading this - keep in mind that when a country with approx. 2.5 million people gets only 60 reaaaally tough IT guys every year, the rule: you pay peanuts - you get monkeys is very important. I'll write later what it takes to be a good IT guy and why do they cost so much. I'm sure not much of you understand the concept of work being done by software architects, programmers etc.


SRAM S7 aka Sachs Spectro Super 7 bike internal gear hub tiny FAQ

I've had a bunch of experience with these hubs already, because we have 2 bikes that are fitted with this type of hub and both were broken several times (but it is understandable as bikes are not new and some failures were because of my dumb head). Super helpful remark!!! - whenever switching box is taken away from the hub - take internal axis with red plastic thing away to the safe place. This will save you time, money and nerves. I've not followed this simple rule and after taking gear switching box and back wheel off the bike I did laid it on the side...the axis was bent when I picked it up again. Axis with little red plastic costs ~6-7 USD without shipping. So, let's go to the questions:

1. How reliable is this SRAM S7 aka Sachs Spectro Super 7 bike internal gear hub?

It is super reliable as long as you care enough. Typical failures are due to biker errors: don't bend the axis; don't use to much force while switching gears; switch gears only when not pedaling; oil cable well before winter and don't switch gears if you feel that cable might be frozen in the housing.

2. Is it enough only 3 gears like S3 or 5 like S5 or should one go for S7?

S7 - definitely. Not only because the well levered load, but also because it is more reliable.

3. How gear switching box is taken off and put on?

To take off the gear switching box switch to 4th gear, unscrew the little screw in the side, but not all the way as it is easy to loose that one. Then try to take the box gradually but don't use too much force not to bend axis. And as recommended earlier - take internal axis out too and put it to safe place not to get sand or dust or dirt inside the mechanism. To put the box on - put internal axis inside the hub with the housing. Be sure to check that a cut in the housing matches with red plastic thingy pin and the red plastic outside in at the top (it should show 12 o'clock and inside pin should be at ~3 o'clock as far as I can remember). Then make sure the box is switched to 4th gear and that a top transparent plastic dash matches with the cuts in the circle inside...if not - use the regulation to make it so. Then put on the box and screw the side screw firmly.

4. What else should one know?

Use the right length of cable and be sure front basket (if you use one) or other gear does not pull the cable out from switching wheel on handle bar. It will be really hard to change cable if this happens.

5. My bike "jumps through" several teeth if I pedal hard. Is it the hub already failing?

I'd guess that it is just loose chain or gear switching box is not fitted right.

SRAM S7 switchbox

SRAM S7 switchbox

Gear switching handle

Gear switching handle

Tagged as: , , No Comments