Snippets

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

Snippets / CSS

@font-face Firefox Cross Domain Problem

The other day I encountered a problem when using custom web fonts for use on a project. I had my project content on mydomain.co.uk, I also had my images on a seperate subdomain - images.mydomain.co.uk and finally I had my fonts on another subdomain fonts.mydomain.co.uk. My Problem with Firefox I then tried to use these web fonts ...

29th Sep, 2011 | » Read more Snippets like this | » Read More

Snippets / Linux

Colour highlighting - grep search results

I always find it difficult scanning through hundreds of lines of search results trying to match the keyword you specified. By default linux doesn't colour code grep search results, but there's an option to change this. By saving some settings inside your .bash_profile (file that get's called upon your login, usually resides within /...

25th Sep, 2011 | » Read more Snippets like this | » Read More

Snippets / Linux

Securing Image Upload directories (777)

It is considered risky to leave directories in your website with the access permission 777, which allows anybody to upload files to this folder. However many PHP projects such as Wordpress require these folder permissions in order to function correctly. I find it helpful to create a .htaccess file to go inside the image upload director...

25th Sep, 2011 | » Read more Snippets like this | » Read More

Snippets / Linux

Send Email from Linux Command Line

Sending emails from the linux command line can be very useful when creating shell scripts to inform people of the completion of a scheduled crontab. Using Linux's "mail" command You can send emails by the following; mail -s "Subject of Message" your@emailaddress.co.uk < /dev/null This simplys sends a blank message to th...

24th Sep, 2011 | » Read more Snippets like this | » Read More

Snippets / MySQL

Backup all MySQL databases into seperate files with crontab

It's highly recommended to keep a backup of all your data and with the following script you can setup an automated task to create a weekly backup of your data without having to manually run it; with linux! The Shell Script "db-backup.sh" Next Step Add to Crontab In order for the script that we have created to be executed automa...

24th Sep, 2011 | » Read more Snippets like this | » Read More

Snippets / Plesk

Delete emails from email queue in PLESK

The GUI for PLESK's CMS is quite limited when you want to delete a large number of emails in one batch without crashing the website. Through a linux command line you can filter and delete messages by either their email address, subject, from or to targets. How to use qmHandle qmHandle -h #################################...

21st Sep, 2011 | » Read more Snippets like this | » Read More

Snippets / Linux

Turn on syntax highlighting VIM

If you want to turn on syntax highlighting for vim editor on Ubuntu such edit the main config file here# open vim settings vim /etc/vim/vimrcThen uncomment " syntax on " around line 20# leave setting syntax onIf you just wanted to turn it on just while you were editing a file (not a permanent solution):syntax on The...

15th Jul, 2011 | » Read more Snippets like this | » Read More

Snippets / Linux

Remember Alias binds - Linux

Binding Aliases in linux is a very useful way shorten your workload and the amount you type!In order to save your alias binds you need to save them in the .profile file which should be in the login root directory.An Example# open file to edit vim .profile # add alias bind alias zf=/path/to/shell/script.sh Remember to save the file a...

15th Jul, 2011 | » Read more Snippets like this | » Read More

Snippets / PHP

Strip non-alphanumerical characters with PHP

In the past, when I first started using PHP in order to filter out bad characters for file uploads, seo friendly URL names and other things I created an array of bad characters. This is obviously not an ideal situation as the amount of characters that people or scripts can inject is ridiculously high, so adding a new element ...

14th Jul, 2011 | » Read more Snippets like this | » Read More

Snippets / MySQL

Filter results by todays date - MySQL

MySQL is a very powerful open source database and there was no suprise when I found there was a way to retrieve records from a database that expired at @ 11.59 of the "end_date" field. You can alternatively do this via php date() function as well.The SolutionAll I wanted to happen was a simple way to display meetings that weren't expired,...

12th Jul, 2011 | » Read more Snippets like this | » Read More