Snippets

Here's some of my tips, tweaks and tuts, ranging from PHP, Linux, MySQL and more!

Snippets / PhoneGap

Virtual Keyboard PhoneGap Overlapping Content

Recently I came across a problem when building a mobile app with a form. When I focused on a lt;input> element the keyboard just completely overlapped all the majority of the content and made it near impossible to see what you were writing.

First I added a preference for the keyboard setting in my config.xml and this worked in the latest version of android (4+) but not in 2~.


 

Eventually after hours of googling I found a StackOverFlow thread which answered the problem. It was that my app was fullscreen. So I just needed to update the confix.xml and set fullscreen to false


 

10 years ago / Read More

Snippets / PhoneGap

Config changes hydrated apps (PhoneGap Build)

It took me a while to figure out that if you have a app with hydration enabled on PhoneGap Build, it will not display any significant changes you make to the config.xml without completely re-building the app or deleting and re-adding it.

Delete the App

delete phonegap app

Re-Add the App

re-add phonegap app

10 years ago / Read More

Snippets / PhoneGap

Play local audio on iOS device with PhoneGap

Recently I had a problem getting audio files to play in iOS with PhoneGap (2.9.0) while it was working perfectly fine on android devices.

Here's the example code I was using:

// console audio after playing
function audio_win(response)  { console.log('Audio FAILED' + response); }
function audio_fail(response) { console.log('Audio WINNER' + response); }

// file path for ios 
// src = file:///var/mobile/Applications/271BF94B-8540-43FB-944E-39E5AC7A9A3F/[APP-PACKAGE-NAME]/www/sounds/filename.mp3
var src = location.origin;

// call the media function
var audio = new Media(src, audio_win, audio_fail );

// PRODUCES ERROR
audio.play()

Here's the updated fixed version:

// console audio after playing
function audio_win(response)  { console.log('Audio FAILED' + response); }
function audio_fail(response) { console.log('Audio WINNER' + response); }

// file path for ios 
// src = file:///var/mobile/Applications/271BF94B-8540-43FB-944E-39E5AC7A9A3F/[APP-PACKAGE-NAME]/www/sounds/filename.mp3
var src = location.origin;

// ADDED
// remove file:// if on ios
if( device.platform === 'iOS' ) {
    src = src.replace('file://', '');
}

// call the media function
var audio = new Media(src, audio_win, audio_fail );

// WORKS!
audio.play()

Don't forget the PhoneGap APIs

In order to use the global variable device you will have to add the following in your config.xml, also remember you need to add the media API.




10 years ago / Read More

Snippets / JavaScript

List all global variables in JavaScript

An easy way to list all of the global variables available the window object:

keys(window);

// returns array obj
// ["window", "location", "external", "chrome", "document", "$", "jQuery", "_gaq"]

10 years ago / Read More

Snippets / Plesk

Outgoing Mail Treated as "local" Plesk

So I originally came across this problem with a PLESK server I was maintaining. For this example we can call it domain.com. However, the MX records for domain.com are NOT set to the plesk server but to other external servers. (So there's no need for PLESK to handle mail) This domain.com's mail settings in PLESK were also disabled. If I tried to send a message to any *@domain.com email address, nobody would receive an email.

The Reason

I found out eventually that it was because PLESK was treating domain.com as local (internal mail routing) so I needed to stop this occuring.

The solution

Edit the "locals" plesk file and then remove the domain.com reference.
vim /var/qmail/control/locals

Persisting Problems?

If the above solution is not successful it's most probably worth checking the following files for domain.com references.
/var/qmail/control/virtualdomains

/var/qmail/control/rcpthosts

/var/qmail/control/smtproutes

12 years ago / Read More

Snippets / Linux

Fix: Firewall is stopped (iptables) in linux

I came across this quick fix when trying to restart the firewall for my linux box.

$ service iptables status
Firewall is stopped.

Trying to start it?

The obvious solution was to just do service iptables start but this didnt do anything.

Solution

We just need to save the firewall rules before we start the service.

$ service iptables save
Flushing firewall rules:  [  OK  ]
Setting chains to policy ACCEPT: filter [ OK  ]
Unloading iptables modules: [  OK  ]

$ service iptables start
Applying iptables firewall rules: [  OK  ]

12 years ago / Read More

Snippets / HTML

Make a whole table rows a hyperlink with HTML

The other day when I was creating a new mail inbox feature for a certain website I needed to somehow make a row of information all clickable in order to take you through the full details of that particular message.

I thought there's probably a way I could do this with JavaScript but surely there was an easy way to do this with normal HTML.

The HTML

Unfortunately one drawback to this method is to have to add the same link inside every <td>, making this process slightly repetitive.

Re: Central Heating Hi John, further to our correspondence regarding the quote for the underfloor heating... 20th Jan

The CSS

In order to create the allusion that the whole row is clickable, you need to set both the <td> and the <a> the same "line-height", also set the traditional inline element <a> to display:block; and finally so there's no gaps between cells set "border-spacing" to 0

table { border-spacing: 0; padding:0; }
table td { line-height:24px; }
table td a { display:block; line-height: 24px; } 

12 years ago / Read More

Snippets / MySQL

Exclude "The", "An" & "A" from MYSQL Ordered list

The aim was to display results from my database in alphabetical order and not having words such "an" or "the" to impact on the alphabetical order (similar to iTunes album order).

So for example

The Doors would be displayed in the "D" artists

A Solution (Slow one)

One way of doing this I thought we could trim the appending name of the artist if it matched any preset criteria. This solution is a temporary one until I find a quicker method!

SELECT artist_name
FROM artists
ORDER BY TRIM( 
LEADING "A "
FROM TRIM( 
LEADING "An "
FROM TRIM( 
LEADING "The "
FROM LOWER( artist_name ) ) ) ) 
LIMIT 30

A Problem

When getting the results, the query does seem to take a little while

100 rows in set (0.29 sec)

12 years ago / Read More