Friday, February 8, 2013

configuring PEP8.py support in PyCharm 2.7

UPDATE
Jetbrains developer Dmitry Jemerov contacted me on twitter with a much quicker way to do this.

Jetbrains released their latest version of the PyCharm python IDE, and one of the great new features is integration with pep8.py. For those who don't know what pep8 is, pep stands for Python Enhancement Proposal. The PSF(Python Software Foundation) keeps a list of these proposals, and each one gets a number. pep8 is a style guide for python that many projects follow, and to make it easier for programmers to check that their code follows these style guides, pep8.py was created, a tool that automatically checks for pep8 compliance.

With this tool integrated into PyCharm, the IDE will show you where you're violating pep8 rules, but here's my problem. pep8 says you should use spaces for indentation, while I strongly prefer tabs, so every line showed an error for me. You can configure pep8 to ignore certain errors, but it wasn't immediately clear to me how. I found out after a bit of digging around, but I want to save you some time. So with no further adue, here's how to do it.

  1. In pycharm, click the settings icon, or go to the settings via the menu bar.
  2. In the project settings section, click 'inspections'
  3. In the list that appears, click 'python'.
  4. Under python, scroll down and click PEP8.
  5. Now, underneath the description, you'll se an 'ignore errors' section. Click the + at the bottom.
  6. Now, go here. This is a page of the pep8.py documentation, listing all possible errors and warnings.
  7. Find an error you want to ignore, and copy the error code at the left.
  8. Paste this error code into the field you just added in the settings window.<:li>
  9. Add all the errors you want to ignore and click apply.

The changes will immediately take effect, without a need to restart.

Thursday, May 31, 2012

Braille and Unicode are more similar than I ever knew.

As you probably know, braille is a writing system that is widely used by visually impaired people. A couple of years ago, I visited China with my parents, where we went to take a look at the terracotta army. Suddenly, I noticed that they also had information in braille. Curious about how Chinese braille would feel, I walked over to the metal plate on the wall on which the information was written. None of the characters made sense to me, but what I did notice, is that they used the same 6-point braille system, that we use in Europe. To explain this, I'll first have to teach you a little bit about how braille works.

Each braille symbol consists of a matrix of 3 high and 2 wide. Each of the cells in the matrix may contain a dot. The cells in the matrix all get a number. The numbers are laid out like this:

14
25
36

As an example, take a look at this image, it's the letter f. This is written by typing points 1, 2 and 4.

Now, going back to the Chinese braille, a couple of weeks ago, I had the brilliant idea to just google "chinese braille", and the first link I came across was a wikipedia article. What a surprise. but in this wikipedia article, I found a great explanation of how different aspects of these chinese characters are shown in consecutive braille symbols. Standing in awe of this ingenious system, that could encode a language as complex as Chinese, into a system where there are only 2^6 possible symbols, I suddenly realized that western braille uses some of that magic too. We had to, with only 64 possible symbols. If you would encode all small and capital letters differently, that would already add up to 52 characters. Add to that our 10 digits, and we've already used up 62 characters, and we're still far from encoding everything. We haven't encoded any punctuation marks yet, the period, colon, semicolon, comma, question mark, exclamation mark and many more also want to be written down, and what about mathematical symbols for addition, division, multiplication and subtraction,...

Here are a couple of tricks that braille uses to circumvent these issues. First of all, we reuse our small leters as capitals, but than with a capital sign in front of them. So to write anyone's name, you'd first write a capital sign, indicating that the letter after this sign is a capital. This sign consists of point 4 and 6. Some abbreviaions and acronyms are written in all caps, and for that, we've got the permanent capital sign, which turns the entire next word into all caps. This significantly reduces the number of characters needed, but there's even more. We also reuse our letters as numbers. The a is the 1, the b is the 2 and so on until j, which is 0. You first write a number mark, and then, any characters that follow before a space, or another non-numerical character are now numbers. for example, let's say for a moment that the dollar sign is our number mark, then 123450 becomes $abcdej.

coming from my thoughts about how diferent languages may use braille in different ways, I suddenly thought about how Unicode does exactly the same thing. For the people who don't know what unicode is, it's a way to store text as numbers. A computer can only store numbers, so there needs to be a mapping from these numbers, to the characters made visible to me as I type out this blog post.

Many years ago, the most used standard was called ascii, which only used 1 byte to store each character, 1 octet to be completely precise, but I'm just going to call it a byte to keep things simple. A byte consists of 8 bits. A bit is a part of memory which can either be 1 or 0, so with 8 bits, you can form 2^8 symbols, But as technology grew more popular, internationalization was needed, and there was no way that all those arabic, chinese, russian, and all the other "weird" almphaets, would ever fit into 256 possible symbols. Unicode's sollution, was the same that braille used, multiple consecutive characters would form new ones. The similarity is not a great discovery, but still, it teases my mind to think about different ways to encode characters. Thinking about it even further, you may even consider our writing to be a character encoding, where each symbol we write is mapped to the idea of a certain character.

Tuesday, May 1, 2012

Is an API copyrightable

I'm a programming geek, and being in the kind of programmer culture that we have on the internet today, I love everything open source, or open in any other way, at least if it's not just a word in the marketing material. With the conflict between google and Oracle, around the IP theft of java API's, I started to think about the consequences it could have when API's get copyrighted.

What's an API?

You're probably using a twitter client on your mobile devices. Those twitter clients need some way to pull in the data from your twitter stream, and to post a new tweet, when you're drinking the best coffee in the world at your local starbucks, and feel the need to let the whole world know about it. To allow for this to happen, twitter built an interface, that programmers can use to hook their application into twitter. Such an interface is called an Application Programming Interface. But an API can also exist within one application. Take for example your word processor. Let's imagine that there is a component that keeps track of the current style settings such as color, font and font size. Such a component is not responsible for drawing the buttons on the screen that control these properties. So, when you use the mouse to click to select a color in the user interface, the component that reacts to that click, needs to have a way to communicate with the style component, and that's where that component's API comes in. The component exposes certain functions that can be executed in order to get or change style settings.

What we call the API is just the set of functions exposed, without considering the implementation, so we don't care how the style properties from our example are stored or retrieved.

The problem

Oracle is now claiming that google has infringed their copyright, by copying the structure of their API. I find this rather logical, many components used in many software applications have only one, or very few ways to structure them logically. Take for example our style component. it would logically have some of the following functions defined in it:

  • get_font
  • set_font
  • get_font_size
  • set_font_size
  • get_color
  • set_color
  • ...
There is no other logical way to define this API. Now, imagine that the set_color function could take a color as a parameter, which would be a component in the program too, with functions like:
  • set_rgb
  • set_hsl
  • set_cmyk
  • ...
These functions are just creating colors based on commonly used color schemes. It would not make sense to create a new scheme, as not to infringe anyone's copyright.

The implementation

I do think that copyright should stay applicable to the implementation of a system, although the system has to be large and elaborate enough. There aren't that many ways to get the greatest common denominator of a set of numbers, so copyrighting that obviously would be a bad idea, but there can really be a lot of difference between different implementations for a spreadsheet application, so it's a good idea to copyrigt Excel or Numbers.app.

Monday, April 30, 2012

My message to the music and movie industry: Don't fight, debate.

SOPA, PIPA, ACTA, and many more laws have sparked debate around copyright infringement. Pirates state that the prices for content are too damn high, while content creators say they really need the money to keep the content coming. But the reason most people download, is not as much about the money, as it is about the ease of it. So instead of fighting the pirates, the movie and music industry should listen to them, and see how they can help, it's the old idea of customer relations management, you see what your customers want, and provide it. To help move the content industry towards this situation, I'd like to give a shoutout to the companies that facilitate this process.

Spotify!

Spotify is an awesome app, if you haven't been living under a rock (I like cliché expressions), for the last year

or so, you've probably heard abot it. You can listen to any music you want from your computer, and for a small fee, also on your mobile devices and without ads. For me this is the best example of making it easier to be legal. Since I've started using spotify, I haven't illegally downloaded a single song, simply because it's much quicker to open up spotify and play it. I no longer have to go through the hassel of opening up my torrent client, looking for a torrent with a good seeder to leacher ratio, clicking the download button, and hoping it'll be a good quality torrent.

Netflix

Netflix is not yey available in Belgium, so I'm unable to say much about it. But the streaming of movies sounds like an easier thing to do than look for a version on the pirate bay that doesn't have japanese subtitles, or worse, is dubbed in German. I wish content creators weren't so picky about where their content could be viewed. Maybe I'm just ignorant of some facts, but I don't get the point. If I watch a movie in Belgium on netflix, and they get the money for it, what's the problem?

YouTube's content id

Youtube is a great way to share content, including content you don't have the right to redistribute. What I like about Youtube's way of handling this, is that they don't just allow copyright holders to take it down, but also to make use of theseuploads of their work. The claim many pirates have made, that these distributions of content also promote the content are valid, so content creaters can benefit a lot from just leaving them up on youtube, and making part of the money they would have made, by getting part of the revenue from the ads on youtube, and yes, I know google takes a cut of that too, but In my opinion, they deserve it fror creating this system.

Monday, April 2, 2012

Don't get squished

Play my code shows the power of the web as a platform. They've built a site where you can create any game you can imagine, and publish it for the world to play in their browser. Below, you can see my first steps into the playmycode world.

How retina ipad screens may even help the blind.

By now, everybody knows that the new ipad has a retina screen, which even to my visually impaired eyes, looked stunning. When I first heard about the ipad, I wasn't too hyped about it though, because the graphics and graphics performance were the only big new features, which to a visually impaired, isn't very interesting. But the increase in the number of people reading on retina screens may cause a change, that will be very beneficial to people who requir a screen reader to read.

Paper publisher's inability to change.

Last year, when my mom got an ipad 2, I was very excited. It was the first time that I'd be able to read the Humo, a Belgian magazine, or so I thought. After tripple clicking the home button to activate VoiceOver, I put my finger on a large piece of text, which was immediately followed by the disappointment of hearing the clicky noise you hear when you put your finger on a place where VoiceOver has nothing to read.

Not knowing much about magazines in the news stand, I tried another magazine, with the same result. I became suspicious about the way magazines published their content to these devices. After doing some research online, my suspicion proved right: to keep the pixel perfect control about the layout of their content, these magazines sent huge images to their readers, which is not a problem for sighted people, because the text is visible as usual. This only becomes a problem when you try to select text, or, as I found out, try to read it with voiceOver.

What these magazine publishers don't seem to get, is that people want to consume media in the form they prefer, not the form the publishers prefer. This is also shown by the increasing popularity of apps like instapaper or readability.

Publishers need to accept that on an iPad, their magazine will look different from the same edition viewed on an HD Television, but also know that people might want to view their content in a text-based browser. The fact that so many types of devices are now connected to the internet, makes it possible for people to read in whatever way they like, if publishers would make the content plain text. I've sent Humo a message, both via their website, and on twitter. On twitter, I got the typical "We'll look into it" response, and I haven't heard from them since.

Retina displays and bandwidth limits to the rescue!

People who have used the new ipad, will know that content that doesn't have a high enough resolution for the retina display, look worse than they would on a lower-res display. This is especially noticeable on the web, where many sites just give you images with normal resolution. Magazine publishers probably don't want their magazines to look bad on the new ipad, but shoving an image with 4 times as many pixels als they used to have down people's wifi, and possibly 3G, or LTE connections, will not make for a nice reading experience either, making for download times in which you could make a trip to the moon and back, and still see the spinning loading icon, and making you reach your download cap by downloading 1 magazine, and a lolcat picture. My hope is that publishers will finally start adopting plain text formats such as HTML, or ship their magazines in the ibook format or as pdf. This way, they'll give their users a much better reading experience, and avoid articles like this one,this and this one.

Sunday, March 25, 2012

Crazy Daisey's apple picking.

This american life created a show called retraction. Their most popular episode ever:Mr. Daisey and the apple factory, contained lots of lies.

Better than the retracted episode.

In this episode, Ira glass confronts Daisey with the lies he has told. If you have no clue what all this is about, I encourage you to go listen to the retractions episode, and if you really want the full story, listen to the apple factory episode too. Don't just read the transcript, because there's a lot of weight in the way things are said.

This retraction episode, is more worth to me, than Daisey's episode, even without considering the lies in there, it's journalism at it's best. You se people really wanting to get to the truth. This makes for a very awkward episode, as you can nearly hear Daisey's brain going in overdrive, trying to come up with an answer to Glass's questions.

A play outside the theatre.

In the retraction episode, Daisey states the following:p> I am agreeing it is not up to the standards of journalism. And that's why it was completely wrong for me to have it on your show. And that's something I deeply regret. And I regret that the people who are listening, the audience of This American Life, who know that it is a journalistic enterprise-- if they feel misled or betrayed, I regret to them as well.

He states that what he said was not up to the standards of journalism, but only seems to regret what he said on This American Life. Does that mean he does not consider the dozens of other programs he has been on: TechCrunch, CNET, Real Time with Bill Maher,c-span..., to be journalism? I find that very hard to believe.

Daisey admits that he has 'taken shortcuts' in his monologue. He gives the following explanation why: Everything I have done in making this monologue for the theater has been toward that end – to make people care. I'm not going to say that I didn't take a few shortcuts in my passion to be heard. But I stand behind the work. I get that he wants people's attention, that he aggregated information from other stories into the story about his own story, and made some facts seem a little worse then they were, to make people aware of the problems in China. As I said, he indeed shouldn't have brought it as news, but I'd go as far, that this should never have beeen part of a play. He tells the story in such a way, that appears to be truth. If you don't explicitly tell them, you shouldn't expect the audience to just know that it's partly/mostly fiction, they're listening to.

If you think, you'll only get heard by telling lies, I think you'll be wrong in any situation. I think Daisey should have either told the story, as it really was. You can get enough drama by telling about people getting poisoned while making an ipad, if you have just red it, it's not necessary to make it seem as if you talked to the man in question. And if you don't have enough information to tell a good story, either you'll have to look further and dig deeper, or there's really no story there, and you'll have to admit it to yourself. I'm afraid that that's Daisey's biggest problem. He came there, and the conditions he discovered weren't as bad as he was expecting. Not bad enough to make a show that would shock people.