Recently I had issues connecting to Github because of some firewall restrictions outside my control. The firewall had outbound SSH (port 22) blocked. My co-worker Justin Hammond found a git config option that lets you force all git commands to use
https:// (port 443) instead of
git:// (port 22).
git config --global url."https://".insteadOf git://
Worked like a charm. Thanks Justin. Hope this helps someone else.
NB: Don't use
--global if you don't want this applied to all repositories. Without it only sets for the current repository you're in.
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
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 origin/master (remote branch)
git rev-parse master (local branch)
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.
Will be adding to this post as I learn/remember shortcuts
.- repeat last command in normal mode
@@- repeat last command entered with
#- find all occurances of the word I'm currently on
dfc- delete everything including the letter 'c'
dtc- delete everything up to the letter 'c'
- shift+h - go to top of screen
- shift+m - go to middle of screen
- shift+l - go to bottom of screen
- ctrl+v [h|j|k|l]` - highlight indeividual items (great for highlighting column(s)
gUiw- capitalize the current word
gUU- capitalize current line
vU- capitalize current character
guiw- lowercase the current word
guu- lowercase the current line
vu- lowercase current character
keybindings I use all the time via mappgings in my .vimrc
,v- create vertical split
,h- create horizontal split
- ctrl+j - go to split below/down
- ctrl+h - go to split on left
- ctrl+k - go to split above/up
- ctrl+l - go to split on right
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
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/' done
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.
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:
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) ... end
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 => false User.update_all ["deleted = ?", false] end end
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) > 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
WHERE clause. That is what the default_scope adds automatically. Duh!! So in order to bypass the default_scope I had to use
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.
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.
In HTML or ERB:
Other HAML Doctypes
The above is the format for HTML 5. I don’t bother with the HTML 4.01 DOCTYPEs