Weechat keyboard shortcuts

I've switched from using irssi to Weechat since I rejoined the ranks as a Racker.

Here is my current weechat.conf file

Some of the ones I use often:

  • ctrl+h - window left
  • ctrl+j - window down
  • ctrl+k - window up
  • ctrl+l - window right
  • ctrl+z - window zoom (make current small window full screen)
  • ctrl+n - next buffer
  • ctrl+p - previous buffer
  • ctrl+y - clipboard paste
  • ctrl+r - search
  • ctrl+[j|m] - stop search

normal commands not included with my weechat.conf that I use:

  • /window resize - resizes window to that percentage
  • /buffer clear - clears the buffer, i use this often with the highlight monitor plugin
  • /buffer merge - merges two buffers into one (use ctrl+x to switch between them)
  • /buffer unmerge - unmerge the buffer you're currently on out to its own

Where I Go To Choose An Open Source License

I go to choosealicense.com to refresh my memory on open source licenses. MIT is usually my favorite.

A good resource, in my opinion

How to Get The SHA of The Last Commit on a Branch With Git

    Tags : 

I've been asked this a few times and have had to do it lately a few times.

To get the SHA of the last commit from a specific branch, use git rev-parse

git rev-parse origin/master (remote branch)


git rev-parse master (local branch)

How to Run a Single Test With Tox

I have to run a single python test once in a while and keep forgetting how to do it with Tox.

Here it is:

tox -e py27 -- project_name_here/tests/folder_name1_here/folder_name2_here/test_file_name_here.py:TestClassName.test_method_name

Hope this helps someone else.

Happy bit twiddling.

Personal VIM Cheatsheet

Will be adding to this post as I learn/remember shortcuts

. - repeat last command in normal mode

@: then @@ - repeat last command entered with : source

# - find all occurances of the word I'm currently on

ctrl+v [h|j|k|l] - highlight indeividual items (great for highlighting column(s)

Using sed and regex to Remove Prefix on Filenames

I used wp2md recently to generate markdown files out of my wordpress posts so that I could migrate to a static blog generator (like Nikola, the one I chose to use on this blog). However, this exported the files with a prefixing datetime stamp (e.g., 20140224-blog-title.md)

I have used sed many times from my command line toolbox to rename files or content inside of files. Here is how I removed the prefixing datetime stamp from my filenames.

for f in *.md; do echo $f | sed -r 's/.*(\d*)-(.*\.md)/\2/'; done
  • the for loop iterates over just my mardown files (files with the md extension)
  • I echo out the filename into the sed command line tool via a pipe, you can send the results of one command to the input of another by piping them together (e.e., command1 | command2)
  • Then I setup the regex s/old_string/new_string/
    • I've learned when using group matching (the sections in the parenthses) and trying to replace the old_string with an entirely new string, you need to start the old_string with .*. This causes the entire line to be replaced with the contents of the new string
    • old_string regex
      • (\d*) - first group match - any digit, 1 or more times
      • "-" - a hyphen separating the match groups
      • (.*.md) - second group match - anything, ending in .md
    • new_string regex
      • \2 - replace the entire old string with the contents of the second group match


20140224-test-driven-development.md becomes test-driven-development.md

NB: the ; do and ; done are just bash scripting loop notation when put onto one line. This script could have also been written as

for f in *.md; do
    echo $f | sed -r 's/.*(\d*)-(.*\.md)/\2/'

I am aware that Nikola has a wordpress importer, but it imports the files to .wp and .meta. I wanted markdown files (*.md)

NB: I also use Rubular.com all the time to test out my regex expressions. You should check it out.

Consolidated My Blogs

I finally consolidate my blogs that were located at:

and unified them here. I also decided to move to Nikola since I'm coding in Python full-time now and it is a nice Python Static Site Generator. New posts and theme changes coming soon.

Using Deafult Scope and Unscoped in Rails

I recently had the need to add a deleted flag to a model in a Rails project. I am usually of the mindset “explicit over implicit” so whenever I needed to use a finder to get content for that model I would do something like:

User.where(deleted: false)

That does lean towards not having DRY (don’t repeat yourself) code. It’s a balancing act. I decided to give default_scope a chance this time. I quickly experienced the downside of that choice. I added the default_scope to my model:

class User < ActiveRecord::Base
  default_scope where(deleted: false)

Well, I needed to write a migration to add the column and then update any existing records to have a default value of false. I generated my migration and added the following:

class AddDeletedFlagToUsers < ActiveRecord::Migration
  def change
    add_column :users, :deleted, :boolean, :default =&gt; false
    User.update_all ["deleted = ?", false]

However, when I looked at the database, none of the pre-existing records had false as their deleted flag. I went to the rails console and typed in the update_all command again:

User.update_all ["deleted = ?", false]

and that’s when I saw how default_scope can bite you in the butt:

~/code/project(master) &gt; rails c
Loading development environment (Rails 3.2.12)
>> User.update_all ["deleted = ?", false]
  SQL (35.9ms)  UPDATE "users" SET deleted = 'f' WHERE "users"."deleted" = 'f'
=> 0

Notice the WHERE clause. That is what the default_scope adds automatically. Duh!! So in order to bypass the default_scope I had to use unscoped:

User.unscoped.update_all ["deleted = ?", false]

in my migration. That then caused all existing records to be updated.

Yes, I’m aware this violates “Explicit over implicit” but it does keep my code “DRY (do not repeat yourself)”. There are pros and cons to all tools. Use them wisely.

Fix Rendering With Presence of Doctype

A couple times now I’ve forgotten to render the DOCTYPE in my layouts on my web apps. The DOCTYPE element tells the browser what type of file to expect. It needs to be the first line in your document, so it usually goes in your application layout file.


<!DOCTYPE html>


!!! 5

Other HAML Doctypes

The above is the format for HTML 5. I don’t bother with the HTML 4.01 DOCTYPEs

Run a Specific RSpec Spec

Tired of looking this up and want to use my writing part of my brain to blog it:

rake spec SPEC=spec/controllers/sessions_controller_spec.rb \
  SPEC_OPTS="-e \"should log in with cookie\""

This is importatnt to me while coding Rails because if I just run

rspec specs/controllers/sessions_controller_spec.rb

the test database isn’t cleared out. By running rake spec I get that.