Posts

  • Speeding Up Site Generation in Jekyll

    When I work on my site I start jekyll using the following command line:

    jekyll serve --future --drafts

    I like this because it shows me what I’m working on and regenerates the files as things are updated:

    Regenerating: 1 file(s) changed at 2016-05-22 14:24:25 ...done in 5.648222 seconds.
    Regenerating: 1 file(s) changed at 2016-05-22 14:24:43 ...done in 5.055759 seconds.

    The downside to this is that if I’m quickly switching between proof reading a post and editing a post it gets a little slow waiting 5+ seconds for the page to regenerate (you should try it). I started looking into the documentation for jekyll serve and there’s an option that allows you to limit how many posts it uses:

    jekyll serve --limit_posts 50 --future --drafts

    This cuts down the time required to see my changes:

    Regenerating: 1 file(s) changed at 2016-05-22 14:25:29 ...done in 1.168727 seconds.
    Regenerating: 1 file(s) changed at 2016-05-22 14:25:49 ...done in 0.96031 seconds.

    That 4 seconds makes a huge difference.

  • Lessons Learned from My First Symfony Project

    I’m writing this post for two reasons:

    1. So others can learn from my mistakes
    2. So I have this documented somewhere other than my laptop

    This post is almost completely a copy and paste job of the notes I created while I was building my last project using Symfony.

  • Setting the Execute Bit on a File in GIT

    I do all of my primary development work on a Windows computer that runs several Vagrant VMs. The other day I needed to add an executable to my repo and have it be automatically marked as an executable file on all the servers (this project isn’t running Ansible yet so it’s not an option).

    If I was running a fully Linux development environment I could just do the following:

    chmod +x /path/to/file
    git add /path/to/file
    git commit -m "Added file"

    But this doesn’t work because of the way Virtual Boxes virtual folders work. In order to do this I need to run the following in Windows:

    git update-index --chmod=+x /path/to/file

    Then I can commit the file and it will be marked as executable when it gets git pulled to the server.

  • 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.

subscribe via RSS