Vagrant + Windows 10 Fix

Have you run into something like this and are tearing out your hair trying to get past it?

After more time than I would like to admin, I found the fix. The first step is to download the file found here, created by Jiri Hruska (known to the Internet as Yirkha).

You have to run it as an Administrator, and it will pop up this box:








Then you need to find VirtualBox in Windows Explorer and set VBoxManage.exe  and VBoxHeadless.exe to run in Windows 7 Compatibility Mode. To do this, you right click on the file, go to Properties, then Compatibility, and use the box for setting it.

On my system, those files are located in C:\Program Files\Oracle\VirtualBox

Now when you run vagrant up, it should get past the network adapter error because that little tool increases the timeout values for you.

If you want to see the full context of how this fix came to be and read more, take a look at VirtualBox Ticket #14040.

Javascript Wait Until jQuery Loads

Ok, if you are like me, you’ve probably had the need to put a small snippet of Javascript between some <script> tags in a view. But, if the rest of your javascript is loaded somewhere in the footer of your layout, then at the point you run that embedded snippet, none of your other libraries will have been loaded.

Allow me to introduce you to a little technique that can be an interesting workaround. I can’t claim to have found this trick as I ran across it on an awesome StackOverflow answer.

Allow me to explain what is going on here.  You will notice the function is wrapped with parenthesis followed by another set of parenthesis. This is called an immediately invoked function expression (IIFE), which is a fancy way of saying that it will run automatically when the code is loaded. When it runs, it checks to see if the window.jQuery object exists and if not, it sets a timeout for 50ms and tries again. This will continuously loop until it detects that the jQuery object exists in the global namespace and will then run your code.

This doesn’t only apply to jQuery. For my use case, I had a javascript object that I needed to set a counter based on values loaded in from a form with dynamic sections. This is  how I made that work:

You will notice the {{ … }} syntax in there. That is the blade templating language in Laravel. For my use case, I needed to generate 0 to N instances of a template and keep track in javascript how many I had so that the next instance generated client side had the appropriate numbers applied to input field names. Probably not the best way to do things, but definitely functional.


PDO Query Nuance: UPDATE WHERE IN Only Updates One Row

I prefer to always use parameterized queries in PDO when possible. Just now, I encountered a situation in which the complications of using them would have not even been worth it. Take a look at this query:

Given that the post_id‘s exist, this will set a deleted flag on all of them right? Ok, let’s try to define that query using PDO and prepared statements…

As it turns out, that will ONLY update the first row. Turns out, the IN clause is a little more complicated than I thought with prepared statements. There is a proposed solution here, but in my case, the data is not user input and can thus sanitize it myself.

Learning Ruby on Rails

completed-rails-for-zombies-redux-cb1011b0ed5f8bb98c97e8e97d7faa3eAs a PHP developer, I’ve always been fascinated with Ruby, specifically the Rails framework. I’ve always felt like I am missing out on something. Recently, I’ve started making a push in my limited spare time to get familiar with the language and idioms of Rails. I’m proud to say, thus far, I have completed the Rails For Zombies course over at Code School. In case you are curious, here is my CodeSchool “Report Card”.

Next steps? I’m going to work on building a rails app from the ground up and learn as I go. As a self-taught developer, I’ve found that spending hours readings the documentation and poring over questions in StackOverflow really helps me to grok the material.

Also, I’ve found a couple other options for learning Ruby.


WordPress Solution: Is its parent directory writable by the server?

There are two common reasons for the error: Unable to Create Directory /abc/def/xyz: Is its parent directory writable by the server?

1) This is the obvious one, and many people try this first and it may not help. You need to make sure your uploads folder located by default in wp-content/uploads and all folders/files below it are writable by the server. The easiest way to do this is to change the permissions to 777 recursively.

2) If #1 didn’t work, then your issue is most likely this: Go to your WordPress Admin Interface -> Settings -> Media and look at the value for the “Store uploads in this folder” setting. It should be “wp-content/uploads” by default but sometimes I’ve seen mine change on a whim to attempt a full server path and ends up breaking. Change it back to the default and it will probably work fine.

If it’s still not working, comment below and we’ll see if we can figure it out.