What’s the deal with Laravel 4 being so dependent on Vendors? I don’t know whether this is simply Laravel 4 confusion or disappointment.
I tried out Laravel 3 and it was absolutely beautiful. It was a drag and drop install, lightweight and to the point. I really liked it. I could jump right in and go through the docs and get excited about a nice looking framework.
But now I am looking at the direction Laravel 4 is headed, and I’m bothered. Is this going to be a waste of time?
Forced Depencies
To install we are forced to use composer, not a big deal. But it installed 15 dependencies. Are these optional packages? I’d like to know Why Doctrine files are being included in the vendor folder when Laravel has it’s own Eloquent ORM? The last thing I want to use is Doctrine ORM. It doesn’t seem to be the full ORM, rather, miscallanious components borrowed from it. The same thing with Symfony, are all these big kahunas playing nice together now?
It bothers me a lot to have no idea what these third party files are doing and where they are tied in. Are they tied into the main system? That would be absolutely ridiculous if they are. If not, why are they included? Why would the default installation assume I want all this?
Autoload What?
You cannot run L4 without using composer. When you do, it takes a few minutes to install — due to all the vendor packages. It seems to generate a unique autoloader name in /vendor like this:
ComposerAutoloaderInitc3b95d1ae18a40f6b5ee9e21dabc03d5::getLoader();
This isn’t right.
Naming Convention
Next I looked at the names of files in Laravel 4. I’m really disappointed they decided to go with CamelCase controllers. So we have CamelCase Controllers and Models, yet our views and seemingly every other file are lowercase. It’s borrowing from two different naming conventions.
File Size
The application size on my hard drive after a fresh install is roughly 27MB with over 3000 files. This has to be a sick joke. This isn’t even funny. A PHP framework does not need to be this massive. You can use composer to install the preferred packages `composer install –prefer-dist` yet it still remains around 20MB.
Code Disease & Overengineering
I must be missing some critical information, perhaps someone can inform me on these simple decisions? I really hope I’m wrong and misunderstood because I’d hate to see a good thing ruined. This is going in the totally wrong direction, it’s becoming less elegant.
I think I’m seeing the anti-pattern of overengineering. Sure it may save time to use third-party applications, and it’s only one guy developing — but version 3 was a better direction. The buzz and excitement is dwindling quick.
I wonder if web forums are dying? Where with this rabbit trail lead us?
I think it was a lot easier in the early 2000′s to get a forum popular. This was before we had instant social media taking over. It was also easier to gather crowds because there weren’t so many options. In the past you would find forum about Cars. Everything from tuning to fixing. Yet now it is narrowed down to something like a car make and model forum, such as Audi TT. Topics are less encompassing.
I don’t have any web forums I visit anymore. I think it’s strange because I used to visit them all the time and was quite active. I even got proud when I reached certain post counts. To me forums seem a little bit dated these days.
Besides all of the above points, I think my #1 reason for being dead on forums is because of StackOverflow. If you are trying to program anything, StackOverflow has come up atleast 100 times with the question you have. It’s almost too good of a system to be true. The answers you get on there are rich in quality and questions are often answered within minutes.
StackOverflow has many sub-sites as well covering a huge range of topics, yet none as popular as the original. And they still have great momentum on the sub-sites. They’ve been quickly active for me. StackOverflow is written in C# on the MVC framework, or .NET.
The co-founder Jeff Atwood of the StackExchange has a new project on it’s way called Discourse. This looks to me like a very promising alternative to web-forums. It’s a cleaner real-time application you would likely expect in 2013.
The system will cost something. I think that’s fair. I’ve purchased Invision Power Boards and I wanted something above the standard freebies with a million addons. I think good software is worth a price, and this looks promising.
Another downside may be that the application may require technical hands to get the Discourse system up and running. The application is written in Ruby. You would not being using the super-popular PHP that comes with every web server, rather you’d install it by installing Ruby, Ruby on Rails, and any other needed Gems to your server. I’m sure they’ll have instructions to make it easy for us non-ruby folk.
Ironically, I have a forum for this site.
Let’s talk about Git. If you are writing software in any way and not yet using it, you should start now. I was quite a novice with Git for a while, and I need to give credit where it’s due. Thanks to my co-working Nick Whiting I have learned so much about it just by watching him.
I’m not a git meistro and I prefer the command line much more over the GUI. Anyways, let me break down a few concepts that were difficult for me to grasp at first so you can get on this gravy train.
I’m going to assume you already have some type of Git shell on your computer. I will also assume you already know that you can type $ git init to create an empty repository. Furthermore, I must assume you know how to connect to your git service. This is about Git commands.
Git Repository
This is just a fancy name for pretty much a dedicated folder to your project. You shold notice that all git repositories have a .git folder that’s usually hidden. Whenever you upload files through FTP, you never want to include that folder as it keeps track of local history and can get insanely large.
Git Commit
When you commit your code it doesn’t mean it goes to your git server. Committing means you’ve added all the changes and files you wanted to, and you are ready to commit those changes right before you push them (or merge).
First you need to make sure there is something to commit. If you haven’t changed any files, you’ll need to in order to get a git status going:’
$ git status
$ git add .
$ git add -u
$ git commit -m "A brief description of files updated.."
Git Push
Anytime you hear push, that means you have committed data that is going to be pushed to the server. It’s tricky to get all the lingo down at first but you’ll get it once you type it over and over. Suppose I type $ git status and it shows me that I have code I can push. I would do it this way:
$ git push origin master
If I was on another branch (which you’ll see below) you would just change the name of the branch like so:
$ git push origin dev
Git Branches
Lets say you have a project for a client going well and running smoothly. And you want to refactor a lot of code. It would be a bad idea to refactor all the main code that’s stable. So, you would want a separate section dedicated to that code. This is what a branch is.
An example would be, you master branch is where all the live code goes. And your dev branch is where you are doing your refactoring. That’s a great way to do things.
$ git branch dev
$ git checkout dev
And, so you aren’t lost here’s how you go back to master:
$ git checkout master
Also, how you can delete a branch. Please be careful with this one!
$ git push origin --delete dev
Git Tags
Have you ever backup up your computer to a certain state? If you have a tag is the same thing. It’s a snapshot of your current code base nicely zipped up for you so you can keep track of versions.
$ git tag 0.1
$ git push --tags
What’s strange is that deleting a tag is a lot different, here’s the syntax:
$ git tag -d 0.1
$ git push origin :refs/tags/0.1
Git Unadding Files
Have you ever just done a $ git add . and realized there are files you don’t want in there? Well you can simply unadd a file by doing this:
$ git reset HEAD file.txt
You might be asking yourself what does HEAD mean? It is the latest commit to that given file you made. So if you updated that file 5 times in the past, by restting the head you would get the newest revision.
Git Ignore
Many times there will be files you never want to add to Git. Such as Caching files and file uploads as they will just waste space. Git ignore will allow you to ignore certain files, to do so create a file in your root directory:
$ touch .gitignore
Within the .gitignore file, lets pretend you wanted to ignore all jpg files and a folder;s c called upload. Inside .gitignore you would add:
*.jpg
upload/*
What’s more is that you can put .gitignore within subfolders and apply the same rules if you choose. Just make sure to put one rule per line, and as always * is a wildcard!
Sometimes you may find that your .gitignore is not working, this is likely due to your local cache. To fix that run these commands:
$ git rm -r --cached
$ git add .
$ git commit -m "Fixing my ignore files"
$ git push origin master
The first line in the code above recursively removed the cached files, hence the -r. So then you must re-add your local files and re-commit them and push them to the server.
Conclusion
I used to use SVN but I love Git much more. One thing I haven’t covered it merge conflicts and stashing. But there are other resources ready for you when you get into more complexities. For now checkout BitBucket and get free public/private repositories, all unlimited.
This will be a quick guide on how to Install Nginx on Windows.
Download and Move
The first step is to download the compressed file from here: http://nginx.org/en/download.html
I then I moved the compressed contents into c:\nginx
Run Nginx
I opened my terminal and navigated to the nginx directory. I am using MINGW32 for my terminal. I then proceeded start the service by typing:
$ start nginx
Check Error Log
You may have a window popup and disappear, the first to check is the error log located at:
c:\nginx\logs\error.log
If you have the following error, this means port 80 is already in use. Possibly by Apache running on your computer:
bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket
in a way forbidden by its access permissions)
To resolve this go to c:\nginx\conf\nginx.conf and look for:
server {
listen 80;
Reconfigure Nginx
Change the port number to something like 8080. Save and close. Now try to start nginx again with
$ start nginx
You will probably get a popup to allow the service in Windows Firewall, accept it. Then head to http://127.0.0.0:8080 and you should see a welcome page for nginx.
For your reference Here are a few commands:
$ nginx -h # Display Help
$ nginx -V # See all version and installed modules
$ nginx -t # Test the configuration
$ nginx -s stop|quit|reopen|reload # Send signal to nginx
$ nginx -c filename # Change the configuration file
If you are saddened by the lack of a shell/bash console in Windows like I am, there is little to worry about these days. We have an excellent selection. Today I’ve found quite the gem and I consider it the best windows terminal tool.
Starting with Cygwin which allows you to install massive amounts of linux packages and run them under windows. Then you have the awesome Git Bash that uses plenty of linux commands for everyday use with git already built in.
Lastly, for SSH access and such you have PuTTY, but a step up is mRemoteNG which is a wrapper around putty to have tabbed sessions and quick connections.
But we have a new friend in town called Console2. This bad boy let’s you create tabbed windows for any shell you have. Let me show you what I mean.
I downloaded Console2 and dropped the the folder in my Program Files. Then I created a shortcut in my QuickLaunch. Next, I opened up my settings and set Git Bash as my default console:
Git Path
C:\Windows\SysWOW64\cmd.exe /c “”C:\Program Files (x86)\Git\bin\sh.exe” –login -i”
Git Path on Laptop
“C:\Program Files (x86)\Git\bin\sh.exe” –login -i
Next I went to the Tabs under settings and gave myself the option for different tabs, Cygwin, Git, and PowerShell.
Terminal Paths
C:\Windows\SysWOW64\cmd.exe /c “”C:\Program Files (x86)\Git\bin\sh.exe” –login -i”
C:\cygwin\Cygwin.bat
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
Now I’m ready to rock with massive tab loading the console of my choice.
One of my favorite things in programming is organizing and structuring an application. That means laying out the folders, naming the files according to a preferred pattern, naming database tables and so on. I may not be the best at it but I find it very satisfying to easily flip through files in a concise manner.
On the flip side, I know some who are great with algorithms and complicated brain teasers. I don’t enjoy cryptography, encryption algorithms or overly complex things of this nature because my mind doesn’t think in such a way.
In my subjective opinion, I have found that over time I find the best way to name almost everything is non-plural. I know people will disagree with me but it’s made my life so much easier. When I work on a project with multiple people I don’t usually set the rules, I just follow them even if I don’t agree with them. It’s easier to be passive, but it causes me a lot of mental loops later that could have been avoided.
Lets say you had the following categories: files, users, games, points. Then let’s assume you’ll have a database for those tables. Perhaps you use an ORM and don’t care what the database tables look like, but I think you should always care.
If we have all of our classes and databases plural we break the entire principal of OOP:
class Files {}
class Users {}
class Games {}
class Points{}
The above classes suggest that they are not single instances. So the files class makes me think of many files, then many users, and many games. You get the idea, but it doesn’t stop here. When you have a database table with id’s which are singular, it may look like this:
files, pk: id
users, pk: id
games, pk: id
points, pk: id
Above should never be done in SQL. Anytime you join tables you’ll get an ambiguous error due to a conflict with primary keys being id — and every SQL query you make will have to be aliased. This is unnecessary work, so a better idea to to name a table after the table name suffixed with an id:
files, pk: files_id
users, pk: users_id
games, pk: games_id
points, pk: points_id
Above is the pattern you would get from following this plural programming pattern. Yet if you loop the data you’ll be getting one record at a time and listing $user[0]['users_id'], it doesn’t look right because it sounds like it holds many user ID’s.
What if you had a class and database table called: life, men, woman, box — to pluralize them you’d get an uneven set of plurals. Because men is man, woman is women, box is boxes. They don’t all end in that s. So now you’ve mixed plurals with irregular plurals and things look inconsistent.
An instance is one copy of a class, having a plural class for a single item violates this rule. My findings suggest using all non-plural words makes life worlds easier. Here’s what classes would like like:
class File {}
class User {}
class Game {}
class Point {}
And here is how the Database Schema might look:
file, pk: file_id
user, pk: user_id
game, pk: game_id
point, pk: point_id
To me this seems more logical. When looping through records or creating an instance you are only reading one entity at a time, which is singular. Reading a series of classes and tables that are plural and non-plural is like a mind warp to me.
I also suggest doing this as much as possible with variables. Unless it’s an array, hash table, dictionary or list or tuple then it’s understandable to pluralize is. Yet at the core of a system I think consistency should be of the utmost importance.
This may not be news to many of the jQuery regulars but I wanted to bring up this topic for anyone missing out. jQuery has a selector called data, you use it like:
$("#dom").data('something');
Yes, quite boring looking. But in a real example you may be used to setting a rel attribute and passing arbitrary data through it for various resons like this:
$("#dom").attr('rel');
While that’s fine and dandy, you are limited to the single rel attribute. You can use HTML 5′s data attribute with jQuery’s data selector and make your task flexible, check it out:
<a class="user" href="#' data-id="1" data=name="user_1">User</a>
$(".user").click(function(e) {
e.preventDefault();
var id = $(this).data('id');
var name = $(this).data('name');
console.log('id' + id);
console.log('name' + name);
});
It’s pretty obvious what’s happening here. use the data-{anything-here} and you can fetch it with jQuery’s data() function. More on the topic can be found in the jQuery API.
I picked up a USB 3.0 flash drive and decided to run a speed test. I gave it a go with a Patriot Supersonic Boost XT USB 3.0 Flash Drive (PEF16GSBUSB). This set me back twenty dollars.
With my little test I set the standard with USB 2.0. I moved a single 700mb AVI file at the rate between 4-6mb/sec. The other tests I did were with two and three AVI files. Doing multiple files is extremely slow at about 1mb/sec. Here is a detailed photo of the transfer rate of the one file:
I’ll admit I tried my USB 3.0 stick before the 2.0 and I was disappointed at first. I seemed to have forgotten how slow 2.0 is. Here I did a another speed test by moving a large zip file on one of my desktop USB 3.0 ports. The increase is 5x the speed capping at 25mb/sec.
I also tried my laptop, which is not a powerful machine by any means. However, I have two USB 3.0 ports and my results averaged about 24mb/sec in transfer speed, about the same 5x faster. When running in the USB 2.0 port I averaged about 20mb/sec.
Is it worth it to upgrade to USB 3.0? In the case of using a USB drive a lot absolutely! Since 3.0 are nearly the same price as 2.0 there is no reason to stay slow. I was still disappointed that I never reached that 10x speed.
The last tests I ran were with multiple AVI files at 700mb/each. Moving multiple files over is quite a bit faster. You can cut the time by 5x. So what would takes 25 minutes would take 5 minutes with many large files.
Once and a while I could get a big spike when doing multiple files – but not often enough. It happens totally at random.
I think if I forked over more money for a nicer 3.0 stick that has faster I/O it would stand out a bit more. It’s a nice little flash drive but it can never compare to the cheapest Solid State Drive on the market.
Sometimes I get into the thick of building a project and don’t give the Database Schema enough respect. This is a terrible oversight. It most often happens when I’m under the pressure cooker and deadline is looming. I tend to fly through a project.
So here I present a MySQL design tip that may help you. Yet when I think back I almost always have a regret about a something in my database design. Recently I was working on a website and it had a table for emails and pdfs, so I made two tables:
email_content
pdf_content
Looking at that for more than 3 seconds it becomes totally obvious I just duplicated my task. In this scenario I’d need two PHP models to represent each table. So I did what anyone programmer in his right mind would do at 11pm, refactor a bunch of code.
So I made a single table that can be re-used for 100′s of different content types’:
content
Here is the table layout. Notice that the “key” and “type” as a pair must be unique. The data row is arbitrary, it could be anything — even serialized data if needed.
CREATE TABLE IF NOT EXISTS `content` (
`content_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`key` varchar(50) NOT NULL,
`type` varchar(50) NOT NULL,
`data` text NOT NULL,
PRIMARY KEY (`content_id`),
UNIQUE KEY `title_type` (`key`,`type`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Now I have one Content_Model which handles all the possible data from this table with a simple function with a key/type argument and a return of the data.
One of my favorite API’s to use is Authorize.net because they are so good at what they do. They make the job of integrating their services so much easier than any other service I’ve used.
Take for example, Paypal which is owned by Ebay. They are a monster sized company yet they have the sloppiest and most convoluted API’s I’ve ever seen. In PayPal, testing IPN (Instant Payment Notification) is fairly simple, but when you get into their business services like Direct Payment, finding out whether you can accept ACH and so forth — most of your time will be spend scanning forums and doing a few hundred searches before you find what you’re looking for. These API’s are also totally inconsistent, in the PHP area anyways.
AIM Credit Card Processing
Most of the time with Authorize.net I use AIM (Advanced Integration Method) which is ridiculously easy to use and not as scary as it sounds. Two steps, Download the SDK, and run the test code.
require_once 'anet_php_sdk/AuthorizeNet.php';
$transaction = new AuthorizeNetAIM("AUTHNET_LOGIN", "AUTHNET_KEY");
$transaction->amount = '9.99';
$transaction->card_num = '4007000000027';
$transaction->exp_date = '10/16';
$response = $transaction->authorizeAndCapture();
if ($response->approved) {
echo "Success! The test credit card has been charged!";
echo "Transaction ID: " . $response->transaction_id;
} else {
echo $response->error_message;
}
Store Credit Cards and ACH
Authnet has a feature called CIM, which is the Customer Integration Manager. It’s awesome. CIM allows you to create user profiles in which you can store any number of Credit Cards, ACH Info, and Addresses.
What’s the point of doing that? PCI Compliance! What a nightmare PCI Compliance is! It’s not worth doing unless you have a boat full of money and some people dedicated to securing your servers. It’s better to just let a massive company be responsible for everything because the PCI fines go up to half a million dollars for Credit Card breaches!
Here’s how you setup CIM with an example of creating a user record, credit card, ach, and address all in one call. You can create multiple cards in one call if you like as well.
<?php
// Require the precious library (It knows to find CIM)
require 'authnet/AuthorizeNet.php';
// Instantiate CIM
$request = new AuthorizeNetCIM("AUTHNET_LOGIN", "AUTHNET_KEY");
// Create a customer Profile
$customerProfile = new AuthorizeNetCustomer;
$customerProfile->description = "Jesse Boyer";
// Your customerId should be based on a user_id in your system or a random number
$customerProfile->merchantCustomerId = 10;
$customerProfile->email = "somebodyiused@toknow.com";
// Add Credit Card
$paymentProfile = new AuthorizeNetPaymentProfile;
$paymentProfile->customerType = "individual";
$paymentProfile->payment->creditCard->cardNumber = "4111111111111111";
$paymentProfile->payment->creditCard->expirationDate = "2015-10";
$customerProfile->paymentProfiles[] = $paymentProfile;
// Add Bank Account
// Note the routing/account numbers have to be correct in length
$paymentProfile = new AuthorizeNetPaymentProfile;
$paymentProfile->customerType = "individual";
$paymentProfile->payment->bankAccount->accountType = "checking";
$paymentProfile->payment->bankAccount->routingNumber = "011000015";
$paymentProfile->payment->bankAccount->accountNumber = "1010169857507";
$paymentProfile->payment->bankAccount->nameOnAccount = "Jesse Boyer";
$paymentProfile->payment->bankAccount->bankName = "Not Bank of America!";
$customerProfile->paymentProfiles[] = $paymentProfile;
// Add shipping address.
$address = new AuthorizeNetAddress;
$address->firstName = "Jesse";
$address->lastName = "Boyer";
$address->company = "JREAM";
$address->address = "12 Florida";
$address->city = "Orlando";
$address->state = "FL";
$address->zip = "32810";
$address->country = "USA";
$address->phoneNumber = "555-555-5555";
$address->faxNumber = "555-555-5555";
$customerProfile->shipToList[] = $address;
$response = $request->createCustomerProfile($customerProfile);
// To see if it worked
if ($response->isOk()) {
echo "Its All Good!";
}
print_r($response);
Charging the CIM User
So you can a user in your CIM manager very easily. With their securely stored information you can bill them monthly, manually, or just keep their card/ach stored securely. It’s easy to charge through CIM. You simply use the same CIM API and pass in the user_id and payment_profile_id, check it out:
// Load this bad boy up and start a AuthorizeNetTransaction
$request = new AuthorizeNetCIM("AUTHNET_LOGIN", "AUTHNET_KEY");
$transaction = new AuthorizeNetTransaction;
$transaction->amount = "100.00";
// This is the ID you which created above
$transaction->customerProfileId = 10;
// This is the ID from the response above (the print_r) with whatever
// payment profile ID you are charging
$transaction->customerPaymentProfileId = 12345678;
// Process it
$response = $request->createCustomerProfileTransaction("AuthCapture", $transaction);
// Then dump out the transaction!
print_r($response);
Other Parameters
You can find out all the other parameters to pass by reading their PDF Doc. You would use the same structure
as you did above in objects rather than XML (Because the classes write the XML for you).
Lastly, make sure to turn off TEST mode in your account.