• Select Distinct With Conditions in MySQL

    The other day I ran into an interesting problem with an SQL query, I needed to create the count() of all items and the count() of a specific set of items. Normally, I would use subqueries but there was so much data that the subqueries took a minute and that was not acceptable to our client (I actually wrote the query originally with a small amount of data and after 4 years the performance of it was horrible. :-)).

    Read on to see how to fix this.

    Read More
  • Ignoring File Changes in a File Using GIT

    The other day I ran into an interesting issue with a Git repository. We needed to have a file included in a repo so it would would get created but we didn’t want to track any of the changes (in this case it was a log file from a legacy application). Normally, if we want to ignore a file inside a repo we add it to a .gitignore file but that wouldn’t work in this case because that would completely ignore the file or track the changes after we’ve added it.

    Git has a quick feature that takes the file and ignores any change to it:

    git update-index --assume-unchanged path/to/file.txt
  • Link Post and Podcast Roundup: December 2016 Edition

    It’s hard to believe it’s December already. :-)

    Read More
  • Maximizing Your Efficiency in Sublime Text - EditorConfig

    One of the things you’ll find annoying if you’re trying to adhere to the PSR standards is that it’s hard to notice things like extra spaces at the end of lines and that you don’t have a blank line at the end of your file. You can run something like phpcbf to fix the file before you commit (and that’s a perfect option which will discuss in another article) but it’s nice to have sublime clean up whenever possible before you save.

    The EditorConfig file is a file format that allows you to define how the editor should save files of specific types. Sublime Text has support through a plug-in named conveniently enough EditorConfig.

    Read More
  • Maximizing Your Efficiency in Sublime Text - Plug-ins

    Another feature that makes Sublime Text a little easier to work with is Plug-ins. Like all plug-in systems, Sublime Text’s Plug-in system allow for developers to extend Sublime Text’s functionality without having to submit a pull request or bloat the core. There are a huge number of plug-ins to pick from but I’m going focus on several that I’ve found to be very helpful in my PHP development.

    Read More
  • Link Post and Podcast Roundup: November 2016 Edition

    Read More
  • Fixing the logrotate "bad file mode" error

    On one of the servers I manage I was troubleshooting a problem where logrotate (check out our guide for setting up logrotate on a custom file) wasn’t running on a set of files. To troubleshoot problems with logrotate I always run the command with a specific configuration and the force (-f) and verbose (-v) options:

    # logrotate -f -v /etc/logrotate.d/log.log
    Ignoring /etc/logrotate.d/log.log because of bad file mode.
    Handling 0 logs

    I assumed it was having trouble with the file it was trying to rotate so I messed with those permissions for a while but then I looked at the permissions on the configuration file:

    # ls -l /etc/logrotate.d/log.log
    -rw-rw-rw- 1 root root 137 Oct  5 12:42 /etc/logrotate.d/log.log

    Logrotate doesn’t like the fact that other people can write to the file so I changed the permissions so only root had write access:

    # chmod 644 /etc/logrotate.d/log.log
    # ls -l /etc/logrotate.d/log.log
    -rw-r--r-- 1 root root 137 Oct  5 12:42 /etc/logrotate.d/log.log

    Then everything worked.

    # logrotate -d -v /etc/logrotate.d/log.log
    reading config file /etc/logrotate.d/log.log
    Handling 1 logs
    rotating pattern: /var/log/resque_worker/log.log  weekly (52 rotations)
    empty log files are not rotated, old logs are removed
    considering log /var/log/resque_worker/log.log
  • TIL: Vagrant Installs VirtualBox

    As part of my morning fighting with Windows 10 Anniversary I learned something new. If vagrant can’t communicate with VirtualBox it will try to install the version it was tested with:

    > vagrant up devel
    ==>  Provider 'virtualbox' not found. We'll automatically install it now...
         The installation process will start below. Human interaction may be
         required at some points. If you're uncomfortable with automatically
         installing this provider, you can safely Ctrl-C this process and install
         it manually.
    ==>  Downloading VirtualBox 5.0.10...
         This may not be the latest version of VirtualBox, but it is a version
         that is known to work well. Over time, we'll update the version that
         is installed.
         Progress: 100% (Rate: 590k/s, Estimated time remaining: --:--:--)
    ==>  Installing VirtualBox. This will take a few minutes...
         A couple pop-ups will occur during this installation process to
         ask for admin privileges as well as to install Oracle drivers.
         Please say yes to both. If you're uncomfortable with this, please
         install VirtualBox manually.

    In my case it didn’t work because I already had a newer version of VirtualBox installed:

    Vagrant has detected that you have a version of VirtualBox installed
    that is not supported by this version of Vagrant. Please install one of
    the supported versions listed below to use Vagrant:
    4.0, 4.1, 4.2, 4.3, 5.0
    A Vagrant update may also be available that adds support for the version
    you specified. Please check to download
    the latest version.
  • Vagrant up error with Windows 10 Anniversary

    This morning my work laptop rebooted and installed Windows 10 Anniversary. When I tried to run vagrant up I ran into some problems:

    > vagrant up devel
    Bringing machine 'devel' up with 'virtualbox' provider...
    ==> devel: Checking if box 'ubuntu/trusty64' is up to date...
    ==> devel: A newer version of the box 'ubuntu/trusty64' is available! You currently
    ==> devel: have version '20160318.0.0'. The latest is version '20160926.0.1'. Run
    ==> devel: `vagrant box update` to update.
    ==> devel: Clearing any previously set forwarded ports...
    ==> devel: Clearing any previously set network interfaces...
    ==> devel: Preparing network interfaces based on configuration...
        devel: Adapter 1: nat
        devel: Adapter 2: hostonly
    ==> devel: Forwarding ports...
        devel: 22 (guest) => 10422 (host) (adapter 1)
        devel: 80 (guest) => 10480 (host) (adapter 1)
    ==> devel: Running 'pre-boot' VM customizations...
    ==> devel: Booting VM...
    There was an error while executing `VBoxManage`, a CLI used by Vagrant
    for controlling VirtualBox. The command and stderr is shown below.
    Command: ["startvm", "6e7619dd-3bbb-41d8-a4af-c10dadb4175c", "--type", "headless"]
    Stderr: VBoxManage.exe: error: The virtual machine 'devel' has terminated unexpectedly during startup with exit code -1073741819 (0xc0000005)
    VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component MachineWrap, interface IMachine

    The only solution I found to this was to:

    1. Uninstall VirtualBox
    2. Install the current version of VirtualBox
    3. Update Vagrant
    4. Reboot

    Just in case someone else needs help. :-)

  • Link Post and Podcast Roundup: October 2016 Edition

    Read More

subscribe via RSS