September 2014
M T W T F S S
« Apr    
1234567
891011121314
15161718192021
22232425262728
2930  

Language

Categories

Meta

Python Snack: How to log only error to stdout in CherryPy

By Bart | April 24, 2014

Started working with Python, which is extremely easy and a joy to work in. It also has great libraries and tools you can use. So, also started using CherryPy to power the XML API I am working on. While debugging it throws out a lot of messages on stdout, of which the access messages I don’t want. Googling and playing around I found this quick way to disable the access logging in stdout:

    import logging
    import cherrypy

    cherrypy.log.screen = False
    cherrypy.log.error_file = ""
    cherrypy.log.error_log.addHandler(logging.StreamHandler())

Topics: Geekstuff, Snack | Geen reacties »

How to ditch PHP, part 2: diving into Python

By Bart | December 14, 2013

Case Study

In part 1 we defined our limits and the requirements needed to replace PHP. We gave Python a first look and found out it is quite easy to use it in Apache. To get a good feeling of what Python can do and how to build a Real World site, I decided to use our Beers website as a case study. It is a simple website where we post beers we tasted around the world, including photos and reviews. It works with a simple database and administration possibilities.  The goal is to re-implement the site in Python and transfer all existing data into it.

Django

Researching Python and web applications quickly puts you on the road of web application frameworks, something I really haven’t used in PHP. Maybe that’s one of the reason of all my bad PHP habits. The de facto Python framework standard seems to be Django. And a nice warm bath it is. It installs like a breeze (as simple as an apt-get install python-django) and has great documentation. I am on part three of its good tutorial now and I am getting a feeling of the joy of using both Python and the Django framework. There are a few things to consider though:

I have used CakePHP before as a framework in PHP, but it didn’t give me the same feeling as Django does. This can of course be because of me. But after running through the tutorial and trying to wrap my head around its workings, Django makes me want to continue with it, CakePHP made me want to put it away. Django gives me the feeling I am still in control, because it hides all the standard stuff behind (highly customisable) admin pages. The actual web application has to be written completely by you. Django includes full MVC support (database connections are seamless, no need to write any SQL) and a template system. Using the manage.py shell you can even load and edit the data in real time. In short, Python with Django lets you create apps, not write the same stuff over and over again. It is not really about the language yet, I hope I can get to that in the next part.

Topics: Geekstuff, Opinie | Geen reacties »

How to ditch PHP, part 1: Introduction

By Bart | December 7, 2013

Introduction

Yes, you read it correctly. After years (approximately 13) of using PHP as my go-to tool for web development, I decided to ditch it. It was becoming more and more of a nuisance and when I got more into C# and Java development lately, PHP started to really feel like a incoherent mess. I read some extra resources about it and the Bad Things I experience are not only experienced by others, no, the PHP mess is even bigger. So I decided to ditch it completely. The first thing of course that pops in your mind is: what next? Which language fits the needs that were filled by using PHP? So I wrote up a little list of features this other language should have for the best transition:

  1. Good templating. I always use Smarty when I program in PHP (that is, I do now, in the past I have written a lot of bad echo "" code).
  2. Good database support. For now, MySQL will do, but I am in the process of ditching that as well, in favor of PostgreSQL. I still want to be able to use my current databases.
  3. Apache integration. I cannot afford to run a specialized application engine on our servers. Many sites still use PHP (like this one). It has all to be combined.
  4. Good library availability. To make real-world applications, XML support, XLS/PDF generation, image generation, etc is mandatory.
  5. Good documentation / community to go to to find stuff out or ask questions when I am stuck. (This is one of the good things of PHP; the documentation is good and there are many people out there that can help you.)

I put this all in a question on Stack Overflow, but also found out, as I already should have known, that these kinds of questions are not a good fit for the site. Thankfully the remarks gave me enough to start digging a little further. Two languages that immediately pop to mind are Python and Ruby. So let’s start with those.

First Stop: Python

Installing / configuring

In my PHP-minded mind, I started to think mod_python was the way to go, but I immediately get reminded that mod_wsgi is a better fit. So I set upon installing and configuring that, which is quite a breeze on Ubuntu. It is right there in the repositories so no need to compile anything. Apache accepted the module easily and configuring it to run an example worked right away. So: installing Python in my Apache server: +1. Now it is time to get up to speed with my Python, which will take some time. Next post, I’ll see if I can get a simple database connection going.

Topics: Geekstuff, Opinie | Geen reacties »

Bart on safety

By Bart | September 24, 2013

When we launched Snøg Avalanche Buddy, we also decided to post the app on some winter sports forums. The reactions we got there were mixed, but mainly very negative. Part of the negativity was aimed at the safety of the app. In one case we were even threatened, that we were putting people in danger. The whole thing gave me the insight that people aren’t thinking thoroughly enough about ski safety in particular and safety in general. Thinking about it, I found out that safety is a three step process of Prevention, Protection and Emergency Response. In this post I will explain what I mean with that. After that, I will talk about ski safety and try to put Snøg’s safety properties into perspective.

What is safety?

100% safety does not exist. Nowhere ever. Even if you have a helmet, seatbelt and super-brakes, there is always the chance of lightning hitting your car and turning it into a fire ball. So, talking about safety basically means talking about risk. How do you treat risks, how do we try to lower them and what do we do if stuff happens anyway? Let’s first define risk. Risk is the product of the chance of something unfortunate to happen and the damage it creates when it does happen. So, dying of a meteor impact is a low risk (low chance, high damage), dying of the common fever is a low risk (high chance, low damage), dying in a car wreck is a reasonable high risk (moderate chance, high damage). We try to control the higher risks, either by lowering the chance of bad things happening, or by lowering the damage if it happens. And this is exactly where the three steps come in.

Prevention

In the first step, it is all about lowering the chances of bad things to happen. This is by far the most important factor in safety. In fact, it is so important, people have been calling it primary safety measures. Prevention basically means staying out of harm’s way. In the ubiquitous car analogy, this means for example not getting into your car, when road or weather conditions are bad. Or driving defensively. There is a lot of technology going on in prevention of accidents.

Examples of prevention measures: good brakes, not running red lights, holding the rail when climbing the stairs, etc.

Protection

The second step is about lowering the effects of an accident, may it happen even after all our prevention efforts. We call these secondary safety measures. It is all about, well, protecting yourself. Often, these measures are the only ones called safety measures and people completely forget the primary measures.

Examples of protection measures: helmets, seat belts, knee protectors, roll cages, etc.

Emergency Response

Okay, so now we were really unlucky. We tried to lower the chances, lower the damage and still we got in an accident. Our last line of defense is emergency response. This is all about getting you as fast as possible into a safe spot again. In our car analogy, think of a system called OnStar that is available in the US. That system will call 911 when it detects an accident.

Examples of emergency response measures: the fire department’s jaws-of-life, always being able to call 112, etc.

Now, what about skiing?

The three steps of safety of course also apply to ski safety and a whole industry is created around ski safety.

In all the discussions on all the forums, many people fail to see the big picture. They buy an avalanche beacon, (mostly) wear a helmet and think they are untouchable. If you do that, think about this: only 30% of people with a beacon are saved from an avalanche. Besides that, the largest risk of an avalanche is not being buried, but hitting a tree or rock. Beacons are your last line of defense, not your first.

And remember: “the mountain doesn’t know you’re an expert“.

Thanks

Many of these insights were inspired / taken from Bruce Schneier’s blog, even though he mainly talks about security and terrorism. The ideas on risks are basically the same though.

Topics: Opinie | Geen reacties »

N reasons why “N reasons why” and “how to become successful” lists are useless

By Bart | August 19, 2013

  1. They oversimplify things, you can not pack a successful business / career / interview in 10 simple rules. If you could, everyone would be successful and not everyone is; hence they are nonsense.
  2. They are basically adverts, they often end in “Dude McDudeson is the author of ‘Be Branson overnight’ or some other business nonsense tripe.
  3. They are not true, most of the time a list like “10 reasons why Branson is successful”, will help you nothing, because there are a zillion other reasons not mentioned in the list. Most notably luck, correct timing and hard work.
  4. Do not try to learn from the big guys, as a three-person business with a yearly turnover of 150k€, it is stupid to try to learn from the big guys. Try to learn from the successful little guys. They are in your own neighborhood, get inspired there, not on LinkedIn from Jobs and Gates.
  5. They often don’t apply to you. Every business is different. Rules that made some people successful can be detrimental to your situation.
  6. They are backwards-looking. For every success out there, there are thousands of failures. Of course the successful ones did something right, but it is hard to put your finger on it. The first person to correctly predict a success has yet to be born.

Bart Friederichs is the author of this blog and an entrepreneur in the Netherlands. He has not published any books at all.

Topics: Opinie | Geen reacties »

Android custom AlertDialog

By Bart | January 7, 2013

For our Snøg Android app, I was browsing the web, figuring out how to add the UnlockBar I wrote to a Dialog, to create a slide-to-OK dialog. I reckoned this would be a simple case of extending the Dialog or AlertDialog class, build it and be done with  it. Well I was wrong. There is a lot of information to be found on the internet about Android programming in general and Dialogs in particular. But not the simple application I wanted. The official documentation tells me to subclass DialogFragment, but it seems like I need to have an ActivityFragment to support that correctly. That’s where I stopped, because the app is a plain simple phone Activity-app. So I ditched that. Then, a lot of blogs and info talking about the onCreateDialog method (nobody telling me in which class it is supposed to be overridden; tip: it’s Activity), that I haven’t had as well. I was just using the AlertDialog.Builder class to create dialogs, and all I wanted was to replace the OK button with my UnlockBar. That’s it! So, after looking around and experimenting a little, I got it: subclass the AlertDialog.Builder class:

public class UnlockDialog extends AlertDialog.Builder {
    UnlockBar unlockbar = null;

    protected UnlockDialog(Activity context) {
        super(context);

        LayoutInflater inflater = context.getLayoutInflater();
        View dlgView =inflater.inflate(R.layout.unlock_dialog, null); 
        setView(dlgView);
        unlockbar = (UnlockBar)dlgView.findViewById(R.id.unlockbar);
    }
}

Then, to use it, simply use this in your Activity to show the Dialog:

UnlockDialog builder = new UnlockDialog(this);
builder.setTitle(R.string.are_you_sure_);
builder.setMessage(R.string.slide_to_quit_snog).setNegativeButton(R.string.cancel, null);
builder.show();

Topics: Geekstuff, Opinie | Geen reacties »

iOS vs Android Development, Round 1: Getting Started

By Bart | October 31, 2012

This week, I took up porting our Snøg Avalanche Buddy to iPhone. To do so, I had to learn quite some things. This post will touch all the troubles I have encountered and I try to compare it to developing an app in Android.

Development Machine

The first hurdle to take is getting your development machine. Android can be developed in virtually all host hardware. Eclipse  is the main IDE used to create Android apps and it is available on Linux, Windows and OSX. Developing for iOS is not so easy. You will need a Mac running at least OSX 10.7 to get to use the latest version of Xcode. Turns out, it is not so easy to get a (second hand) Mac. Luckily I could borrow on old one from somebody. Good thing is that Xcode is free.

Because I come from a Linux (Ubuntu) background, I also have quite some trouble getting used to the OSX user interface. It is not so easy as everybody makes you believe it is. One of the main reasons I switched to Linux in the beginning of the millennium is multiple desktops and I still cannot get my head around the fact that the two other major OS’s still haven’t embraced it. My head just gets completely messed up with so many windows on one screen. But maybe it is just me. Also the shortcuts are different, but that’s just something to get used to, so I won’t bash Apple over that.

The Language

Mostly because of historical reasons, the iOS / OSX ecosystem is built around Objective-C. When you come from a C/C++/C#/Java background (like me), you are in for quite a ride. The syntax is based on the early-80s language Smalltalk and is completely different from what I am used to. I won’t go into details, there are many tutorials out there to teach you the language. All I can say is that it all feels very messy and inconsistent to me. I have to admit of course, that I just started out with it, and have over 15 years experience in C and its descendants.

The IDE (Xcode)

Three words: What The Fuck!

This IDE seems to be designed by people that care about looks instead of clarity. There is a lot of clicking and completely incomprehensible windows, icons, etc. I have to connect a button touch event to an event handler by dragging a line? Seriously? There is a separate “Interface Builder” that doesn’t seem to have any connection with Xcode whatsoever?

It could be the tutorial I was following, but it otherwise also doesn’t seem loigcal whatsoever. It could also be that I have to use Xcode 3 instead of 4, because of the Mac I am using, but still. Compared to this thing, Borland Builder is heaven.

In Conclusion

First remind that I am completely new to both Macs and Objective-C, and have quite some experience in Java and Linux when I started Android development. But, I remember the first “Hello World” app in Android to take me less than 25 minutes, from downloading and installing the IDE to having it on an actual, real device. Xcode took quite some time downloading and installing (10 GB for an IDE and SDK? Second WTF), not to mention getting some app to run. In the emulator. Even though the iOS version on my iPad is newer, Xcode wouldn’t accept it as a development device. Android has no problems at all like this.

The Winner: Android Development

I am going to give this round to Android. Developing for it really is a breeze. The IDE installs and runs on all modern OS’s, is clear and concise and easily supports all devices. Getting to use Java is very nice as it is (in my opinion) the cleanest OOP language out there.

Let’s see what the other rounds may give.

Topics: Geekstuff, Opinie | Geen reacties »

C#.NET snack: sign data with RSA

By Bart | July 10, 2012

Create keys:

var csp = new RSACryptoServiceProvider(keyStrength);
var privateKey = csp.ExportCspBlob(true);
var publicKey = csp.ExportCspBlob(false);

Sign data:
var csp = new RSACryptoServiceProvider();
csp.Clear();
csp.ImportCspBlob(File.ReadAllBytes(privateKeyFile));
var sig = csp.SignData(data, new SHA1CryptoServiceProvider());

Verify data:

csp.Clear();
csp.ImportCspBlob(File.ReadAllBytes(publicKeyFile));
if (csp.VerifyData(data, new SHA1CryptoServiceProvider(), sig)) {
    Console.WriteLine("Data is OK");
} else {
    Console.WriteLine("Data is not OK");
}

Topics: Geekstuff, Snack | Geen reacties »

Copy JVC Everio .MOD files on Linux

By Bart | June 4, 2012

I patched a little Python script to correctly copy .MOD/.MOI files to MPEG-2, including the aspect ratio bug in the format: http://blog.friesoft.nl/files/sdcopy.py. It is tested and works on Ubuntu 12.04.

Topics: Geekstuff | Geen reacties »

Adobe Flex snack: Error #2048: Security sandbox violation

By Bart | May 22, 2012

If you are building a Adobe Flex application that uses sockets, you have to send the policy-file-request, or crossdomain.xml. A lot of info available on it, except that you need to send a null character at the end of it.

Topics: Geekstuff, Snack | Geen reacties »


« Voorgaande Artikelen