Using Webpack’s hot module reloading with an Apache Backend

http://webpack.github.io/docs/webpack-dev-server.html#combining-with-an-existing-server

Even though it doesn’t look like it, everything that you need to know is placed in that blurb.  If you pay attention to the port numbers, the backend is placed on port 9090 and the webpack-dev-server is placed on port 8080.

So the idea is that your backend on port 9090 will be responsible for serving that preliminary html file.  Inside of that html file, the script tag will be pointing toward localhost on port 8080, the webpack-dev-server.

Then you follow the rest of the instructions and it should work just fine.

Incidentally, the root directory was inside of a subdirectory for me, let’s call it “WPExperimental”.  I would navigate to it by going to localhost/WPExperimental/index.html

Also, let’s put all assets under the “asset” folder.

So when writing out the configurations, script src in the html page will point to:

and the output publicPath in the webpack config file will be set to:

 

index.html is located under the WPExperimental subfolder.  As we mentioned before, pulling the webpage means that we can navigate to in the web browser’s address bar:

Notice how I’m using port 9090?  That’s the backend address and we want it to serve the initial template.

And voila.  You set in place a system where you navigate like normal with your backend server, however the javascript stuff are going to be served separately from the webpack_dev_server.

Incidentally, when it’s time to take it to production, I was planning on using Twig, a PHP templater, to mess with the script src link.  Something like

Where rootdir:

equals “http://localhost:8080/WPExperimental/” when DEBUG tokens are enabled.

and equals “/WPExperimental/” when DEBUG tokens are not enabled.

INNER JOINS with LEFT JOINS

In this scenario, I was attempting to Left Join a table to another table and Inner Joining them to a third table.  I ended up getting no results from the query.

A bit of research found this link:

http://www.sitepoint.com/forums/showthread.php?769412-Combining-Left-and-Inner-Joins

In short, you have to perform the Inner Joins first before you Left Join.

My solution was to Left Join the entire way.  My reason for the Inner Join in the first place, and the reason why I’m unsure of this method was that it seemed like a good way to kill performance.  However, I’m not at the stage where I need to kill time performance tuning the system so I’ll have to ignore it for now.

I’m probably wrong anyway, but it wouldn’t hurt to check when I finally get the time.

Differences between ON AND VS WHERE in SQL for Outer Joins

When joining, I like to use ON + AND a lot.  I heard that this tends to have better performance than running a WHERE query.  And it worked well as long as I stayed with INNER JOINS.  Imagine my surprise when I needed to do a LEFT JOIN while performing a conditional match.  I expected a single row back, but SQL returned every single possible row instead.

After searching around, I found this link:

http://www.codeproject.com/Articles/231132/Difference-between-And-clause-along-with-on-and-Wh

Currently, I’m building up a website, so I can’t begin using Explain to tune.  In the meantime, I’m going to use WHERE to filter the list whenever I have an Outer join.  If this ends up killing performance, I’ll have to find a way to alter the queries later.

PHP Empty Multidimensional Arrays

Discovered today that running empty() on a multidimensional array returns false.

http://forums.phpfreaks.com/topic/183410-checking-if-multidimensional-array-is-empty/

To get around this, I propose using array_filter on the multidimensional array first.  I’m betting this will not work for an array within an array within an array, but it seems to work fine for an array within an array.

So:

Creating Local Git Repositories with Sourcetree

Storing a repository locally on your hard drive sort of defeats the purpose behind Git’s design…it’s not on a remote server with timely backups, and you’re basically the only one who can access and maintain it.

That said, it is a viable solution if you happen to like using Git and you have the following reasons for doing it:

  • You’re using Windows
  • You want to version control your own code
  • You want to keep your code in your hands and not some server several hundred miles away.
  • You don’t have a convenient local area network computer to store the repository.

Surprisingly, it isn’t as difficult as most solutions make it out to be.  In fact, you do not need to run your own Git server.  All you need is a git client.  Then, using the client, you create two repositories instead of one.  And then have one repository point to the other as the remote.

You have to deal with one problem however, pushing will probably throw an error.  Git will refuse to push because the remote has a checked out branch.

http://stackoverflow.com/questions/11117823/git-push-error-refusing-to-update-checked-out-branch

There are three different solutions:

  1. Create a bare repository
  2. Create and check out a dummy branch on the remote repository
  3. Edit the configuration files to ignore this check

I’m going to cover two of them since the third one strikes me as interesting, but bad practice.  The first solution cannot be done using Sourcetree alone.  Creating a bare repository:

https://answers.atlassian.com/questions/172509/how-do-i-create-clone-a-bare-repository-in-sourcetree

What is a bare repository?

Bare repository is the one that has no working tree. It means its whole contents is what you have in.git directory.

You can only commit to bare repository by pushing to it from your local clone. It has no working tree, so it has no files modified, no changes.

To have central repository the only way it is to have a bare repository.

I included the above quote to basically say that a bare .git repository is just going to have a .git folder with stuff inside.  Nothing else will be in that directory, so if you do have source code in that directory, do not be afraid if they are not being updated whenever you push.

In Git you should only use a “bare” repository to clone and pull from, and push to. It doesn’t have a checked out tree, so it just does what the “server” notionally does in a centralized VCS – records commits, branches, etc when you push to it, and gives you the latest versions when you clone or pull from it.

I suppose I should also say that I’m throwing all the above links because I saw a stack overflow comment about how online repositories like GitHub are basically bare .git repositories, but I lost the link. Or maybe I didn’t…

There are two types of repositories: bare and non-bare

Bare repositories do not have a working copy and you can push to them. Those are the types of repositories you get in Github! If you want to create a bare repository, you can use

So, in short, you can’t push to a non-bare repository (Edit: Well, you can’t push to the currently checked out branch of a repository. With a bare repository, you can push to any branch since none are checked out. Although possible, pushing to non-bare repositories is not common). What you can do, is to fetch and merge from the other repository. This is how the pull request that you can see in Github works. You ask them to pull from you, and you don’t force-push into them.

But, as said before, you cannot create a remote repository using sourcetree alone.  Converting a remote repository to a bare repository can be done using the following method:

You can simply convert your remote repository to bare repository (there is no working copy in the bare repository – the folder contains only the actual repository data).

Execute the following command in your remote repository folder:

Then delete all the files except .git in that folder. And then you will be able to perform git push to the remote repository without any errors.

As said twice before, you can’t use Sourcetree to do the above.  However, you can download and use Git from the command line to pull it off:

http://git-scm.com

Which leads to our second solution…how can you push to the local (remote) repository using sourcetree?

The answer is to go to the second repository and create a dummy branch.  Then check out the dummy branch.  Now you can use the first repository to push to the second repository.

Remind me that I need to add how-to create the repositories later.

 

Preventing Post Resubmission

http://stackoverflow.com/questions/11377259/form-is-resubmitted-when-the-back-button-is-pressed

The above link had some good links inside.  I’ve attached them below:

http://stackoverflow.com/questions/3923904/preventing-form-resubmission

http://stackoverflow.com/questions/660329/prevent-back-button-from-showing-post-confirmation-alert

 

The following link contains info on how to do it server side.

http://bjw.co.nz/developer/general/75-how-to-prevent-form-resubmission

Sql Patterns

http://stackoverflow.com/questions/1382842/mysql-insert-joins