self.li - note to self and share with others, blog by Peter Legierski

Peter Legierski

/pronounced as leg-year-ski/

Occasional workaholic, regular teaholic. Lead Developer of GatherContent. Fat, powdered nose, indoor climber!

Currently working on my personal project phpconsole. Check it out, it will speed up your development process!

Yellowish tint on your Nexus 7? Here’s how to fix it

I’ve been using my nexus 7 for nearly a year now and never thought that there would be a simple solution to a problem that every Nexus 7 owner faces (literally) - yellow tint on the screen. We all know it, we all saw it and there’s nothing we can do about it, right? Wrong.

I’ve found an app that does an amazing job in terms of fixing (more like hacking) colours on my precious. It’s called Screen Adjuster. The trick is very simple: the app displays a layer above everything else on the screen, which you can turn a little bit blue, which in turns offsets the yellow of the screen itself, making it much more “white”.

I’ve set blue to +13, left all other sliders alone and set the app to autorun on startup and hide status bar icon - as a result I have a tablet that looks good and is not littered by any unnecessary notifications/icons/whatever.

image

image

Enjoy!

Posted 3 weeks ago - Comments

Gmail Blue now available on Android devices (video)

Gmail Blue, an amazing new version of Gmail is now available on Android devices! See the video below for a quick preview:

image

Posted 1 month ago - Comments

Production/development switch for your codebase

tl;dr: Add “.production” file to the root folder od your codebase on production servers, add “.development” file to the root folder of your codebase on development servers (both files empty, only name is important), ignore them globally in your git repo, ignore them locally in your FTP settings or whatever you’re using to push changes up to your servers (I’m using ST2+FTP plugin for dev server) and add the following somewhere at the top of your index.php file:

Now, you can put all settings for both production and development environments in your configuration files and choose the right one based on your ENVIRONMENT constant! Sweet, one less thing to worry about!

Long version

How do you deal with differences in your codebase between production environment and development environment?

In my case, I used to have my codebase in git set to production (disabled error displaying, live base_url, live database, all functionality enabled) and using git’s “ignore locally” feature several files changed so that error displaying is enabled, base_url set to dev server, dev database details, emails redirected to phpconsole.

What’s wrong with that approach? Quite a few things, actually. What if a new developer sets up his account on dev server without changing any config files and starts running his code against live database? Well, we can change the repo to point to dev db by default. But what will happen if someone deploy code to one of production servers and forget to change values to point to the live db? Oopsie, some of the clients are hitting our dev database!

One day I was wondering how to make it all work automatically and remembered that Beanstalk uses “.revision” file in root folder of your codebase to track which revision is deployed to your servers.

I thought “brilliant!” and decided to use similar approach:

The snippet of code from tl;dr above sets ENVIRONMENT constant that can be used to change your application’s behaviour. If none of environment files is present, the page will exit with an information about what happened. This way we’re mitigating risk of running wrong version of the code,while keeping convenience of single codebase.

Of course, you’re not limited to only 2 options, you can easily add another one, e.g. “.staging”.

Let me know what you think about this approach in the comments below.

You can also read:
How to understand half of Harry Potter book in any given language
How to increase productivity per square inch of your screen
Logging in with QR codes

Posted 2 months ago - Comments

Super fast FTP upload (if you have thousands of files)

I vaguely remember one of my ex-colleagues moaning about WordPress taking oh so long to upload via FTP. I’ve been reminded of this problem a couple of days ago, moving several of my sites to a new hosting provider. Pretty much every folder contained over 1000 files and the process took forever.

I came up with a solution that probably to some of you will be totally obvious and familiar, but I’m sure there’s plenty of people who can benefit from this post.

Requirements:

  • SSH access to your server
  • Linux or Mac on your machine - with Windows there might be slightly more fiddling

Steps:

  1. Open terminal and navigate to a folder that contains your page files
  2. Run “zip -r code.zip *”
  3. Upload created code.zip file in your preferred way (I use Sublime Text 2)
  4. SSH into your server and navigate to a folder where you uploaded your code.zip
  5. Run “unzip code.zip”
  6. Delete both code.zip files. You can use “rm code.zip”

The biggest win is the fact that you have to upload only ONE file, which is much much faster than uploading thousands of separate files.

Want real numbers?

Ok, let’s try it with the latest version of WordPress. Zipped file straight from their server is 5.2MB and (on my worse than usual connection) uploads in 1:26. Unzipped folder contains 1026 files, is 11.8MB and uploads in 21:06 (!)

The difference is less significant on better internet connection but more significant when the size of your project grows up to a few thousands files and above.

Hey, all my WordPress files are in a subfolder! What did you do?!

Ok, ok, calm down, we can fix it real quick, moving all WP files one folder up:

  1. Run “cd wordpress/”
  2. Run “mv * ..”

The second command moves all files from current folder to one folder up (“..”).

You can also read:
How to understand half of Harry Potter book in any given language
How to increase productivity per square inch of your screen
Logging in with QR codes

Posted 3 months ago - Comments

How much code did you really write? (+ source code)

Have you ever thought how much space is taken by characters (spaces and tabs) preceding your code, just to indent it for readability? I bet when you look at the code in most of the editors, you don’t really notice it. It’s there and it lets your creation breathe. But take a look at the following screenshot from Sublime Text 2 (awesome editor by the way):

Notice, how many spaces are there! For bigger projects it can be mind boggling. I started wondering, how much spaces do I have in my code that is not really a code? How much spaces do I have on phpconsole page?  To answer that question I wrote a simple script that calculates number of spaces preceding code within selected folder. It takes into account *.php, *.html and *.htm files. I thought about adding *.css and *.js but many of them are minimised these days, so there is not much sense in adding them.

Here’s the code:

My results:

phpconsole - landing page for my project that I encourage you to check out:
17.82% of selected folder’s files (3774 spaces, 21181 total characters).

legierski.net -  my homepage:
7.64% of selected folder’s files (400 spaces, 5236 total characters).

CodeIgniter 2.1.3 - my PHP framework of choice:
3.70% of selected folder’s files (92426 spaces, 2497844 total characters).

In CodeIgniter’s case it’s over 90KB of indentation!

How does it stack up against your code? Let me know in the comments below!

You can also read:
How to understand half of Harry Potter book in any given language
How to increase productivity per square inch of your screen
Logging in with QR codes

Posted 6 months ago - Comments

4 weeks into my ‘Half hour’ productivity hack

Yes, 4 weeks, and guess what, it still works! It’s not one of those productivity hacks where you try to be super efficient and do more in the same time (that doesn’t work for most people). Instead it is a really simple system and focuses on exploiting our habits.

Ok, so what is it all about?

A lot of us wakes up early 5 days a week, works in the office for a few hours, comes back home and after a dinner negotiates with the inner self “I should be doing something creative. Why am I watching TV? This month I wanted to work on project X, but man, I’m so tired! I think I’ll let myself off today and work hard tomorrow evening instead”. And that happens pretty much every day.

I decided to break this bad habit by exploiting my most productive environment and working on my personal projects right after finishing work, for half an hour each weekday. No snacks, no breaks. Just get back to work!

Keeping creative work in one block makes things much easier and half an hour (for starters) is not that long. After a while I may extend that period, but I believe now, at the beginning, the most important thing is to reinforce the habit.

The hack works exceptionally well for me and I feel much better being able to work towards self-development every day without noticeable effort. I can also enjoy the rest of the evening, knowing that I already made some progress today.

I think it’s also important to give yourself a weekend break from that routine. Enjoy your free time, do what you love, sleep longer if you need it, code/design/study languages if you really want to and then get back to work on Monday.

Do you have similar experience with productivity hacking? Did you try it yourself? Share in the comments below.

You can also read:
How to understand half of Harry Potter book in any given language
How to increase productivity per square inch of your screen
Logging in with QR codes

Posted 7 months ago - Comments

CodeIgniter and its Download Helper - be careful!

Beware! Just the other day I’ve experienced an unusual bug, that turned out to be a feature of CodeIgniter’s download helper. Downloading files works as expected in 99% of cases, but the remaining 1% are the files without any extension. If you try to download a file without extension, you’ll see a blank screen, no information whatsoever about what went wrong, no error logs to work with and of course no file that you wanted to download in the first place.

Luckily, the issue is really obvious, the fix comes in two flavours and they are both very easy to implement.

The problem is the helper’s design. Take a look at the source code. In the lines 51-54 there’s an if statement that checks if the filename contains a dot = filename has an extension. If yes, continue, if not return false. The script terminates without any explanation, instead of at least notifying us in error logs (or user, by displaying a message) that there’s something wrong.

I can see 2 reasonably clean fixes and 1 hack to get rid of that problem:

Fix no.1 (recommended)
Create a file called MY_download_helper.php in application/helpers/ folder. Copy the contents of /system/helpers/download_helper.php and delete lines 51-54. The good thing about this solution is that you don’t have to refactor any other code - helper will continue processing request and send application/octet-stream header (because of lack of recognised extension). You just have to remember that in the future the original helper can change and you should update your version accordingly.

Fix no.2
This fix is more future-proof, but requires a bit more work and changes the original filename. Create a file called MY_download_helper.php in application/helpers/ folder and paste the following code:

Drawbacks: you have to change force_download() to force_download2() all over the app and downloaded file will have different extension compared to the original file.

Quick hack (not recommended)
Go to file /system/helpers/download_helper.php and simply delete lines 51-54. It’s fast and it works. Why is it not recommended, then? It will break as soon as you update CI to the latest version and the helper will get overwritten by a newer version.

I hope this post will be helpful to me and others desperately googling something like “codeigniter file download problem”.

If you know a better solution to this problem - please, let me know and I’ll post it here!

You can also read:
How to understand half of Harry Potter book in any given language
How to increase productivity per square inch of your screen
Logging in with QR codes

Posted 7 months ago - Comments

Stop Validating Email Addresses With Your Complex Regex - The PHP Way

In his recent article, David Celis argues that we should stop validating addresses with regular expressions, saying, that it’s waste of time and effort. Apparently instead we should just rely on activation email being sent to the address specified by user. Is that really the best way?

Looks like it’s a great moment to share my recent discovery:

filter_var($emailFILTER_VALIDATE_EMAIL);

This simple PHP function will return true or false, based on specified email. You can read more here. I know you all love PHP, it’s so popular after all!

No regex, no mess.

Simple, isn’t it? :)

Posted 8 months ago - Comments

World’s Largest Wi-Fi Network Doesn’t Keep Passwords in Plain Text Anymore - or does it?

It’s a continuation of a story from a few months ago; FON, claiming to be world’s largest Wi-Fi network, also committed the largest crime against password protection: keeping passwords in plain text / reversible form and sending them in plain text via email, if you used ‘forgotten password’ feature.

Looks like FON doesn’t keep passwords in plain text anymore, or (which is unfortunately more likely) just changed the way how “forgotten password” feature works. Either case, FON is not going to send you your old password in an email, if you happen to forget it.

It’s great to see a progress in this space, but would be even better to get a reply from FON: 


You can also read:
How to understand half of Harry Potter book in any given language
How to increase productivity per square inch of your screen
Logging in with QR codes

Posted 9 months ago - Comments

Front-end is a waiter, back-end is a chef

How do you explain a difference between a front-end and a back-end dev to a non-techie? I was speaking with a friend of mine the other day and she asked me what exactly do I do for a living.

Back-end web development I replied.
What does it mean that it’s back-end? I don’t get it she said.
In general, you have front-end and back-end web developers. Let me put it this way: Website that you see on your computer is like a dinner ordered in a restaurant; front-end is a waiter that brings you the dish and back end is a chef who made it –I explained.

What is your favourite way to explain to non-technical people what it means to be a back-end developer?

Reply in comments below or hit me on Twitter.

Posted 10 months ago - Comments