Now I’m not going to talk about user input validation, no that’s something that’s been covered a lot around the web, I’m going to talk about something else.
Let’s imagine you are designing a game, where the user can create a puzzle, for example a maze, and you want to verify that what the user has input is a valid maze, that if played by another player that player will have a chance of winning it. Normally the solution that would come to your (and mine) mind is to try to solve that maze automatically – also we’re not going to talk about the different algorithms for solving mazes – but there is another way to do it that no one told us about in Algorithms 101!
Continue reading “Verifying User Input – Thinking Outside The Box”
Two days ago I needed to generate a PIL image that is made up from repeating a pattern – another PIL image – multiple times, I didn’t find a code online to do it so I just wrote this small code to do it, thought might share it to help somebody out there.
Continue reading “Get Pattern From an Image in PIL Python”
I was working an Android application, and I had an activity that contains a map in it, the map is hosted inside a MapView. The application had to show some pins over the map, the pins locations are obtained from a web service. I had to retrieve the pins locations after the user pans the map or zooms in or out.
Google didn’t provide events for panning and zooming inside MapView class, but you can extend the class and do it your self, and that’s what I did.
Continue reading “Android Map View With Pan & Zoom Events”
It’s been a long time since the last time I blogged about something, and many things have changed since then,
I graduated, got engaged and moved to Dubai.
I have plenty of things in my mind to blog about, many solutions and many tools that I developed that I’d like to share it with everyone, but I haven’t settled down, and my schedule is not stable yet, so I haven’t got enough time to sort things out and start blogging, anyway this post is simple and it doesn’t need much description so I thought I’d share it with you now.
Now let’s move to business, so I was working on an Android application and I needed to log some debug messages, normally I’d use
Log.d(TAG, message); and this will send the message to logcat, but logcat is not useful for long messages, like for example if I needed to log the response I received from a web service, this response might be long and sending it to logcat will truncate it.
Continue reading “Log to a file on computer in Android”
I was upgrading my Django Bookmarks site, and I wanted to list the online users. I searched the internet and I found a simple method, but it doesn’t work properly. So I developed my own method.
Why the simple method didn’t work?
The problem with it is that it depends on the last login date in the user model. This field is updated on every login for the user.
Imagine the following scenario:
* The user X logs in @ 1:00 pm.
* The user X posts a new post @ 1:30 pm.
* The user X comments on a previous post @ 1:35 pm.
* The user X leaves the website @ 1:40 pm.
* The user X comes back to the website @ 3:00 pm.
* The user X is logged in since the session cookie has not expired yet.
* The user X posts a new post @ 3:15 pm.
* A guest enters the website, and looks at the online users corner.
The guest won’t see X’s name in the list of online users, simply because X’s last login date is @ 1 pm, even though user X is now online and he has just posted a new post.
Continue reading “Get Online Users in Django”