Posts

  • Link Post and Podcast Roundup: May 2016 Edition

    Here are this months links…

  • Validating Last Names

    Most of my life I’ve been a Warren. When my wife and I got married we decided to take each others names and my last name became Keck-Warren. My assumption was that it would be hard to get the DMV to change my license but then I would be on my way.

    But I was wrong. It turns out that it was easier to get some of my socially conservative family members to understand than it was to get some computer systems.

    Why This is Stupid

    People have crazy names and if you create a barrier that prevents then from signing up because their last name has a space or a hyphen they’ll go somewhere else. It also causes all kinds of information mismatches between sites and systems.

    Insurance

    I had to visit a hospital for a couple tests right after I changed my name and their computer systems didn’t accept hyphenated last names. I was shocked that a hospital’s computer system wouldn’t allow the hyphen. We were able to move on through the process by removing the hyphen but the real problem started when they tried to bill my insurance. My insurance had a hyphen in my last name but the hospital didn’t. Because of this mismatch it caused my insurance to reject the claim.

    This was strike on against this hospital and I haven’t been back.

    Site Registration

    Several times over the last couple years I’ve tried to sign up at various websites only to be told that my last name isn’t valid. My first fix is to remove the hyphen and that usually fixes the problem.

    What You Can Do To Help

    Test your sites signup process with common last name “oddities” things like Keck-warren, O’Connor, “van der Wall”, and McDonald. Test with non-latin names like Авандеев and قذافي‎. Everything you can do to make sure new users can get in because the rest of us non-alpha character last name people will thank you and you might end up with a few more customers.

  • Rotate a Custom Log File in Ubuntu

    As developers it’s super helpful to log information to a file so we can retrieve it later. The problem we run into is that over time those log files can take up a lot of space so it’s important to clean them up. We could do that manually by logging into the server and manually deleting them but that’s time consuming and it would be better if we could just have the server do it automatically.

  • Fixing the "fork failed - Cannot allocate memory" Error When Running Composer

    The other day I tried to install the FOS User Bundle but I received the following error:

    $ php composer.phar require friendsofsymfony/user-bundle "~2.0@dev"
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
      - Installing friendsofsymfony/user-bundle (dev-master 16b04c4)
        Cloning 16b04c49af05dd3fb381e4abe04f0e5e231ac76d
    
    Installation failed, reverting ./composer.json to its original content.
    The following exception is caused by a lack of memory and not having swap configured
    Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details
    
    PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///var/www/composer.phar/vendor/symfony/console/Application.php:954
    Stack trace:
    #0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///var/www...', 954, Array)
    #1 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(954): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
    #2 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(754): Symfony\Component\Console\Application->getSttyColumns()
    #3 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(715): Symfony\Component\Console\Application->getTerminalDimensions()
    #4 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(648): Symfony\Component\Console\Application->getTerminalWidth()
    #5 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(130): Symfony\Component\Console\Application->renderException(Object(ErrorException), Object in phar:///var/www/composer.phar/vendor/symfony/console/Application.php on line 954
    
    Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///var/www/composer.phar/vendor/symfony/console/Application.php:954
    Stack trace:
    #0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///var/www...', 954, Array)
    #1 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(954): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
    #2 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(754): Symfony\Component\Console\Application->getSttyColumns()
    #3 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(715): Symfony\Component\Console\Application->getTerminalDimensions()
    #4 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(648): Symfony\Component\Console\Application->getTerminalWidth()
    #5 phar:///var/www/composer.phar/vendor/symfony/console/Application.php(130): Symfony\Component\Console\Application->renderException(Object(ErrorException), Object in phar:///var/www/composer.phar/vendor/symfony/console/Application.php on line 954

    In order to solve this problem I had to setup a swap file:

    $ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
    1024+0 records in
    1024+0 records out
    1073741824 bytes (1.1 GB) copied, 1.54095 s, 697 MB/s
    $ sudo /sbin/mkswap /var/swap.1
    Setting up swapspace version 1, size = 1048572 KiB
    no label, UUID=035dd6b9-2ff5-4597-bc7d-3f89f478e855
    $ sudo /sbin/swapon /var/swap.1
  • Fixing the "You are not allowed to access this file. Check app_dev.php for more information." error

    If you attempt to access your application running inside a Vagrant VM using app_dev.php you’ll receive the following error:

    You are not allowed to access this file. Check app_dev.php for more information.

    If you look into your app_dev.php file you’ll see a line that looks like the following:

    // This check prevents access to debug front controllers that are deployed by accident to production servers.
    // Feel free to remove this, extend it, or make something more sophisticated.
    if (isset($_SERVER['HTTP_CLIENT_IP'])
        || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
    ) {
        header('HTTP/1.0 403 Forbidden');
        exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
    }

    The important part is this line:

    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')

    This line looks at the IP address you’re using to access the system and makes sure it’s referring to the “local” computer. There are a couple options to fix this. This first is that you can just remove this line and then delete the app_dev.php file when you deploy. This could create a potential security problem because if you forget to remove it someone could access it and use the dev tools.

    The better option is to add your local computers IP address to the list. To do this we’re going to change the exit function so it outputs you’re IP address.

    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information. You're IP:  . $_SERVER['REMOTE_ADDR']);

    Now if you try to access the site you’ll get your IP address:

    You are not allowed to access this file. Check app_dev.php for more information. Your IP: 192.168.56.1

    Then you just need to add your IP to the list:

    if (isset($_SERVER['HTTP_CLIENT_IP'])
        || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1', '192.168.56.1']) || php_sapi_name() === 'cli-server')
    ) {
        header('HTTP/1.0 403 Forbidden');
        exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information. Your IP: ' . $_SERVER['REMOTE_ADDR']);
    }
  • Link Post and Podcast Roundup: April 2016 Edition

    Aprils links just a few days late.

  • Fixing the "const_get: wrong number of arguments" error when installing Resque on Ubuntu 12.04

    I was setting up a virtual server that’s using resque to perform background jobs and when I ran into the following error:

    $ resque-web
    /var/lib/gems/1.8/gems/rack-1.6.4/lib/rack/handler.rb:22:in `const_get': wrong number of arguments (2 for 1) (ArgumentError)
            from /var/lib/gems/1.8/gems/rack-1.6.4/lib/rack/handler.rb:22:in `get'
            from /var/lib/gems/1.8/gems/vegas-0.1.11/lib/vegas/runner.rb:280:in `setup_rack_handler'
            from /var/lib/gems/1.8/gems/vegas-0.1.11/lib/vegas/runner.rb:278:in `each'
            from /var/lib/gems/1.8/gems/vegas-0.1.11/lib/vegas/runner.rb:278:in `setup_rack_handler'
            from /var/lib/gems/1.8/gems/vegas-0.1.11/lib/vegas/runner.rb:36:in `initialize'
            from /var/lib/gems/1.8/gems/resque-1.26.0/bin/resque-web:13:in `new'
            from /var/lib/gems/1.8/gems/resque-1.26.0/bin/resque-web:13
            from /usr/local/bin/resque-web:19:in `load'
            from /usr/local/bin/resque-web:19

    After a lot of fighting I learned that Sinatra wasn’t compatible with rack 1.6.x so the only way to fix the problem was to downgrade to a version that worked. After much testing it appears that 1.5.5 was the last version that worked.

  • Fixing Vagrant "Warning: Remote connection disconnect. Retrying Connection" Error

    Today when I tried to boot a VM I got a scary message:

    > vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Clearing any previously set forwarded ports...
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
        default: Adapter 2: hostonly
    ==> default: Forwarding ports...
        default: 22 (guest) => 2223 (host) (adapter 1)
        default: 80 (guest) => 8080 (host) (adapter 1)
        default: 4444 (guest) => 4444 (host) (adapter 1)
        default: 3306 (guest) => 3306 (host) (adapter 1)
    ==> default: Running 'pre-boot' VM customizations...
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
        default: SSH address: 127.0.0.1:2223
        default: SSH username: vagrant
        default: SSH auth method: private key
        default: Warning: Remote connection disconnect. Retrying...
        default: Warning: Authentication failure. Retrying...
        <snip>
        default: Warning: Authentication failure. Retrying...
    Timed out while waiting for the machine to boot. This means that
    Vagrant was unable to communicate with the guest machine within
    the configured ("config.vm.boot_timeout" value) time period.
    
    If you look above, you should be able to see the error(s) that
    Vagrant had when attempting to connect to the machine. These errors
    are usually good hints as to what may be wrong.
    
    If you're using a custom box, make sure that networking is properly
    working and you're able to connect to the machine. It is a common
    problem that networking isn't setup properly in these boxes.
    Verify that authentication configurations are also setup properly,
    as well.
    
    If the box appears to be booting properly, you may want to increase
    the timeout ("config.vm.boot_timeout") value.

    The odd part was if I tried to manually SSH into the VM I received a password prompt which isn’t supposed to happen.

    > vagrant ssh default
    vagrant@127.0.0.1's password:
    Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com/
    New release '14.04.1 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.
    
    Welcome to your Vagrant-built virtual machine.
    Last login: Mon Mar 21 20:28:37 2016 from 127.0.0.1

    To fix this problem I needed to “reset” the authorized_keys file to the default:

    wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O ~/.ssh/authorized_keys
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    chown -R vagrant:vagrant ~/.ssh

    After another vagrant command Vagrant automatically replace the default file with one specific to my computer and we were back off to the races.

    > vagrant halt
    ==> default: Attempting graceful shutdown of VM...
        default:
        default: Vagrant insecure key detected. Vagrant will automatically replace
        default: this with a newly generated keypair for better security.
        default:
        default: Inserting generated public key within guest...
        default: Removing insecure key from the guest if it's present...
        default: Key inserted! Disconnecting and reconnecting using new SSH key...
  • 6 Things I Learned From Modern PHP: New Features and Good Practices

    Modern PHP: New Features and Good Practices

    I recently read Modern PHP: New Features and Good Practices and I thought I would pass along several things that I learned while reading the book.

  • Jekyll Hickups

    Today marks the one month mark of my move to Jekyll so I thought I would recount some issues I’ve run into.

    Feedburner

    On my Wordpress installation I installed a plugin that redirected RSS subscribers from the feed hosted on the site to Feedburner so I could get statistics about all of you who are subscribing. I checked my statistics and my subscribers went to zero:

    Zero Subscribers

    The problem was that the link on my Wordpress install pointed to /feed/ and the plugin redirected the folder to the correct Feedburner URL. The fix was to add a redirect to the site’s configuration:

    # redirect /feed/ to feedburner
    Redirect 301 /feed http://feeds.feedburner.com/ThisProgrammingThing

    Increase in 404 errors

    On the 15th, I received the following error in my email:

    Googlebot identified a significant increase in the number of URLs on...

    I check the errors and it was mostly /category/ and /tag/ pages that Wordpress creates automatically. Normally people don’t usually use these so I’m not too worried.

    Broken Images in RSS

    I only post some images but I noticed that the following happened when I looked at my RSS feed:

    Broken Images in RSS

    The fix to this is to prepend all image links with {{site.url}}.

    {{site.url}}/assets/2016/brokenimages.png
    

    The horrible downside to this is that {{site.url}} is www.thisprogrammingthing.com and not dependent on what’s being served (which makes sense). So I have to upload all my images to the live server when I’m checking my post because it looks like this otherwise:

    Broken Images in Post

subscribe via RSS