Categories Tags

Blog

I recently started playing more and more with PHP7.1.

To begin my experience, I started by aliasing on my command shell as follows:

alias php='/Applications/MAMP/bin/php/php7.1.0/bin/php -c "/Library/Application Support/appsolute/MAMP PRO/conf/php7.1.0.ini"'

I thought ok cool, with it being on my path as “php” composer will automatically pick up that version.  However, it did not.  I kept getting the following error message:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - package/name dev-master requires php ^7.0 -> your PHP version (5.6.28) does not satisfy that requirement.
    - package/name dev-master requires php ^7.0 -> your PHP version (5.6.28) does not satisfy that requirement.
    - Installation request for package/name *@dev -> satisfiable by package/name[dev-master].

Finally, I decided to do a bit more digging.  In doing so, I determined that composer was getting PHP from my path.  However, only an un-aliased version of it.  This meant that it ended up pointing back to the base install of PHP 5.6.

So, what I needed to do to fix the problem, was to update the order in which it finds PHP on the path.  More specifically, in my “.profile” file, I updated the PATH variable to say the following:

export PATH="/Applications/MAMP/bin/php/php7.1.0/bin/:$PATH"

And that is all.  I am now able to successfully run composer with PHP7.1.

Posted in php

Tags:

In a *nix systems, you are able to change the actual permissions by using a command line command. The problem with this is the fact that you don't have a nice GUI like Windows does to click and choose what permissions goes where.

The "777" actually represents two things. Each digit in the number represents a bit string for the actual permissions (see below), but also each character means something. The sevens are broken down as follows:

  1. Digit 1 = user
  2. Digit 2 = group
  3. Digit 3 = world

Depending on what each are set to, the user/group/world will have the permissions that it was set to.

Now, what do each piece of the bit string mean? A "1" means that the value is allowed and a "0" means that it is not allowed. So, starting from left to right:

  1. Digit 1 = Read
  2. Digit 2 = Write
  3. Digit 3 = Execute

So, if you want a user to have read permissions only on the file, you would have a binary string of "100" which is 4, so the file permission would be 4xx (where xx doesn't matter because we are only talking about user).

The lazy man's file permission is "777" because you are essentially everyone access to do whatever they want to do with the file.

Posted in tools

Tags:

Today, I realized that I had accidentally placed the TEMPDB on the wrong disk drive. At first I thought that I may need to re-install SQL Server 2012 because it is a system database. But, luckily you do not!

All I ended up having to do is the following:

  1. Run this script:

USE master

GO

ALTER DATABASE TempDB MODIFY FILE (NAME = tempdev, FILENAME = 'd:\data\tempdb.mdf')

GO

ALTER DATABASE TempDB MODIFY FILE (NAME = templog, FILENAME = 'e:\data\templog.ldf')

  1. Restart SQL Server

And BAM. The TEMPDB has been relocated for you J

Referencehttp://blog.sqlauthority.com/2007/04/01/sql-server-tempdb-is-full-move-tempdb-from-one-drive-to-another-drive/

Posted in sql-server

Tags:

Today I ran into an issue where the Object Explorer wasn't responding when I tried to get the properties of a database, but I was curious what the recovery model of my database was. Instead of waiting until the process which was blocking access to the database properties, I queried the database itself to see what the recovery model was.  The query to do so was fairly straightforward:

SELECT DATABASEPROPERTYEX(DB_NAME(), 'RECOVERY')

Posted in sql-server

Tags:

So, for the past little while I've been plagued with the inability to copy and paste code/data on a remote machien. This has been bothering me for the last little bit. Finally today I decided to actually try to resolve the issue.

So, I went to my trusty source Google to tell me how to fix the issue, and I found out a little more about how it works.

Apparently when you RDP to a server, and try to copy and paste, it is using an application called "rdpclip.exe". When copying and pasting fails, all you really need to do it restart this application.

So, to do that you can just type into command prompt the following:

taskkill.exe /F /im rdpclip.exe & rdpclip.exe

This will kill any of the currently active versions of the application, and then restart it.

Happy pasting!

Reference: http://patricksheedy.net/softwareblog/2008/01/28/fix-cut-and-paste-problems-with-remote-desktop/

Posted in tools

Tags:

No tags found

Today I needed to convert an integer into a uniqueidentifier column. At first, I thought that SQL Server would just allow me to do it intrinsically (because I can go the reverse way). However, surprisingly this was not the case. I got the following error message:

Msg 529, Level 16, State 2, Line 1

Explicit conversion from data type int to uniqueidentifier is not allowed.

So, I hit up my trusty Google and found that you actually need to do the following:

  • Create a new column (if putting on a table) of type uniqueidentifier
  • UPDATE dbo.Table SET GuidColumn = CONVERT(VARBINARY(16), IntegerColumn)

And then you are done.

Posted in sql-server

Tags:

Today I was working on fixing up my continuous integration server (running GitLab’s CI multi-runner).  I was making my own custom image based off of the core Ubuntu 16.04 image and all was working perfectly except for the fact that the mysql service would not start up.

This bothered me.  I knew that I had the image working before I rebuilt the server, so why weren’t my images working now?  Reading through the error logs didn’t really tell me much, but it did end up pointing me in the right direction.

Turns out my host (the machine which was running the docker instance) didn’t have any swap space setup and because of that, the mysql service was not able to run.  So, to fix that I ran the following:

  1. Run dd if=/dev/zero of=/swapfile bs=1M count=1024
  2. Run mkswap /swapfile
  3. Run swapon /swapfile
  4. Add this line /swapfile swap swap defaults 0 0 to /etc/fstab

I can’t take the credit for the solution, but hopefully it saves you time!

Referencehttp://www.prowebdev.us/2012/05/amazon-ec2-linux-micro-swap-space.html

Posted in tools

Tags:

I’m going to start by asking a question … are you a jack of all trades?  Are you the best at everything you do?  Or, are there people who know better than you?  This same question holds true with teams you are on.

When you hire a team, or are brought onto a team, the people that are chosen are normally there to expand on the current set of skills that the team has available to them.  So, I want to ask, why not trust them to do what they were brought on to do?

Lots of people get lost in the fact that they want to lead a team and by doing that try to control each of the interactions whic occur on it.  This sense of control could make it feel like the project is going smoothly and efficiently, but at the say time will likely start to make people feel untrusted which in turn affects productivity.  If people are constantly looking over their shoulders, to see if they are being monitored, or feeling pressured to work, the work that they produce will suffer.  But not only that, their desire to exceed expectations will likely also diminish.

Instead, in a team situation, you need to really stop and let your just work and do what they were brought on to do.

Of course, there will be times that this trust has been abused but those times generally followed up by some tough conversations where the situation is addressed.  If it isn’t, it still is not a reason to not trust the team, it is an issue for the team leads (or managers) to deal with.  Lack of trust breeds negativity in the work environment which in turn is counterproductive.

I would like to encourage you to trust those with whom you work.  Your team will end up being a lot more productive if you can.

Posted in tools

Tags:

I’ve always been a lover of the command line and for some weird reason whatever environment I am in, I like to boot up applications from terminal.

This goes from the simplest of tasks, such as opening a Finder window from the current directory:

open .

To opening my text editor:

subl .

However, in order to do the previous one, you actually need to set up your Mac with this command.  You might think that it is difficult but it is not.  It’s as simple as running the following command:

ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

This will make a symbolic link between the Sublime Text app (their command which is built-in) and a folder which you normally have on your path.

Posted in tools

Tags:

Holy smokes, it seems like just yesterday that I purchased IcePets.  But alas, it is not.  Today, my anniversary of owning IcePets.com, I come to you humbled by the overall tenacity of each and every one of the IcePets members.  You could have bailed a while ago, back when the site started becoming fairly static, but you didn't!  You had faith in us, and a love of the site which I am in awe of.  I know it has been several years (3 or more) since any huge features were added to the site, and that a battle system was promised very early on in the development.  However, each day I return to the forums happy because I see "10 unread" messages.  From the outside it may not seem like a lot, but it helps to refuel my passion for the project on the days that I start working on it and feel exhausted just thinking about all of the work that there is still to be done on the recode before we can actually have decent growth.

I don't know about you, but every day when I check on Virtual Pet Directory, I always look to see if the total active user count has gone up or down from the day, or days before.  I'm happy to say that over the two years that we have been tracking the user activity on there, it has remained around the same.  We have had some spikes, 257, and we have had our dips, 90, but now we currently stand 8 users more than we had two years ago, 118.  The total number of users isn't anywhere near our competition, but that doesn't matter.  From the outside, it would appear as though we are a site that is hanging on by a thread.  But that is not how I see it.  I personally see it as a site which is currently in a holding pattern, anxiously awaiting the recode which has been in the works for a little while now.

The biggest thing that amazes me about the members is how much of a community it is.  New members are welcomed in with open arms, old members are welcomed back with excitement as if a long lost friend has recently returned.  And most importantly to me, tell us that IcePets is a community where they feel safe place for them to post even if they are normally a quiet individual.  To me, this speaks wonders of the community.  Although small, we are a powerful community who just love to hang out and play together.

I would like to take this opportunity to also thank all of the staff who have given up countless hours of their personal time to help us grow.  I know that I haven't always been the easiest person to deal with, but we got through it and are stronger for it.  But, I will openly admit, if it wasn't for you, the site would likely be dead despite all I would have tried.  I can code, I can organize and on occasion, I can even chat on the forums.  But the one thing I cannot do is use your countless years of experience with the community to really understand what it is the users want.  You guys make my work look easy.  Throughout the years, some faces have changed.  We have lost some powerful members from the staff team due to real life commitments, but just when things look gloomiest, a different staff member steps up and takes the reigns.  For staff members who have had to leave the team, I am honoured to have worked with you.  And for the staff members who are still working with us, thank you for your continued support, it is greatly appreciated.

Thank you all for your continued support of IcePets.  If we band together and stay strong, we can make it through the current drought, and reach the promised land which is otherwise known as "the recode".

Thank you for reading.

Posted in icepets

Tags:

Throughout university, with all of the individual projects that you do, you learn that you as an individual are able build some pretty neat things on your own.  And if you were like me, completely dread any sort of team work.  This of course was because of the fact that team projects in university typically ended up with one or two people doing all of the work (which in my case was normally me).  This was a great learning experience for me but it also scared me a little about working on teams.

When going into my first job out of university I was going to be put on a sprint team, I entered a little hesitant, but being right out of school I knew I had a lot of things still to learn so I was all in!

I joined the team as a Junior Software Developer, the team I was on consisted of both several Seniors each of which had different specialities.  I was excited!  Not only was I given the unique opportunity to work with people and actually choose what area I was going to specialize in.  At the time, I didn't know what I wanted to specialize in all I wanted to do was code, and learn along the way.  That is exactly what I did.

The team that I was now on worked way more efficiently than I could have ever imagined.  But not just that, the collaboration and actual team work that went on was amazing.  Through design and implementation discussions and working with various members of the team, I was able to learn skills that would help me to excel at my career.  This was all due to the fact that on the team, everyone was able to check their egos as the door.  Had this not been the case, well, the experience and lessons learned would have been significantly different.

However, working in teams can also be a huge challenge.  There are people who always like to be heard and have their stuff be built the way they imagined it.  Situations like these can end up leading to poor decisions because the best work that comes out of a team is work that is built through a collaborative effort as it does the following:

  •  satisfies people's desire for their opinions to be heard
  •  combines the experiences of everyone involved to get a much better solution 
  •  promotes further team work and collaboration

One thing that you always have to remember when working in a team is the fact that every member of the person of the team is a person just like you.  So remember to treat them that way.  The team will work more cohesively if everyone is given the same respect that you would like to be given.

In conclusion, teamwork does not need to be as painful as it was in group projects throughout school, yes it can be, but it can be a very fruitful and fulfilling experience depending on what you put into it!

Posted in tools

Tags:

So, after you read my first blog post, you can see, that I'm a strong believer in the use of frameworks. But there are so many frameworks out there! So why did I choose Laravel out of all of the possibilities?

At the time that I was choosing a framework, there were several main players:

  • CodeIgniter
  • Symfony
  • CakePHP
  • Zend
  • Yii
  • And many more ...

Don't get me wrong, all of these frameworks are good and have their benefits but these were some of the leading factors that pushed me away from the other ones.

The fate of CodeIgniter was somewhat questionable. Around the time I started developing some of my projects, the main company that was supporting it was abandoning ship so I wasn't too sure about the status / livelihood of it at that point because of that, and it was built for an older version of PHP and from what I had read, the code wasn't updated to make use of the newer features which made it so that this framework was not the one for me.

I had tried both Symfony and Yii before, but I got confused in them. There was stuff that magically worked (which is awesome) and stuff that you had to do. I ended up scrapping those because I never really got into the flow of working with those.

I had a friend who was friends with the creator of CakePHP he got some decent say into what was going on. However, he also said that it felt and was very bloated which immediately deterred me from using it.

Which brings me to Laravel. I started playing with it back in the day of Laravel 3. After a little ramping up, it just clicked with me. At the time I was just starting up a freelance project and decided it was the best approach because it does follow the "Model View Controller" approach, and it was starting to gain a little bit of steam in the PHP development community. The thing that really struck me was how flexible it was. I could literally just "plug stuff in" and it works. Or, if I don't like how one thing is configured in the main framework, no problem, I can tweak it in my own area to better suit my needs!

The best part about it is that they supported closures! For those of you who do not know what closures are, they are essentially ways of scoping things into a function call. With Laravel, if there is a value at that point in time, it will just use the value otherwise it will call the function (even an anonymous function) in order to derive the required value(s). This was a huge plus for me! It means I can easily inject more logic as I need to.

After that Laravel 4 came out. I was hesitant! I started using it (and composer) for the first time and for me, it was a nightmare! Sure, part of it was me being new to using composer and how the library dependencies worked. But, after a few days of struggling, and several bug fixes later, I started working and enjoying Laravel 4 as much as I did Laravel 3.

After the initial ramp up on Laravel 4, I found myself excited to code! And, now that I knew how composer worked, I could make my own packages to help other developers using Laravel! I was on cloud nine! That was when I built 4 different packages for Laravel:

  • Asset Processor - easy cache-busting, pre-processor and minification script for all CSS and JavaScript objects
  • Layout View - easy way to set up different "layouts" and redirect to the correct one depending on the situation / settings
  • Feed Reader - a simple RSS feed reader to pull information into your application
  • Revisable - using the built-in soft-deletes that Laravel had, allowing you to maintain history of model's data that have changed

Then they came out with Laravel 4.1 which required lots of changes to your existing code but it did feel like it was working better. I took that as an opportunity to build up Virtual Pet Directory. And did it ever feel good to be coding.

Now here I stand mid-November and Laravel 5.1 is out and guess what? Long Term Support! Taylor Otwell from Laravel has now said "this is our best incarnation of the framework, we will now be supporting it for the future". For a developer, and an owner of a site, this is a huge win. It means I can now code with confidence that if there are bugs, they will be resolved and pushed forward in new releases.

Over the last 3 years, Laravel's core community has jumped in between a few sites. They started directly on the main Laravel domain, and now finally reside over on Laracasts. What is Laracasts you may ask? Well, Laracasts is an incredible resource made by Jeffery Way, who is a Laravel enthusiast and an amazing teacher. Through this site, he teaches things such as best practices, cool new features of both Laravel and PHP. He has several in depth breakdowns of what is actually going on in the Laravel framework and it is just an invaluable resource for anyone starting out. And, if you still have questions about how to do stuff in the framework, then all you need to do is write on the discussion forums and a lot of people are willing to help you out.

Laravel is still actively being developed and has a large number of contributors who all do their best to improve it with commits going in each day!

So, to conclude I have a few reasons why I chose Laravel for my primary framework and they are:

  • It follows all of the best practices that are currently out there
  • Active community who are all making their own plugins to make the framework better
  • Learning curve ramp up significantly reduced if you use Laracasts
  • It just feels right when coding

Thanks for reading :)

Posted in laravel

Tags:

Testing in general is a process that is normally left really in a partial state. The problem with this fact is it normally leaves things up to users or testers to find. And then, once found, the cost to fix the bug could be huge and hypothetically speaking, could touch various other parts of the application.

This is where unit tests and integration tests come in handy! Since this is a fairly broad topic, I am going to start by just talking about Unit Tests.

By definition, unit testing is a software testing method by which individual units of the source code are tested to determine whether they are fit to use.

So let's start from the beginning. What is a unit? It is the smallest testable part of an application. In procedural programming this could be an entire function, or as much as an entire page / section of code. In object oriented programming, these either an interface, or could even be a class.

But writing unit tests is still me writing code how will it help in the long run since it's taking away from the development of my site? It will help in the long run. I've had several occasions come up when I go to change "one small thing" which then ripples through and breaks other pages that touch this one unit. Essentially you are building your first layer of protection against future potential bugs.

The nice thing about writing test cases is it also allows you test things that may occur on the fringe cases. This will help to ensure that everything will should act as it's supposed to even in the strangest of situations. One of my favourite testing strategies (although admittedly I rarely do it), is actually test driven development. With Test Driven Development, you start coding by knowing what you want the end result to be (for your unit of work). You actually write tests for it and expect it to fail. If it doesn't fail right out of the gate, then your test may not actually be doing anything/finding anything useful. Then as you work your way through the development of this unit, you run your tests. Are all of your tests passing? If they aren't, then you know that you still have some work to do. However, if everything passes, then you know your application should work for at least all of your known cases. Which if you set up your tests correctly, should give you good confidence in the code.

The nice thing about writing these unit tests is that once you find a bug in any environment and resolve it, you are then able to actually write a unit test in order to actually test for that case so, if you change some more code, you don't re-introduce that bug.

With PHP, I, like most people, use PHPUnit as the primary unit testing software. Not only because it's built into Laravel and Laravel actually has helpers built on top to make the testing process even easier!

Although writing these test cases can sometimes be a big pain in the butt, if you do it correctly it can help you to spot issues earlier on in development before the time when it is "too late".

Hopefully this comes in handy for you!

Posted in php

Tags:

Some of you may know this about me already.  But for the last 4 years, I have been an active member of Toastmasters.  Through their program, and just putting myself out there in a calm supportive environment, I was able to break out of my shy shell and become a much more active communicator.  But confidence is not the only that that it has given me over the years.  Over the years I have taken on several executive roles at our club in order to help out.  This includes:

  • Sergeant at Arms
  • Vice President of Education
  • Mentorship Chair

While there, I found out about a program that I never knew existed.  It is called the “Youth Leadership Program”.  It is an eight-session program which is free for teenagers (from ages 12-18) to attend.  During these sessions, they learn a bit about leadership as well as improve their communication skills in order to boost their overall confidence.

Over these 8 sessions, each Youth Leader is required to complete 2 speeches and 2 evaluations.  But these are not the only things that they will be doing during this session.  Each Youth Leader will be encouraged to participate in Table Topics (speaking off the cuff) and take on other roles, in order to gain even better experience.

This year, IcePets is partnering with Brampton Toastmasters as a sponsor for two of these programs.  The first program has been already been scheduled for August 8th - 12th, and the second will be planned out later on in the year.

Looking back, I personally wish I had known about and actively participated in a Youth Leadership Program in the past.  I managed to work my way through University and the first few years of my career with being that quiet individual that knew a fair bit, but wouldn’t share it unless asked.  However, thanks to Toastmasters, I was able to break from that mold which has helped me to excel in what I do.

Last April I had the privilege to be the co-ordinator for a Youth Leadership Program and it was such an incredible experience.  The Youth Leaders amazed me from the very first day!  Everyone started off very  quiet, not really wanting to talk even amongst themselves.  However, that changed within the first hour of the program and by the very end, the Youth Leaders had been transformed into much more confident presenters.

These programs are all around the world, so if you are not aware of where they may be, ask at a local library, or go on Google and look for a local Toastmasters club, they could point you in the right direction.

Posted in icepets

Tags:

My anniversary for owning IcePets.com is coming up fairly soon (August 8th) and all I can say is wow has it ever been a ride so far.

I had been working as a freelancer with them for a little over a year, so I knew exactly what I was getting into.  Some very bad legacy code which was pieced together (and still holding fairly strong) with super glue and duct tape.  When going through the code, I noticed numerous back doors into the site that a previous programmer had built in for "security reasons".  AKA, in case they were banned, they would be able to make their way back into the site.  Those were patched, and the user was banned.  But here I was, owning a site and working with a bunch of people who I now call my friends with no idea the full vision.

So, my first order of duty was to bring the recode up into the foreground because the site wasn't really moving anywhere fast because I knew if this site was to be anything, the recode would bring a definite life to it.

Laravel was just breaking through the headlines on the PHP front when I had started working on the site.  But not only that, I was just working through the framework at the time and was entirely overwelmed!  There was so much going on, I knew it was all good and neat but just so much stuff!  But, I managed to power through it.  I started building the site up with Laravel 3.  A month later I heard that Laravel 4 was getting ready to be launched and it had some fairly substantial changes in it (aka - don't bother even trying to upgrade, just re-implement (copy and paste code) and build it up that way.

I was a little hesitant, but decided it had to be for the best.  That was when I was first introduced to "composer".  I had always dreamed of a way to easily incorporate other open source work into my projects, but never really knew a way.  This in itself was confusing!  Finally I managed my way through that hump and then came the next releases of Laravel (4.1 and 4.2).  These were fairly big.  By this point in time, I had already really started to focus on coding lots of the features. There were things I felt were clunky but it worked.  But something felt wrong.

When Laravel 5 came around, I decided to revisit the entire framework that I had thrown together to build IcePets version 2 (yes - a bit of a framework on top of the framework).  So, I started from scratch again.  This was ok because this time I knew it felt cleaner.

The last two years have been such a learning experience for me both technically and with leadership skills.  Looking back when I had originally thought about my very lofty goal of finishing the IcePets recode in a year, I realize how oblivious I was.  And, to be honest, I'm glad I didn't make that personal goal.  The technical learnings that I have picked up through the multiple iterations through the code, has slowed down progress on the site, but it has also opened my mind to way more options which I never even thought was possible.

I would like to say thank you to both the IcePets.com staff members as well as all of our loyal members who stick with us through this recode.  The best thing about the recode to me is the excitement it brings to me each and every time I think about it.  There are so many opportunities for us to morph the site into something substantially better than it currenlty is.  Once the recode is done, I think you will love the site and it will be a great place for all of us to bond as a community!

Thanks for reading!

Posted in icepets

Tags:

I've heard and seen the following so many times.  "Why should I use a framework when I can just code my own framework?".  Or, "using a framework slows down the application, and I need it to be speedy.  So I need to use raw PHP".  Yes, those two statements are 100% accurate.  You can build your own framework, and technically yes your code would hypothetically speaking be faster if you wrote barebones PHP.  

However, script speed isn't the only thing you should be worried about!

There are several PHP frameworks out there that are being fairly actively worked on. Let me ask you a question.  What do you think would work better?  An application/framework that is being developed by one individual who has a certain set of skills?  Or, would you rather use a framework that is being actively worked on by a bunch of software developers around the world who are actively talking about ways to improve?

To me, the answer is simple.  Use the framework.  I have been developing software for over 10 years now, and I still find myself learning from those around me.  Be it through code reviews from co-workers, or from merge requests and issues logged from other people on GitHub.  Yes, I have a fair bit of knowledge but everyone picks up things differently.  Could I make a decent framework?  Possibly, would it benefit from other people's input?  Probably.

The fact that something is "open source" doesn't mean that there is nobody monitoring check ins and updates for it.  Take Laravel for example.  When I wrote this post, there is a total of 294 people who have contributed fixes to the framework.  However, they have core maintainers.  It is these people (who are normally core to the project and have proven themselves already), that are reviewing every check in that someone does and making sure it meets the standards that they wish to enforce.

"I like to know everything about what is going on in the application".  My answer to that is who cares?  Do you know how the operating system that your application is running on works?  Do you know the inner workings of PHP converts the code you write to code that the computer can understand?  Likely your answer to both of these is "no", so why do you need to know each and every inner working of the application too?  Yes, it helps when you are trying to design and write the code (to some degree), but it shouldn't change your mind.  Treat the code that they give you like an extension on the PHP language.  But more than that, let it help guide you on what some best practices are / may be when you actually start building your application.

"It is all written by other people, so there could be bugs."  Yes, this is true.  Just like PHP can have bugs.  Code has bugs no matter where you get it from so don't let that be a deterrent.  Is your code 100% bug-free?  Probably not.  So why not let others handle the core of the framework while you reap the benefits when they have bug fixes available?  Lots of frameworks use unit tests in order to test and validate each "unit of work", so they work on proving their code works.  And if a bug is found, more unit tests can be added to ensure that they don't crop up again.

If you write your own framework, are you able to search Google for your specific issues that you have?  Likely not because it is fairly hard to give enough information if you built a framework because you need flatten it out as much as possible.  With a framework, you are able to Google the framework name you are using and your particular question.  Or, post on the framework's forums.  Both places will likely get you a much better answer and, depending on how active the community is you could have a response in a matter of minutes.  Sure there are moving parts, but there are also more people willing to help to lubricate them.  So why not?

"But there is so much to learn if I use a framework". Yes, yes there is. Learning curves aren't necessarily a bad thing. They are a way that you become a much better and much more rounded developer. They help you to flex to expand what you know which in turn allows you to make better decisions going forward.

"What do frameworks buy me?" Most frameworks come with at minimum an easy way to interact with your database. By profession, I am a database developer. So I don't mind writing SQL queries. But if I'm given the option to have them auto-generated based on a object, why wouldn't I take it? It's 1 less thing that I have to manually do. It's these small efficiencies you gain through the development of an application that allow you to:

  1. Create the site quicker
  2. Make the site more robust
  3. Make most more easily maintainable code

Not writing SQL queries isn't enough for you? Then how about the fact that for the most part, the use of a framework will not necessarily force best practices on you. But, they do their best to help push you in the right direction! I've seen so many sites which have code that is a nightmare because essentially every layer is tangled together. You have the database being directly summoned by the front end and huge "if-then-else" statements that start forcing more and more levels of indentation which can get confusing. I'm not saying you can't do this in a framework. But, after using it a bit, you will quickly realize that it is not the right thing to do. The "Model View Controller" architecture has been around since the late 1970s and is still a prominent setup. Because it pushes you to ensure that every section does it's own work and that is all.

Sure frameworks can cause an extra little bit of processing time in your application, but that is nothing a little extra RAM, a better CPU or even, an SSD cannot solve. If you are able to determine that those are your bottlenecks that is. For the most part we are talking milliseconds which isn't much time at all. Your system could be processing someone else's request at that time. However, you will make up for it in the amount of code throughput you can have as you work on your application.

If you ask me why do I use a pre-existing framework, the answer is simple:

  1. Support of a Community - I trust the developers around the world to come up with solid frameworks and the communities that back them.
  2. Time Efficiencies - I don't like to write a lot of the boilerplate code that you need to when writing from scratch because they take time and don't provide a lot of value.  Let the "magic" happen.
  3. Code Maintainability - I want my code to be maintainable in the future. Yes, it is possible outside of a framework. However, it is a lot harder.
  4. Learning - By reading through the code that exists in the framework, I am able to pick up a few "neat tricks"

Hopefully this helps to guide you in your decision of whether or not to use a pre-existing framework or to make your own a little bit easier!

Posted in programming

Tags:

So, I was doing a consultation this week regarding some database work and got to hear a little horror story from the owner of a site.

Please Note: The owner of the site has next to no programming experience.   The only experience they have is dealing with the code that they were originally sold.

The owner of the site contacted me because they felt there had to be another way of handling this particular situation.  What the problem boiled down to was the fact that they had 1 large table that had more than 256 columns in it!  And better yet, the columns that were actually needed depended 100% on the "earlier" content of the table (i.e. the first few columns).  To me, I immediately saw this table and was appalled.  I thought to myself, well this obviously needs to be a mapping table, and treated as such.

After talking with the owner for a bit, apparently this was their first inkling too.  However, the programmer "swore up and down that it could only be done this way".  Hearing that saddened me a little.

Now, you maybe wondering why this blog post is called "My Way or the Highway".  That's because one thing that I have learned in my years of programming is the fact that there truly is no "one right answer".  In fact, every time I work on a programming problem, I myself come up with 3-5 alternatives before narrowing the problem down into which solution I'm going to take.

In order to develop applications, you need to take a few things into consideration and most importantly, leave the ego at the front door.  In my opinion, this holds true for more than just programming exercises.  Someone else to bounce ideas off of may help you see the problem in a way that you never even thought about before which could lead to a better overall application.

After peering through the code a bit more, it was clear to me that the reason why "it was the only way this could be done", was because they wanted to be lazy when handling access in other pieces of code.  All they really needed to do in order to make this mess manageable was to wrap the database call in some sort of data access layer.  When they do that, they would be able to handle any updates/inserts that are needed and still send back all of the data that was required to process the data instead of that and then so much more.

In short, when programming, try your best to keep an open mind and focus on other alternatives and please don't take the solution that "is done fastest" because that normally leads to pain points and wasted resources in the future.

Had this programmer done what the owner, who was speaking from what logically made sense to them, listened to them and re-evaluated their statement, then I wouldn't have likely needed to be brought into this discussion at all.

I've been programming for years now and I still realize that I know just a tiny bit of the broad spectrum that coding provides.  So, that is why I always ask others for their opinions and leave my ego at the door because at the end of the day, I want the best product out there.  Not a decent product that is filled with patches that is being held together with bandaids and chewing gum.  You only get that solid result from reaching into the depths of programming experiences both that you had, and that everyone else has had in order to get the best results!

Thanks for reading!

Posted in programming

Tags:

Lots of times when I talk to site owners, one of my first question that I ask them is "what is your backup strategy?"  And shockingly enough I've seen so many with strategies that would make me not want to sleep at night.

I've seen people who are so sure in their code that they decide that they don't actually need to make backups.  Which just tells me how immature they are.  They really think the only thing that could affect their code's well-being is the code itself?  How about the thing that it runs on (i.e. the server)?  They crash from time to time and you lose data.

The next "backup strategy" that I've seen is people use cPanel or some other tool in order to make a local backup of the site and just leave it there.  That's great if your database gets hacked or messed upend you have to revert it. However, what happens if your server goes into an unrecoverable state?  Well then, you are out of luck because you put all of your eggs in one basket.  The funny thing is, sometimes these peoples backup requires them to manually go in and click a button.  I personally would at least look for a somewhat automated approach to doing this because the last thing you would want to do is have to revert your site's content back 1-2 months because you "forgot to take a backup".

Now that we have gone through two of the most common backup "strategies" that I have seen, let me talk about some that I would prefer to see people having.

Code:

  • Source Control - in this day in age there really isn't a reason why your code couldn't be in source control.  You can choose the flavour that you would like (be it subversion, git, mercurial, etc), there are normally free services available for private source control repositories.  This means that repopulating your code is a simple "get/pull" command.
  • Offsite Backup - Normally fairly cheap to set up (assuming you know how), you can get a virtual private server (VPS) where you just "rsync" or "scp" data from one server to the other.  As long as this is in a different data centre than the main hosting service is, the likelihood of both going down is much lower.  Your recovery strategy would be copy the latest code back to your server and deploy the database.

Database:

  • Master/Slave Server - A master/slave server will allow for a constant syncing of your database between two servers.  The actual name varies depending on the platform however they all use the same concepts.  Every X minutes the slave server will poll the master server asking for any new/updated data which it then replays these changes on it's local database and everything.  Then if you are really paranoid (like I am), you could have a backup run off of the slave server every so often that way you have an extra copy of the complete database (which can be stored externally) and it doesn't impact the performance of your actual application.
  • Offsite Backup - Similar to code, a database backup is fairly easy to export and ship to another location.  It can all reside in a single file.   Zipping this up and secure copying it to another server will have yet again a bit more overhead when you are forced go into disaster recovery mode.  But, it will at least protect you in the unfortunate event of a server failure.

If you don't take much away from this article, there are two key points that I want you to take away.  

They are:

  • Servers fail, make sure you have a backup plan if your primary server goes down
  • Don't rely on someone remembering to take a backup of something.  Because it will be forgotten.  Set up some regular scheduled jobs to make your backups and lock them up in a safe facility for you.

I hope you found this informative!

Thanks for reading.

Posted in tools

Tags:

A few weeks ago, a friend of mine mentioned (just after I did a painful upgrade to Laravel 5.2 - I messed up a few times so it ended up taking longer than the estimated 1 hour), a service that will automatically upgrade Laravel (for a fee) from one version of Laravel to another and they were having a discount because they were in alpha!

So, knowing I had an old Laravel 4.2 application running up in production, I figured "what is the worst that could go wrong?".  So I decided to give it a shot because an upgrade like that would take me a while to manually do.

Their steps are fairly straight forward.

Select the "Shift" (the upgrade) you want

  • Login with your GitHub account (BitBucket and GitLab are also supported)
  • Specify your repository and branch that you want it applied to
  • Pay for the Shift
  • Wait for the job to complete

Once the job is completed, you will now have a new branch in your repository.  This branch contains all of the changes that they have made, and a slew of suggestions that they found as they went through it.

So, you may be thinking.  "I changed my 'config/app.php' file to include some more stuff.  Will I lose those changes?".  The answer is no!  They recognize the changes to the file and instead of automatically modify it, they add comments to the pull request that they generate saying "you will need to merge this manually.".

Once you are happy with the remaining changes, and have fully tested your application, it is time to merge the pull request in, and you are done!

The other migration that I completed with it was a migration from Laravel 5.1 to Laravel 5.2.  In this shift, we found a tiny bug (it suggested I remove "pluck" from a JavaScript file because it assumed I was using the eloquent model's "pluck" command).  I reported it through a comment on the pull request and they responded fairly quickly acknowledging and resolving the issue going forward!

I am loving the tool and can't wait to use it in the future!  I would strongly suggest trying it out whenever you have a chance!

Laravel Shift: https://laravelshift.com

Posted in laravel

Tags:

Today I needed to figure out how big a bunch of tables were in a database (we were in the process of pruning it and wanted to spend the correct amount only pruning what was necessary).  Luckily this is actually fairly straight forward!


SET NOCOUNT ON 
 
DBCC UPDATEUSAGE(0) 
 
-- DB size.
EXEC sp_spaceused
 
-- Table row counts and sizes.
CREATE TABLE #t 
( 
    [name] NVARCHAR(128),
    [ROWS] CHAR(11),
    reserved VARCHAR(18), 
    DATA VARCHAR(18), 
    index_size VARCHAR(18),
    unused VARCHAR(18)
) 
 
INSERT #t EXEC sp_msForEachTable 'EXEC sp_spaceused ''?''' 
 
SELECT *
FROM   #t
 
-- # of rows.
SELECT SUM(CAST([ROWS] AS INT)) AS [ROWS]
FROM   #t
 
DROP TABLE #t

Hope this helps you as much as it helped me!

Reference: http://therightstuff.de/CommentView,guid,df930155-f60f-4f56-ab33-f1352ff091a1.aspx

Posted in sql-server

Tags: