Syncable Host File to Make the Internet Suck Less

We've all been there. A friend sends you a link to an internet shock site. If you're familiar with the hosts file on your machine, then you can use this large sync-able list to compliment your own rules. If you using a Mac, you can use the nifty Gas Mask program to edit your hosts file without having to jump into a shell.

URL for the hosts file is:

http://someonewhocares.org/hosts/hosts 

As well as IPv6 files, there are a few other formats available as well.

We've all been there. A friend sends you a link to an internet shock site. If you're familiar with the hosts file on your machine, then you can use this large sync-able list to compliment your own rules. If you using a Mac, you can use the nifty Gas Mask…

Read More

Virtualmin - FTP/SFTP File Writing Errors

If you're using Virtualmin on your servers and have a few odd FTP error messages (happened for me using SFTP too), then it's one of three things.

  • Disk quota for the hosting account has exceeded
  • Server has ran out of memory
  • The configuration options below need to be set in /etc/proftpd.conf

As mentioned above, I found that these two options added into /etc/proftpd.conf fixed the file write issue in some cases:

AllowRetrieveRestart on
AllowStoreRestart on

If you're using Virtualmin on your servers and have a few odd FTP error messages (happened for me using SFTP too), then it's one of three things. Disk quota for the hosting account has exceeded Server has ran out of memory The configuration options below need to be set in…

Read More

Useful Notes for phpinfo() & Capturing Output of phpinfo()

I recently needed to capture the output of phpinfo() for a to a log upon install. I'd been able to do this in the past but couldn't quite remember how I managed it. This is where ob_start() and ob_flush() come into their own.

To get the contents of phpinfo(); into a variable, you can use the following:

ob_start();
phpinfo();
$strPhpInfo = ob_get_contents();
ob_clean();

The variable $strPhpInfo will now contain the output from phpinfo().

A side note, if you only want the variables section of phpinfo(), then use:

phpinfo(32);

and it'll give you just that in the output. You can read more about the other values you can pass to phpinfo() at php.net/manual/en/function.phpinfo.php.

I recently needed to capture the output of phpinfo() for a to a log upon install. I'd been able to do this in the past but couldn't quite remember how I managed it. This is where ob_start() and ob_flush() come into their own. To get the contents of…

Read More

PHP ActiveRecord - Get Last Query

I recently had to do some work on an older site that used the PHP implementation of ActiveRecord. One of the issues I had was that the queries being ran weren't produced the expected result. I found two commands to help with this an issue the last run query:

If you're within a model, you can do:

echo self::connection()->last_query;

and if you're outside your model, you can use:

echo model::connection()->last_query; 

I recently had to do some work on an older site that used the PHP implementation of ActiveRecord. One of the issues I had was that the queries being ran weren't produced the expected result. I found two commands to help with this an issue the last run query: If…

Read More

Install Old Version of Laravel 4.1.X for PHP 5.3 Servers using Composer

If you need to install an older version of Laravel for use with a server that has PHP 5.3.X for example, you can do so using the following command:

composer create-project laravel/laravel project-directory 4.1.*

This is useful when you can't upgrade the version of PHP but still wish to use Laravel.

If you need to install an older version of Laravel for use with a server that has PHP 5.3.X for example, you can do so using the following command: composer create-project laravel/laravel project-directory 4.1.* This is useful when you can't upgrade the version of PHP but…

Read More

Almost Time for Amsterdam!

Preparing for Laracon EU 2013

It's a couple of weeks away until I head off for Amsterdam.

I'll arrive in Amsterdam on the 25th August of August and depart on the 31st. I'll be in Amsterdam to attend the fantastic Laracon EU conference along with a work colleague.

We're currently in the process of making plans of what to do while we're there, we got a lot of the common tourist things done last year, so this year it'll be good to see some new places.

If you have experience of renting a boat of in the 'dam too, I'd like a chat.

If you've got any suggestions, leave them in the comments below. If you know anyone in Amsterdam with good local knowledge, point them in the direction of this post too!

It's a couple of weeks away until I head off for Amsterdam. I'll arrive in Amsterdam on the 25th August of August and depart on the 31st. I'll be in Amsterdam to attend the fantastic Laracon EU conference along with a work colleague. We're currently in the process of making…

Read More

Interactivity for Payment Forms

Interactivity for Payment Forms

A short while ago now I read an article by Michael Villar of Stripe on using animations when users are completing payment forms.

Villar put forward the argument that this improves the user experience.

Below is a demonstration of doing that.

Interactivity for Payment Forms A short while ago now I read an article by Michael Villar of Stripe on using animations when users are completing payment forms. Villar put forward the argument that this improves the user experience. Below is a demonstration of doing that. …

Read More

Laravel: Filter Every Array Element with a Closure

I always forget about how awesome Laravel Collection's are. I came across this gem when needing to run a filter on every element of an array. I think it may of been Dayle's book that first informed me of them. For example, if you have an array of fruits that you want to filter down, you can do the following:

// Create an array of fruits
$array = ["banana", "apple", "orange"];

// Transform the array into a Collection object
$collection = new Illuminate\Support\Collection($array);

// We don't like banana's anymore, so we're going to filter them out
$no_bananas = $collection->filter(function($element) {
    if ($element != "banana") return true;
});

// Dump out our array now, and we'll see the banana's are gone
dd($no_bananas);

I always forget about how awesome Laravel Collection's are. I came across this gem when needing to run a filter on every element of an array. I think it may of been Dayle's book that first informed me of them. For example, if you have an array of fruits that…

Read More

Laracon US 2014

If you haven't noticed yet, the Laracon US 2014 videos have been posted online for a short while now, you can grab them over on Userscape's website at http://userscape.com/laracon/2014/.

One talk of note, which I've recommended to a lot of people is by Greg Baugues, titled "Devs and Depression".

If you haven't noticed yet, the Laracon US 2014 videos have been posted online for a short while now, you can grab them over on Userscape's website at http://userscape.com/laracon/2014/. One talk of note, which I've recommended to a lot of people is by Greg Baugues, titled…

Read More

Adding Google Sitemap's to Ghost Blogging Platform

I recently wanted to replace my statically generated sitemap.xml file with a dynamically one generated by ghost. It ended up being pretty trivial to do, but the following two links helped immensely. At present, it's a hack to the core which you'll have to repeat if you upgrade - but that's a small price to pay for having your sitemap generated dynamically.

For adding sitemap support:
http://tstrimple.com/hacking-ghost-adding-dynamic-sitemap-xml/

For updating the format/count:
http://www.mathachew.com/blog/customizing-your-dynamic-sitemap-in-ghost/

I recently wanted to replace my statically generated sitemap.xml file with a dynamically one generated by ghost. It ended up being pretty trivial to do, but the following two links helped immensely. At present, it's a hack to the core which you'll have to repeat if you upgrade -…

Read More

A Love of Brasil

I've seen a lot of people unhappy with Brasil and their football team the past few days. There is a piece of me that deals with that unhappiness and disappointment of events in a way that allows me to deal with things.

If you've met me in person, played football with me or spoken to me about sports then I've probably at some point mentioned Brasil. I'll be travelling over to Brasil later this year and I'm sure that I'll love it. I have an incredible amounts of friends and people close to me there, it'll be good to finally spend time learning about the country and life in it.

Both Brasil as a country and the friendly nature of Brazilians has been a part of my admiration since I was a kid and this was mainly influenced by one person, an idol of mine: Ronaldo Luís Nazário de Lima.

I had a childhood that wasn't like most kids. I spent most of it in a wheelchair, unable to walk and dealing with the effects of Legg–Calvé–Perthes Disease which prevented me from walking normal until I was about 12 years old. When I started high school at 11, I was on crutches and then a walking stick. I missed out on the whole childhood adventure of climbing trees, playing football and doing the usual things that children do.

For my life and career, this served me well. I learned to program basic at this time and started to learn a lot about computing which has done me well considering that I'm now a programmer as a professional.

Football seemed to touch something deep inside my soul. As soon as I was able to walk, then run - I began to play football. This is now one of the most important parts of my life, I have been told that I will be unable to walk by doctors three times in my life so far. I still prove them wrong and will continue to do so, until I actually can't. I have no idea if I'll be walking by the time I am 40, 50, 60 or older. I hope that it will be longer, of course. I have no control over that though, it all depends on how well my hip manages to deal with life. My doctor would prefer me to have a hip replacement now, to which I object completely. I prefer to deal with the pain of having my 'real' hip and being able to play the sport that has given me so much.

As a human, I think I've overcome quite a lot to get to where I am now. The inspiration for that and the never giving up came from years of watching and learning about Ronaldo. This is a professional sports player that has had career threatening injuries more times than people care to remember. There is an image that sticks into my mind of Ronaldo while he was playing for Inter Milan on 21 November 1999 against Lecce felt his knee buckle, he was out for a long period of time.

I sat watching the moment I'd waited for, on the 12th April 2000 Ronaldo was named a substitute for the game against Lazio in the Copa Italia final. Ronaldo played seven minutes in total. He took the ball on the edge of the D and collapsed. His knee had given way again. There is a now famous photo of Ronaldo laying on the pitch in anguish.

Ronaldo Injury

This image has stayed with me for life. I've had serious knee injuries myself and serious ankle injuries too. I never gave up hope that I would play again and always believe that I would be able to recover from them. In Ronaldo's case, he not only came back from these awful injuries, he resumed his career after them. The attitude and commitment to do that is amazing to me and part of the reason why he has remained my idol throughout life.

If you ever wondered how severe Ronaldo's knee injuries have been, look at the photo below.

Ronaldo's Knee

I read an interesting post a few days ago, which talks about what Ronaldo could have been which I'd recommend reading.

Always remember, that no matter how bad things may be at present, they can always get better.

I've seen a lot of people unhappy with Brasil and their football team the past few days. There is a piece of me that deals with that unhappiness and disappointment of events in a way that allows me to deal with things. If you've met me in person, played football…

Read More

MariaDB: Set Maximum Server Connections via Query

If you're a MariaDB user and need to set the max_connections variable a little higher while the server is running, you can use the following SQL query:

# This will give you the current mac_connections setting
select @@max_connections;

# Set the maximum connections allow for MariaDB
set global max_connections = 200;

# To see that the variable has been changed, run the following query again:  
select @@max_connections;

If you're a MariaDB user and need to set the max_connections variable a little higher while the server is running, you can use the following SQL query: # This will give you the current mac_connections setting select @@max_connections; # Set the maximum connections allow for MariaDB set global max…

Read More

ncftp: Recursive File Get

A while ago I wrote a post about using the basic ftp command to recursively fetch remote FTP files, it seems this doesn't completely fetch them recursively. A great little program called NCFTP will do this accurate and pretty quickly. Install NCFTP if you haven't already, then run the program:

ncftp

This will give you a prompt, at which type the following:

set save-passwords yes

Which will allow the program to save your password while its working and transferring files. Open a connection to your FTP server by using the following at the command prompt:

open -u ftp_username ftp_host

It'll ask for a password, enter it and then it'll go away and connect. To then download your files recursively, enter the command:

bgget -r file/path

and once you've finished queuing files, type:

bgstart

to begin the transfer and NCFTP will go ahead and download all your queued files.

A while ago I wrote a post about using the basic ftp command to recursively fetch remote FTP files, it seems this doesn't completely fetch them recursively. A great little program called NCFTP will do this accurate and pretty quickly. Install NCFTP if you haven't already, then run the program…

Read More

Titanium: Remove All Children of View

I picked up this function somewhere a while ago, it's useful when you want to remove all the children elements of a view in Titanium.

function removeAllChildren(obj) {
    var c = obj.children.slice(0);
    for (var i = 0; i < c.length; ++i) {
        obj.remove(c[i]);
    }
}

I picked up this function somewhere a while ago, it's useful when you want to remove all the children elements of a view in Titanium. function removeAllChildren(obj) { var c = obj.children.slice(0); for (var i = 0; i < c.length; ++i) { obj.remove(c[i]); } } …

Read More

Apple Swift Programming Language Manual Download

After Apple's impressive WWDC keynote earlier, you can download the reference manual for the Swift programming language for iBooks using the following URL:

https://itunes.apple.com/gb/book/swift-programming-language/id881256329?mt=11

After Apple's impressive WWDC keynote earlier, you can download the reference manual for the Swift programming language for iBooks using the following URL: https://itunes.apple.com/gb/book/swift-programming-language/id881256329?mt=11…

Read More

Linux: Find All Modified Files in Last X Days

Nifty linux command to remember:

$ find . -mtime -3 -ls /

This will display all the files modified in the last 3 days. You can change 3 to suit as many days as you require.

Nifty linux command to remember: $ find . -mtime -3 -ls / This will display all the files modified in the last 3 days. You can change 3 to suit as many days as you require.…

Read More

How to Detect Version of CS Cart Websites

Quick tip, if you need to find the version of a CS Cart based website, simply append ?version to the query string, so for example if you shop name is mysupershop.co.uk, point your browser at:

http://www.mysupershop.co.uk/index.php?version

You'll be presented with a page that notifies you which version of CS Cart is installed and running, similar to:

CS-CART: version 2.1.4 PROFESSIONAL

Quick tip, if you need to find the version of a CS Cart based website, simply append ?version to the query string, so for example if you shop name is mysupershop.co.uk, point your browser at: http://www.mysupershop.co.uk/index.php?version You'll be presented with a…

Read More

Laravel Homestead: Add Enviroment Variables to Nginx

If you wish to set your enviroment by using server enviromental variables with the new Laravel Homestead you can do the following:

Edit the website configuration name, by running the following command within the VM:

$ sudo nano /etc/nginx/sites-available/local.dev

Within the location ~ \.php$ { block, update your configuration to resemble this:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param LARAVEL_ENVIROMENT "dev";

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

Now restart Nginx

$ sudo /etc/init.d/nginx restart

Next, edit your bootstrap/start.php file and update the method to detect enviroment:

$env = $app->detectEnvironment(function(){
    return getenv("LARAVEL_ENVIROMENT");
});

Now you can set your enviroments per server.

If you wish to set your enviroment by using server enviromental variables with the new Laravel Homestead you can do the following: Edit the website configuration name, by running the following command within the VM: $ sudo nano /etc/nginx/sites-available/local.dev Within the location ~ \.php$ { block, update your configuration…

Read More

MySQL Procedure: Drop All Tables in Database

If you ever need a progmatic way to drop all tables in a database, you can use the following stored procedure:

DELIMITER $$

DROP PROCEDURE IF EXISTS `drop_all_tables_from` $$

CREATE PROCEDURE `drop_all_tables_from`(IN schema_target VARCHAR(128))
BEGIN
    DECLARE table_list TEXT;

    SELECT
        GROUP_CONCAT(`TABLE_NAME`)
    INTO
        table_list

    FROM `information_schema`.`TABLES`
    WHERE
          `TABLE_SCHEMA` = schema_target;

    IF table_list IS NOT NULL THEN
        SET @drop_tables = CONCAT("DROP TABLE ", table_list);

        PREPARE stmt FROM @drop_tables;
        EXECUTE stmt;
        DEALLOCATE PREPARE stmt;
    END IF;

END $$

DELIMITER ;

To use, simply call the procedure with the database name as the parameter:

CALL drop_all_tables_from("database_name"); 

Note: This will drop all tables, without confirmation for the database name provided.

If you ever need a progmatic way to drop all tables in a database, you can use the following stored procedure: DELIMITER $$ DROP PROCEDURE IF EXISTS `drop_all_tables_from` $$ CREATE PROCEDURE `drop_all_tables_from`(IN schema_target VARCHAR(128)) BEGIN DECLARE table_list TEXT; SELECT GROUP_CONCAT(`TABLE…

Read More

Laravel: Prevent Sessions for Routes via a Filter

I needed to prevent Laravel from using sessions for a few API endpoints in an app, this is how I did it:

Route::filter('session.remove', function()
{
    return Config::set('session.driver', 'array');
});

This can be used quite easily with a route or route group:

Route::group(array(
    "prefix" => "api/v1",
    "before" => array("session.remove")
), function() {
    Route::get('/search', 'SearchController@getPerformSearch');
});

I needed to prevent Laravel from using sessions for a few API endpoints in an app, this is how I did it: Route::filter('session.remove', function() { return Config::set('session.driver', 'array'); }); This can be used quite easily with a route or route group: Route::group(array( "prefix" =>…

Read More