Quick thoughts on IT, fun projects, and the singularities I come across.
  • Electronics Projects

    Electronics Projects

  • Coding Projects

    Coding Projects

HTML5 Resume Template

HTML5ResumePreview

HTML5ResumePreview

I’ll keep this short since it’s not a proper how-to post or lengthy tutorial. I recently discovered a resurgence in the concept of HTML resumes and was thoroughly impressed. As always, I recklessly decided I should take a stab at it myself even though I knew I was out of my depth. Ended up with a half-decent HTML5/responsive/mobile-friendly resume using Bootstrap 2.3 and wanted to share it with the masses. Check out the demo and if you want to build on it, grab the source. Enjoy.

Demo   Source

Chef and iptables

Like many DevOps professionals before me, I needed a way to manage iptables programmatically through Chef. Before I realized that Opscode had written a cookbook for just this, I had already spent some time building my own. The cookbook written by Opscode is very clever and allows you to apply a set of iptables rules with a single line in another recipe. The only problem is that it is predicated on you creating ‘templates’ of iptables policies you want to apply in advance, and you can only apply those templates. You can’t just supply a port number or part of a rule. Additionally, their cookbook wasn’t compatible with Vagrant because of the ruby binary wasn’t in the paths used in the cookbook.

Short version – I wrote my own iptables cookbook and augmented the Opscode iptables cookbook, and I wanted to share.

Changes to the Opscode Cookbook

Basically, the cookbook functionality is unchanged save for two parts. First, in addition to the previous method for invoking iptables, you can now invoke it by setting the ['iptables']['roles']  attribute to one or more roles (comma delimited). There is a new ‘default.rb’ attribute file and the default recipe has been modified slighly to support this. Second, the default recipe has been modified to detect the path to the ruby binary so as to be compatible with Vagrant boxes instead of being hardcoded.

You can check out all of the code on Github.

My iptables Cookbook

My requirements were a little less generic, and so my iptables cookbook is a little more isolated than the Opscode version. Specifically, I didn’t want to affect any existing iptables rules or chains, so my cookbook injects new chains that should be specific for the servers application (hence App-INPUT and App-OUTPUT chains). Unfortunately, today my cookbook only supports ports to be specified via attributes and only works on Enterprise Linux OS’s. Having seen and played with Opscode version, I’ll have to refactor mine to support Debian Linux versions as well as non-attribute driven usage.

To see the full cookbook or to clone, check out the repo on Github. Otherwise the bulk of the logic is in the default recipe, which you can check out here:

 

Would greatly appreciate any feedback/criticism from the Chef community. Thanks for reading.

Bootstrap Scrollspy Workaround

I was recently working on a new HTML project when I came across the Scrollspy feature in Bootstrap’s framework (v2.3). The feature looks really good on Bootstrap’s pages, I figured I’d use it in my project as well. I immediately had issues with the links aligning the content to the viewport and issues with the scrollspy highlighting the right link based on what content was in the viewport. This was all supposed to be out of the box functionality… After doing some research (read: Googling), I came across a few bug tickets and workarounds, but no wholistic solutions to reproducing the functionality on Bootstrap’s site. So I decided to build it manually.

Let’s get started.

Preparation

If you want to jump right into the project, you can download the starter kit (it’s just Boostrap 2.3, a modified Hero Unit example page, and a very slightly modified Bootstrap CSS).

If you want to start from a 100% clean version of Bootstrap 2.3, go download the source and extract it. Keep your top-level folder name whatever you want it to be, but rename the ‘bootstrap’ folder assets (we are matching the existing folder structure in the source code we are going to borrow from one of their examples. Feel free to build your folder structure however you see fit). Create a sibling folder to contain your HTML files and create an index.html inside. Finally, go download jQuery, place it in your assets/js folder, and rename it ‘jquery.js’ (for simplicity). Your folder structure should look like this:

Perfect. Now browse to the Hero example and steal borrow their source code (just right click anywhere, view source, Ctrl+A Ctrl+C) and paste it into your index.html file. We have to make a few minor changes here as well. Scroll to the bottom of the code and replace this:

with this:

For sanity testing, open index.html in your browser – it should look like the original and function without errors.

Now let’s strip out the 3 sub-headings and replace them with a content area and a set of links in the sidebar.

Replace this:

with this:

Open this up in your browser and verify everything is kosher. If so, we’re all done with prep and can move on to the custom JavaScript.

The Offset Logic

At this point, you probably clicked the links and noticed that the viewport doesn’t line up quite perfectly. This is because the height of the top nav bar isn’t being taken into account. Let’s fix that first, then reproduce the scrollspy effect.

To fix this issue, we need to ‘intercept’ the normal link function and replace it with our own. Once intercepted, we’ll scroll to that element with an offset equal to the height of the header.

That’s it. Add this block of javascript in your index.html just after your script source declaration for jQuery and boostrap.js. Test it in your browser, and experiment with changing the offset number and its effects.

The Scrollspy Effect

To create the Scrollspy effect, all we need to do is add the ‘active’ class to the li tags when the viewport is lined up with the corresponding section.

Again, you’ll need to add this code block after the script source declarations for jQuery boostrap.js. That’s it. Now you’ve got a dead-accurate version of the scrollspy, with complete control. Demo and source for the complete package are below.

Demo   Source

Enjoy.

Raspberry Pi Project 1: NAS and XBMC

The Raspberry Pi makes a great HTPC or media PC, whatever you want to call it, because of its low cost, low power consumption, quiet, and small form factor. As I was getting ready to start my Raspberry Pi build, I realized that the Pi could take over a few other functions that my desktop does, including NAS, at a fraction of the cost (see my previous post about Powering a Pi and related utility savings). But could I modify a RaspXBMC build to also run Samba or some other network file sharing? Could XBMC be installed on Raspbian with less than a thousand calls to aptitude? Could XBMC and Samba run simultaneously on a Pi without making video playback unwatchable? That’s what I hoped to find out.

For context, I started with a Raspberry Pi starter kit from Amazon. For storage, I am using a Fantom 2TB external hard drive. After some preliminary research, I decided to start with Raspbian and try to install XBMC on top. For this walk-through, I’ll assume you’ve got your Raspberry Pi powered, connected to your router, and that you have gotten Raspbian installed. If you need help getting started, check out the Raspberry Pi Quick Start Guide.

Part 1 – NAS

Part 1.1 – NTFS-3G

If you don’t plan to use NTFS as your filesystem for your Pi storage, you can skip this step!

If you do want to use NTFS, and you want to be able to read AND write to the drive, you need to install NTFS support:

If you’re starting with a brand new external hard drive, you’ll need to create the partition and filesystem.

Part 1.2 – Automounting with fstab

In Raspbian (and every flavor of Linux I’ve worked with so far), all filesystems that should be mounted at boot are identified in the fstab file (/etc/fstab). The fstab file can be configured a million ways, so I’ll just share my configuration and explain.

The first four lines were created automatically by the Raspbian install, we’ll leave those alone. We’re only interested in the last line that starts with /dev/sda1, that’s the line I’ve manually added to the configuration.

BUT WHAT DOES IT ALL MEAN???  The columns of the fstab file (courtesy of the ArchLinux wiki) are

<file system> - the partition or storage device to be mounted. In my case, “/dev/sda1″
<dir> - the mountpoint where <file system> is mounted to. In my case, “/media/1TB”
<type> - the file system type of the partition or storage device to be mounted. In my case, it is “ntfs-3g”
<options> – mount options for the filesystem. In my case, I chose “defaults” which includes mounting the filesystem as read-write with no umasks for permissions/access
<dump> – not needed in our case, just use 0 (zero)
<pass> -
used by fsck to decide which order filesystems are to be checked. You can set this to 0 (zero)

So my configuration file says to mount /dev/sda1 on /media/1TB as an NTFS filesystem, using default mount options, and never run fsck on this drive.

Now that you have an example, implementing is pretty easy.

  1. Make a backup of your fstab file
    sudo cp /etc/fstab /var/fstab
  2. Open fstab in your favorite text editor
    sudo vim /etc/fstab
  3. Add the lines to the configuration (see example above) to automount your drives
  4. Save and close the fstab file
  5. Test your configuration by executing a mount all command
    mount -a

If your drive correctly mounted to the mount point you specified (/media/1TB) and it is mounted as read-write, you’re golden.

If you are using multiple drives, then simply add additional lines to the fstab to cover all of the drives you want to automount. Now our storage will automatically mount read-write at startup.

Part 1.3 – Samba

In my build, I wanted to share out any drives mounted in /media/ in case I added drives in the future. Additionally, accessibility rather than security was the priority for me. Because of that I set up Samba to allow anonymous access to any device on my LAN. If you’re cool with that approach, follow along. If not, you may have to do some research on how to set up Samba to your liking.

  1. Install samba
    sudo apt-get install samba
  2. Open the samba config file in your favorite text editor
    sudo vim /etc/samba/smb.conf
  3. Find the line that says “security = user” and update the file with the following lines
  4. Scroll to the bottom of the Samba configuration file and add a new section for your new share. See my configuration for example
  5. Test your configuration by executing ‘testparm’ and examining the output
  6. Assuming your test went well, reload samba
  7. On another device, try to mount the share. On Windows, you can just open the start menu and type “\\yourservername” or “\\your.server.IP.address” On a Mac, open Finder, go to the “Go” dropdown menu at the top, and choose connect to server

    Courtesy of Mobilefish.com

    and enter “smb://yourservername” or “smb://your.server.IP.address” If prompted for a user account, choose Guest.

OK, this is already over 1000 words long so let’s take a breather and continue with XBMC in Part 2.

Part 2 – XBMC

Part 2.1 – Installing XBMC

Installing XBMC is usually pretty easy, but since we’re using Raspbian we can’t use the normal packages. Fortunately for me and anyone who is trying to accomplish this, Michael Gorven has already figured this out for us and even hosts the packages we need. Go ahead and open a new window or tab and browse to http://michael.gorven.za.net/raspberrypi/xbmc . The author has already done a great job of documenting this process so I won’t duplicate it here. Once your installation is finished, test that you can start XBMC by executing ‘sudo xbmc-standalone’ and seeing if XBMC appears on your display.

This is perfect, except that XBMC is now tied to our session. Now if you’re directly connected to the Pi with a keyboard, this is irrelevant. If, like me, you’re doing all of your Pi work via SSH, XBMC will die once you terminate your SSH session. Let’s set up XBMC as a service so we can start/stop it gracefully and allow it to run after our SSH session ends. Additionally, if you’re having issues with XBMC not starting at boot, setting up a service can ensure that XBMC is started for the right run levels.

Part 2.2 – Setting up XBMC as a Service

The XBMC Wiki has a good article for how to set up XBMC as a service, but I want to expand on it a little bit.

  1. Create the init script file
  2. Paste the following code into your vim session:

    Save and quit out of vim. There are a few differences between my init script and the one provided on the XBMC wiki. For one, my “runas” user is set to “pi” – you’ll want to set this to whatever user you installed XBMC with to avoid permissions issues. Additionally, my init script will take “status” as an argument to the init script and will return information about whether or not XBMC is running.
  3. Change the script’s permissions to make it executable
  4. Test that the init script is working:
  5. If you want XBMC to start when the OS boots, update the rc.d scripts. Unless you have a specific use case, using the “defaults” argument will work for you.
  6. If you want to be thorough, restart your Raspberry Pi and verify that your disk has been mounted (via fstab from Part 1) and that XBMC has started.
  7. You’re done. Time to enjoy.

abed_cool_cool_cool

Part 2.3 – XBMC Remote

If you’re going to manage your XBMC/NAS/Pi remotely, I would also suggest downloading the XBMC Remote App for your Adroid or iPhone. To enable remote control on XBMC, go to System -> Settings -> Services -> Remote Control and enable both “Allow programs on this system to control XBMC” and “Allow programs on other systems to control XBMC.”

XBMC Settings->Services Screen

Courtesy of xbmc.org

Assuming you’re on the same wireless network, you should be able to connect to the XBMC with your remote app using your Pi’s IP address and the default username and password of ‘xbmc.’

Well at nearly 2000 words, this has been a whopper of a post. Hopefully this write up has helped you one way or another, and let me know if you have any questions. Enjoy your new combination NAS and HTPC.

Powering a Raspberry Pi

I recently started building out a combination NAS and HTPC on a Raspberry Pi and came across some interesting information about powering Raspberry Pi’s. While this isn’t a project post per se, I thought it was interesting enough to share and wanted to send this out as sort of a PSA for the users out there who don’t know the potential danger of “backpowering” a Raspberry Pi.

For those who don’t already have one, here are a few suggestions for where to get a Raspberry Pi.

Where to get a Raspberry Pi

If you have some of the peripherals (SD card, HDMI cable, micro USB power supply), you can get started with a standalone Model B Raspberry Pi for as low as $35.

If you would rather get a starter kit, the prices are pretty reasonable and usually includes an SD card pre-loaded with the Raspberry Pi New Out Of Box Software (NOOBS). Here are two good starter kits.

Power Consumption

As an Arduino die hard, I didn’t think I really needed a Raspberry Pi for anything. I was sold once I realized I could run all of my home web server functions on the 3.5 watt ARM processor instead of 85 watt Intel chip in my desktop. The Raspberry Pi will actually pay for itself in about 4 months.

Utility cost of running home server on full x86 desktop (Intel dual core, ATI Radeon HD GPU, 3 HDDs) [high estimate]

(Power draw x hours per week x weeks per year x cost per kilowatt hour) / (1000 watts per kW x 0.85 efficiency x 12 months a year) = estimated cost per month

(150 watts x 168 hours x 52 weeks x $0.10 per kW hour) / 1000 watts per kW x 0.85 efficiency x 12 months a year) = $12.85 per month

Utility cost of running home server on Raspberry Pi and one external hard drive (5 watts for Raspberry Pi, 15 watts for HDD under load) [high estimate]

(20 watts x 168 hours x 52 weeks x $0.10 per kW hour) / 1000 watts per kW x 0.85 efficiency x 12 months a year) = $1.71 per month

Approximate cost savings: $11.14 per month

Powering the Pi and the Dangers of “Backpowering”

The Pi only has two USB ports, so obviously many folks incorporate a powered USB hub to expand its capabilities. At some point, someone discovered that the powered hubs were actually supplying power to the Pi via the uplink between the hub and the Pi. Now you can power your peripherals and the Pi from one outlet. Cool right?

no

Read More