$data = array(‘formElement’ => ‘…’,‘subform1′ => array(‘first’ => ‘…’,‘second’ => ‘…’,),‘subform2′ => array(‘first’ => ‘…’,‘second’ => ‘…’,));
Making a “hello word” application for my android mobile phone was in my Todo list for ages, and last night (a flu blocked me home) I spent a couple of course challenging myself to develop a mobile application starting from scratch (including downloading and setting up the needed tools).
I timeboxed my hack-night and I kept things super-simple, opting for the phonegap desktop app to run the server (the mobile phone connects to it, downloads and execute the code in realtime, in beta version and sometimes not refreshing as expected) and for the online compiling tools (free up to one application, a bit slow but they do the job).
The only problem I had was the layout. The phonegap CSS layout didn’t suit my needs and I started with a new one, ending up spending most of the time with font size and media queries to render the application properly on different devices (the app executed via the desktop app rendered differently from the compiled APK one on my Nexus 4).
This was my “hello world” application so I kept it simple, without any complicated phone API interaction, just a calculator for runners (insert distance and time, calculate velocity).
Download & repo
If you want to give at try, download the APK. Source code on github. It asks for lots of permissions, but don’t worry, I just haven’t had the time to take out the one I didn’t need from the default settings.
The app compiled in a 480Kbsize APK file, that is good considering the app wasn’t written in the native Java language, and I haven’t even spent a second trying to strip out the unnecessary stuff (nobody cares about size, do you ? ;-))
These days I needed to read some technical PDFs on my kindle. Unfortunately, due to PDF format reasons, the kindle cannot zoom in the text and auto-wrap it, making it impossible to read a A4 PDF full of text. Here a solution that only uses free software on windows to convert PDF into a text-resizable “kindle” format. It should work for most for the ebooks, keeping images, text format, lists and most of the layout, unless it’s full of tables and complicated structures.
Here the steps
- Only if the PDF is locked with a password: unlock with SysTools PDF Unlocker. Mine was encrypted after purchase to make piracy more difficult. In this case we just want a better copy for ourselves, so no need to worry about removing the password.
- Convert the PDF to RTF with calibre;
- Open the RTF with an editor (the free Kingsoft Writer works great);
- Perform some search and replace, to remove footer and unwanted indentation. For instance in my PDF there was a repeated text from the footer “page 01″, “page 02″ etc. I fixed that by replacing “page ^#^#” with “”. “^#” means any digit. You can find more special symbols in the “special” button dropbown, e.g. to replace tabs and newlines and fix the layout. There must be similar functionalities in any decent text editor you are using;
- Send the document as attachment to your kindleEmail@free.kindle.com, your document will be delivered in a few minutes.
Follow these steps
- Download this file VInk.xml.zip
- Extract the xml file into C:Program Files (x86)Notepad++themes” (create the directory if not existing)
- Restart notepad++
- Go to Settings->Style configuration, select VInk
tested with WIN8, Notepad++ v6.5.3
In this article, a quick guide to the most commonly used Postgres commands
sudo apt-get install postgresql postgresql-contrib
Create superuser from the commad line
sudo -u postgres createuser –superuser digideps
Create database from command line
sudo -u postgres createdb newDatabaseName
Login via command line (postgres is the default root user)
sudo -u postgres psql [dbname]
DEVELOPER OPERATIONS / QUERIES
Change password of the postgres user
Grant permission on db1 to user1
grant all privileges on database db1 to user1
List tables in a db
Export db snapshot
sudo -u postgres pg_dump dbname —clean > dump.sql
Import db from snapshot
sudo -u postgres psql dbname < dump.sql
A few days ago I got involved in a chat about the usage of Object-oriented design patterns. I brought up the problematic of their usage when not needed, that ends up in adapting the code to the pattern and altering it, risking to increase its complexity. I mentioned an example of usage of the Observer design pattern, that I’ve seen used even where one object A (Subject) just needed to keep an array of reference of objects B (Observers), but B didn’t actually need to refer back to A.
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
In this post, I’ll expose a case where the usage of that pattern is very simple to understand: a Newsletter system, with senders (Subject) and subscribers (Observers).
In this example, we have two users, John and Mike who both subscribe to the NewsletterSender (Subject). When the email is sent, both are notified by
NewsletterSender::notifySubscribers() that iterates the users and call their
update() passing its reference. Via this reference, the users will then be able to call the getter to read the email. So, John and Mike will both receive the reference to the NewsletterSender, John will print out the email text, but Mike only decides to say that there is an email (different implementation).
One of my client recently needed to implement an application-level encryption for some existing applications.
Unfortunately, the design pattern used for the database layer obliged me to write an independent script to browse the database and encrypt the data for each user using a user-specific two-way encryption key.
So, I ended up writing a simple utility class that applies a user-defined function (modifies) to the defined columns and records (via a filter query) of each database table.
It can be used for any relational database server supported by PDO (MySQL, SQL Server, MySQL, Oracle). I’ve only used it with MySQL but it should work smoothly with all the others.
An example of usage is in the README, hope it’s clear enough.
You can basically use this to mass editing Db records with a function that is NOT easily implementable with a simple MySQL Query, e.g. encrypt the data with a custom PHP function.
File uploading normally requires client validation (mainly as a UI improvement) and server validation (in case the client validation is bypassed/hacked).
<input type="hidden" name="MAX_FILE_SIZE" value="2621440"/>
The idea is accessing the
files JS property of the input field and read the file size on the ‘change’ event (when a file is selected from the user). If the selected files exceeds the max size, I simply display a clear user warning and disable the
submit button. I’ve created a generic script that automatically listens to the
change event for any file upload element, and reads the max upload size in bytes from the
MAX_FILE_SIZE HTML input hidden element in the same form.
Server side validation (PHP)
Just set the desidered value for ‘upload_max_filesize’ and ‘post_max_size’ PHP settings (php.ini). Alternatively, if you need application specific settings and you use apache as webserver, add the following lines into the
.htaccess in your webroot
php_value upload_max_filesize 25M php_value post_max_size 25M
The web application I’m working on (PHP 5.3, zf2, Doctrine2, on MySQL/Apache) has recently raised interest from the clients and it now needs to be installed on their premises, often a Windows server( arghhh!). That meant we had to make the application compatible with both MySQL and SQL-Server.
Here I summarize the changes and the solutions we adopted.