Philip Hutchins

Head in the cloud...

Configuring a Static IP Block From ATT

So you’ve ordered a block of static IP’s from AT&T for use at home. You’re tired of forwarding a million custom external ports to non matching internal ports. You want to use them to point to various hosts, virtual machines, and devices behind AT&T’s modem/router combo or your router which is behind their modem/ruoter.

Obtain your IP block information

The first step to getting this all set up is knowing the correct information about the static IP block that you have been assigned. These are assigned in blocks of 8, 16, 32, etc… One thing to note is that 3 of the IP’s out of your block will not be usable by you. Those 3 represent the network, gateway, and broadcast addresses.

Killing a Hung SSH Session

How to kill an unresponsive SSH session

If you’re like me, I’m sure you’ve been in a situation where your SSH session is hung and you simply need to kill it so you can reconnect or get on with your business. I generally either just close the pane or window and reopen it or find the process from a different window and kill it from there. I got tired of this today and decided to find out how to kill it the right way.

Sure enough there is a very simply and easy way to kill a hung session!

~.

I hope this helps save some time in your day… I know it will for me!

My Tmux Config

My tmux Config

Feel free to use as you like…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# use vi mode
setw -g mode-keys vi

# remap prefix to Control + a
#set -g prefix C-a
#unbind C-b
#bind C-a send-prefix

# force a reload of the config file
#unbind r
#bind r source-file ~/.tmux.conf

# quick pane cycling with Ctrl-a
#unbind ^A
#bind ^A select-pane -t :.+

# move around panes like in vim (only in tmux 1.6)
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind h select-pane -L

# Sane scrolling
set -g mode-mouse on

# color options
#set-window-option -g utf8 on
#set -g default-terminal screen-256color

# colors
setw -g mode-bg black
set-option -g default-terminal "screen-256color" #"xterm-256color" # "screen-256color"
set-option -g pane-active-border-fg blue

# Titles (window number, program name, active (or not)
set-option -g set-titles on
set-option -g set-titles-string '#H:#S.#I.#P #W #T'
#set -g status-bg colour240

# disable mouse control by default - change 'off' to 'on' to enable by default.
setw -g mode-mouse on
set-option -g mouse-resize-pane off
set-option -g mouse-select-pane off
set-option -g mouse-select-window off
# toggle mouse mode to allow mouse copy/paste
# set mouse on with prefix m
bind m \
    set -g mode-mouse on \;\
    set -g mouse-resize-pane on \;\
    set -g mouse-select-pane on \;\
    set -g mouse-select-window on \;\
    display 'Mouse: ON'
# set mouse off with prefix M
bind M \
    set -g mode-mouse off \;\
    set -g mouse-resize-pane off \;\
    set -g mouse-select-pane off \;\
    set -g mouse-select-window off \;\
    display 'Mouse: OFF'
# zoom this pane to full screen
bind + \
    new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
    swap-pane -s tmux-zoom.0 \;\
    select-window -t tmux-zoom
# restore this pane
bind - \
    last-window \;\
    swap-pane -s tmux-zoom.0 \;\
    kill-window -t tmux-zoom


#### COLOUR (Solarized 256)

# default statusbar colors
set-option -g status-bg colour235 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default

# default window title colors
set-window-option -g window-status-fg colour244 #base0
set-window-option -g window-status-bg default
#set-window-option -g window-status-attr dim

# active window title colors
set-window-option -g window-status-current-fg colour166 #orange
set-window-option -g window-status-current-bg default
#set-window-option -g window-status-current-attr bright

# pane border
set-option -g pane-border-fg colour235 #base02
set-option -g pane-active-border-fg colour240 #base01

# message text
set-option -g message-bg colour235 #base02
set-option -g message-fg colour166 #orange

# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange

# clock
set-window-option -g clock-mode-colour colour64 #green

bind-key J command-prompt -p "join pane from:"  "join-pane -s '%%'"
bind-key S command-prompt -p "send pane to:"  "join-pane -t '%%'"

Reverse Scrolling in Windows 7

There is no straight forward way built into Windows 7 to reverse the scrolling direction for your mouse. If you’re like me, you primarily use a Mac with OSX. Once you get used to the natural scrolling, its kind of nice. I got tired of trying to wrap my brain around switching back and forth between different scrolling directions when at work or home and decided to find a way to switch my Windows 7 machine to match my Mac.

There are two real ways to do this…

Option One

This is the way I chose. I chose this becuase finding the registry key for my house was not straight forward. The logitech driver overrides the hardware tab in the windows control panel which you would use to find the key.

  • Open power Windows Power Shell by browsing to Start Menu > All Applications > Accessories > Windows PowerShell

  • Wait until you see a prompt that looks something like this…

1
PS C:\Users\flip>
  • Then enter…
1
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 }
  • All done. You may need to unplug your mouse and plug it back in or reboot to see your changes.

Option Two

This is the manual way of doing things. You will change a flag in the Windows registry to get the desired effect.

  • Open the “Mouse Properties” dialog in your control panel and click on the “Hardware” tab.
  • Open the device properties window by clicking on the “Properties” button in the bottom right corner just above the “Apply” and “Help” buttons.
  • In the device properties dialogue window, click on the “Details” tab and select “Hardwire Ids” from the “Property” drop-down list. You should see a list of entries starting with “HID…”. Write down the values that start with “HID\VID_???…”.
  • Close device properties by clicking “Cancel”.
  • Close “Mouse Properties” by clicking “Cancel”.
  • Find and open the application “regedt32.exe” as an administrator, if you are not already logged in as one.
  • Navigate to “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID”, and look for an entry that resembles the “VID_???…” number that you wrote down earlier in step 3.
  • Open each child entry under your specified “VID_???…” key, and open the “Device Parameters” key. In my case, there were two child entries with a long “serial number”-like alphanumeric text string.
  • There should be a key named “FlipFlopWheel” under each of the “Device Parameters” key. Reverse the entry value for the “FlipFlopWheel”. i.e. if default is “0” (zero) change it to “1”, and vice-versa.
  • Do the same step 9, for each alphanumeric text string key entry, and their “Device Parameters”, “FlipFlopWheel”.
  • Close “regedt32.exe”.
  • Unplug your USB mouse, and listen or watch for Windows 7’s acknowledgement and confirmation that it has recognized the event of the mouse being unplugged. In my case, it was simply a “USB device unplugged” system sound. Re-connect the mouse and the new settings should have taken effect. If not, simply shutdown and restart Windows 7.

Enjoy life a little bit more now…

Finding UTF-8

Issues due to differences in file encoding can sometimes be elusive and frustrating. I’ve found a few little tricks to uncover where the issue exists and to fix the problem.

If you have an idea of which file the characters are, you can use cat to display all characters and adds a $ to the end of your lines so that you can confirm that there are no special characters hiding in each line.

1
cat -vet filename

The options…

1
2
3
4
5
-e                       equivalent to -vE
-E, --show-ends          display $ at end of each line
-t                       equivalent to -vT
-T, --show-tabs          display TAB characters as ^I
-v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB

Determine what character encoding is used by a file like so…

1
file -bi [filename]

Use VIM to change a file’s encoding

1
2
set encoding=utf-8
set fileencoding=utf-8

You will only notice a difference if you add utf-8 characters. Most characters on the keyboard will create a unicode equivalent if you hold down the alt key.

Change a files encoding via athe command line

1
iconv -f ascii -t utf8 [filename] > [newfilename]

OR

1
recode UTF-8 [filename]

Installing Octopress

After intalling my new Octopress blog I figured it might be appropriate to write a blog about installing Octopress! The process was fairly easy but I found that going into it I’d made a few assumptions that were a little bit misleading. After getting over a couple of mental speed bumps, tiny ones really, I’m up and running with a brand new blog!

Assumptions

  • Octopress is a package of software that I will unpack into a directory on my web server and I will browse to it to administrate the setup and create posts

This was completely wrong. Come to find, its a good bit neater than this. You unpack or checkout the source onto a *nix or osx machine, fill out a simple config file, then use rake to build and then publish your site locally or remotely. After it has been published, it is a static site.

  • I will need to set up a database to hook Octopress into

After messing with Wordpress and Drupal for many years, I pretty much assume that every blog suite will need a DB. This is not the case. Since Octopress builds your blog at your command, you publish static content so there is no need for a DB or even logging into an interface via the web. You do all of your blogging hackerstyle from the command line!

Installation

Steps…

  1. Install and Ruby
  2. Install Octopress (really just checking out a git repo)
  3. Configure Octopress
  4. Configure your Web Server

Install Ruby

This step will differ greatly depending on what opreating system you’re installing this on. Generally you might want to install RVM to manage your ruby versions and then install ruby using RVM. I am serving this off of a server running CentOS so it was a little different for me…

Here was my process

Remove old ruby

1
$ yum remove ruby

Install dependencies

1
2
3
4
5
6
7
8
9
$ yum groupinstall "Development Tools"
$ yum install zlib zlib-devel
$ yum install openssl-devel
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ tar xzvf yaml-0.1.4.tar.gz
$ cd yaml-0.1.4
$ ./configure
$ make
$ make install

Install ruby

1
2
3
4
5
6
$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
$ tar zxf ruby-1.9.3-p194.tar.gz
$ cd ruby-1.9.3-p194
$ ./configure
$ make
$ make install

Update rubygems

1
2
$ gem update --system
$ gem install bundler

Test ruby and rubygems are working

1
2
3
#Close shell and reopen for changes to take effect
$ruby -v
$gem --version

Rails

1
2
3
$ yum install sqlite-devel
$ gem install rails
$ gem install sqlite3

Install Octopress

If you installed RVM, it may ask you to trust the .rvmc file, you can savely say “yes” to this

1
2
3
4
5
6
$ cd
$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress
$ gem install bundler
$ bundle install
$ rake install

Configure Octopress

You need to edit a few configuration options for Octopress.
_config.yml

Edit this file and configure the first few lines to your liking. You can see below how I configured mine. There are more configuration options near the bottom of the file that you can explore.

1
2
3
4
5
6
url: http://phutchins.com
title: Philip Hutchins
subtitle: Head in the cloud...
author: Philip Hutchins
simple_search: http://google.com/search
description:
Rakefile

Edit this file to configure the way your blog deploys

1
2
3
4
5
6
7
8
## -- Rsync Deploy config -- ##
# Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
ssh_user       = "phutchins@phutchins.com"
ssh_port       = "22"
document_root  = "/var/www/vhosts/phutchins.com/httpdocs/"
rsync_delete   = false
rsync_args     = ""  # Any extra arguments to pass to rsync
deploy_default = "rsync"

Configure your Web Server

If you havent set up a site for this yet, you’ll need to copy the default site and give it a name for your new site

1
2
$ cd /etc/apache2/sites-available
$ sudo cp default mysite

Open your new configuration file with vim or your favorite text editor

1
$ sudo vim mysite

Lines that need to be changed are labeled with comments above. /var/www is the default directory so you will need to change that to the directory where you want to host your Octopress public folder out of. You can either point directly to the public folder or use the rake deploy function of Octopress to push your site to the web sites /var/www dir. I recommend the second option.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<VirtualHost *:80>
  ServerAdmin webmaster@localhost

  <!-- point the line below to Octopress's public folder -->
  DocumentRoot /path/to/octopress/public/folder
  <Directory />
      Options FollowSymLinks
      AllowOverride None
  </Directory>

  <!-- point the line below to Octopress's public folder -->
  <Directory /path/to/octopress/public/folder >
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all
  </Directory>

  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Lastly, you’ll need to restart apache

1
$ sudo service apache2 reload

All done! Now you should be able to browse to the URL or IP of your Apache server and view your site. At this point it will be pretty empty and bare so lets move on to making your first blog post.

Your first post

As Octopress is based on Jekyll, it offers rake tasks to create posts and pages that have some basic metadata included in them. It also wil generate global categories for you ass you add them to your posts and pages.

Adding a Blog Post

To create a post you use rake. Just replace “My Blog Title” with your title.

1
rake new_post["My Blog Title"]

This creates a file for your post in the source/_posts directory named with the date that you created it and a munged version of the title you used. By default, these are created as a Markdown files. Navigate to your newly created file and you will see something like this…

1
2
3
4
5
6
7
---
layout: post
title: "My Blog Title"
date: 2013-09-14 00:21
comments: true
categories: [Blog, Awesome]
---

Creating the post

Once you have the post file created, you can begin to add your content below the last set of three dashes. You work with simple text but why stop there when you have Markdown??

Working with Markup

Markdown lets you do a lot so I’ll only cover a few simple things here.

Headers

You can create headers in a few ways.

The above header is created like this. You can add are remove #’s to change the size. A single # represents a H1 while three #’s represents an H3 and so on.

1
##### Headers

Underlining text with equals or dashes creates H1’s and H2’s respectively.

1
2
3
4
5
This is an H1
=============

This is an H2
-------------

It does not matter how many equals or dashes you use. Any number will work

Code Blocks

For a code block, you can indent lines with a tab or 4 spaces. You can also use “` before and after your code. To specify the type of highlighting use something like this…

``` bash
ls -altr
```
Links

To create a link, use the following syntax.

1
[Link Text](http://my.page.com)

For more information check out the Markdown Documentation Page.

Deploy your new post into production

To generate your blog, simply run rake generate. This will create the blog and all files required for it in the public folder.

Then to publish to the location you configured in Rakefile, run rake deploy. This will push your public folder to the configed location.

Managing your Content

There are a few ways that you can manage your blog. I’m current using a git repo to store the entire Octopress codebase. This allows you to not only edit and make updates from many locations but it also gives you the ability to use git as a way to publish.

Overall thoughts…

Octopress is pretty easy to use and great for someone that doesn’t mind a little hacking. Even better for someone that likes a little hacking. :) If you’re like me, you hate when gui editors change something that you’ve typed or created becuase it thinks it knows better than you do.