When it comes to structuring your MySQL database you have one of two choices. You can normalise your schema or you can denormalise it. Both have their advantages and trade-offs, but when should you use one over the other?
Normalise Essentially normalising your schema means breaking it into multiple tables. In a traditional application you might have the following tables; users, categories, pages, profiles, profilemeta, tags, media, pagescategories and so on. Normalisation prevents redundant data and keeps things lean.
Recently whilst building a Laravel 4 application, I needed to validate some monetary values in the form of: 10.00, 5.00 and so on. Surprisingly Laravel’s default validation options don’t account for monetary values, so you have to use a regular expression instead.
Using the numeric validation type also works as I believe it uses PHP’s in-built function is_numeric() to validate numbers. I prefer regular expressions because you have greater control over what is allowed and isn’t.
There is a lot of confusion when it comes to MySQL and views versus stored procedures. Many people often wonder what the difference is between the two of them?
Views It is all in the name. Views are essentially virtual tables comprised of pre-written SQL statements. You might have a view for displaying users who have joined in the last couple of days. Think of views as a means of getting data from your database without having to write or call queries constantly.
Now that I use a Mac for work I use Sequel Pro for administering databases (at home I use Navicat, but can’t warrant the expense for work paying for a Mac licence). I recently needed to import an .sql file that I dumped via the command line on a remote server. The size of the database dump file was almost 400mb (it’s a big database).
I encountered an issue where the database dump would get half way through the importing process and then error out about the encoding being incorrect. The database dump file I am pretty sure was UTF-8 and it seems autodetect failed to address the issue, then I got digging and worked out the problem.
I actually really like the Blade templating parser that Laravel ships with, but I know there are many who do not like it. Funny story about Blade, it was inspired and originates from .Net templating called Razor. Razor…Blade, get it? Razorblade.
Today we are going to be making Laravel use Twig instead of Blade. If you already use Twig in other PHP projects or come from a Django/Python background, then understandably you probably would want to use Twig over Blade. Different syntax but the same result.
Recently I was tasked with writing a regular expression that would check for a valid Australian phone number for both landline and mobile phone variants whilst allowing for different formats (spaces, no spaces, international dialing code, brackets, area code, no area code).
The below regular expression code and subsequent tests are for Australian mobile and landline numbers only, but could be tweaked to work for other countries as well.
The expression `// This is our bread and butter expression var phoneExpression = /^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/; // Valid var phoneNumber1 = "0411 234 567"; var phoneNumber2 = "(02) 3892 1111"; var phoneNumber3 = "38921111"; var phoneNumber4 = "0411234567"; // Invalid var phoneNumber5 = "3892 11"; var phoneNumber6 = "diane 0411 234 567"; var phoneNumber7 = "bob"; if (phoneNumber1.match(phoneExpression)) { console.log('Valid 10 digit mobile number'); } if (phoneNumber2.match(phoneExpression)) { console.log('Valid 8 digit landline number with circular brackets wrapping area code'); } if (phoneNumber3.match(phoneExpression)) { console.log('Valid 8 digit landline number with no spaces or area code'); } if (phoneNumber4.match(phoneExpression)) { console.log('Valid 10 digit mobile number with no spaces or international dialing code'); } if (!phoneNumber5.match(phoneExpression)) { console.log('Invalid landline number which is 6 digits instead of 8'); } if (!phoneNumber6.match(phoneExpression)) { console.log('A name and space before a valid spaced 10 digit mobile number'); } if (!phoneNumber7.match(phoneExpression)) { console.log('No valid number entered, a name appears to have been entered instead'); }` Supported formats: 0411 234 567, +61411 234 567, (02) 3892 1111, 38921111, 3892 111, 02 3892 1111
Recently whilst trying to use the Zurb Foundation Abide validation component I ran into an issue where I was getting a bizarre error involving form validation.
The error message might vary, but it’ll look similar to this: Error: Syntax error, unrecognized expression: [data-‘Times New Roman’-abide]
The issue stems from the fact Foundation utilises an internal namespace. All you have to do is set the namespace to be blank and everything appears to start working:
At work our internet connection is painfully slow for the moment while we sort something better out and I ran into a rather interesting quirk whilst using Composer and timeouts.
I was trying to install Laravel and because of the sheer number of components it got part of the way through and then would display some error message about exceeding the timeout limit of 300 seconds (5 minutes).
The reason for this appears to be due to the fact my Internet connection is mega slow and some components being largish in size. When calling composer update or composer install you just need to specify a higher timeout value.
Currently Bootstrap is still the preferred choice for prototyping web applications and rapidly getting a MVP out the door. As great and undeniably helpful it is, Bootstrap is far too opinionated to be a viable front-end CSS solution for a lot of people. It throws the kitchen sink at you and its default style.
There are numerous themes for Bootstrap and means of creating your own styles, but as someone who’s now worked with Bootstrap quite extensively, it feels like you’re constantly overriding base styles (even using Bootstrap Sass won’t help you).
Newcomers to Node.js will have run into this issue a couple of times. You get your setup working, you’ve built a little application and on your server you start your Node app, but then you close the terminal window and your application stops.
When I first started using Node.js, this is the first thing I Googled, “How do I keep a Node.js app running after I close the terminal console?”