Working Ninja


Enable the "Start up automatically after a power failure" feature found within OS X without OS X installed.


  1. Find the LPC controller via lspci.
  2. Reference the LPC controller datasheet to find the register to update.
  3. Update the register with setpci.
  4. Test.
  5. Add the setpci command to crontab.

I'll be performing the following steps on a 2008 MacBook 4,1. Similar steps should be successful with other models.

1. Find the LPC controller via lscpi.

$ lspci | grep LPC
00:1f.0 ISA bridge: Intel Corporation 82801HM (ICH8M) LPC Interface Controller (rev 04)

Note the PCI address (00:1f.0) of our LPC Interface Controller. This will be referenced later with the setpci command.

2. Reference the LPC controller datasheet to find the register to update.

Searching the Internet for "82801HM datasheet" yields this datasheet from Intel. After opening the PDF, find the page for "AFTERG3_EN" via the Appendix A Register Bit Index (at the end of the PDF): GEN_PMCON_3—General PM Configuration 3 Register (PM—D31:F0)  

Offset Address: A4h
Default Value: 00h
Lockable: No
Attribute: R/W, R/WC
Size: 16-bit
Usage: ACPI, Legacy
Power Well: RTC

Bit: 0
Description: AFTERG3_EN — R/W. This bit determines what state to go to when power is re-applied after a power failure (G3 state). This bit is in the RTC well and is not cleared by any type of reset except writes to CF9h or RTCRST#.

0 = System will return to S0 state (boot) after power is re-applied.
1 = System will return to the S5 state (except if it was in S4, in which case it will return to S4). In the S5 state, the only enabled wake event is the Power Button or any enabled wake event that was preserved through the power failure. NOTE: Bit will be set when THRMTRIP#-based shutdown occurs.

From the above, we find that our register location is 0xA4 (A4h) with bit 0 (AFTERG3_EN) being the one that controls whether or not to power on the device after a power failure. Setting this bit to 0 will power on the machine.

3. Update the register with setpci.

Get the current value (should be 1):

$ sudo setpci -v -s 00:1f.0 0xa4.b

Set the bit to 0, per our datasheet:

$ sudo setpci -v -s 00:1f.0 0xa4.b=0

This is where I get lost. I do not see how we are setting just bit 0 to 0 with the above line. Searching online yields the same command for similar devices and different commands for others (who's manuals I cannot find online).

Verify that the bit is now set to 0:

$ sudo setpci -v -s 00:1f.0 0xa4.b

4. Test.

Shutdown the machine and disconnect the power supply.

5. Final Things

The AFTERG3_EN bit is reset to its default at reboot, so lets add the above command to our crontab (as root):

@reboot /usr/bin/setpci -s 00:1f.0 0xa4.b=0



Before stumbling upon this module, whenever I connected to my audio receiver via Bluetooth, I had to change the Pulseaudio sink as well as set the default output. Thankfully there is an easy fix that will do both of these when a new sink is available.

Add the following to /etc/pulse/ Or better yet, if you haven't already, create a local config for Pulse audio at ~/.config/pulse/

.include /etc/pulse/
load-module module-switch-on-connect

Now if only I had stumbled upon this before attempting to write a custom udev rule!



Python 2.7 is not provided on CentOS 6 because Yum depends on Python 2.6. Simply installing 2.7 over 2.6 will break Yum. Thankfully, Red Hat provides us with an alternate installation method through their SCL project.

First, get Python 2.7 installed:

Next, add the project path to the top of the script:

import sys

Lastly, call the script via Cron:

cat /path/to/project/ | scl enable python27 python

Using IUS (Inline with Upstream Stable)--a nifty repository provided by EPEL--we can upgrade beyond PHP 5.4 by first removing our current version of PHP, installing our preferred version (5.6 in our case), and then restarting Apache:

$ sudo yum remove php-cli mod_php php-common

$ sudo yum install mod_php56u php56u-cli php56u-mysqlnd

$ sudo apachectl restart



Renewing an SSL but can't recall exactly how it was filled out last time? Try the following:

openssl req -text -in request.csr

The above command will decode the CSR file and output its contents in human readable text. Enjoy!

More here:


Sometimes it is necessary to resize partitions (e.g. updates to GitLab require additional space on /opt). Here's what we need to do. If you have an LVM parition, you're in luck! Things are pretty straightforward.

  1.   Run vgdisplay (Volume Group Display) to verify we have space to expand our partition.
    •     The line PE Free / Size should have space available.
  2.   Next, add space to the parition with lvresize (Logical Volume Resize):
    sudo lvresize --size +100M /dev/mapper/opt
  3.   Now that the volume has been expanded, let's commit those changes to the filesystem:
    sudo xfs_growfs /dev/mapper/opt



Here's a simple way to count lines of code via the command line that I recently used for a Django project:

find . -name '*.py' -not -path "*/migrations/*" | xargs wc -l


wc -l **/*.py


dd if=<path to input file> | pv -s <size e.g. 1377M> | dd of=<path to target device>



To swap control and command, add the following to your ~/.Xmodmap file:

remove control = Control_L
remove mod4 = Super_L Super_R

keysym Control_L = Super_L
keysym Super_L = Control_L
keysym Super_R = Control_L

add control = Control_L Control_R
add mod4 = Super_L Super_R

The above current works for both an Apple laptop and an Apple keyboard.

Also, to use Command+Tab to cycle windows, make sure to update keyboard shortcuts to use Ctrl+Tab instead of Alt+Tab (for Xfce, Window Manager -> Keyboard). All other keyboard shortcuts should come through (from the Control to Command swap perspective).



The Old Way

import os

os.system('find /home/user/documents -type f -iname "*.doc"')

The New, Recommended Way

import subprocess

    '-type', 'f',
    '-iname', '*.doc'

Bonus Tidbit

At this point, we can incorporate some nice exception handling:

import subprocess

        '-type', 'f',
        '-iname', '*.doc'
except subprocess.CallProcessError as e:
    print e.returncode
    print e.cmd
    print e.output

See the official Python Documentation for more usage and recommendations on the subprocess module.