Skip to content

Instantly share code, notes, and snippets.

@jbgo
jbgo / bulk_probind_dns_updates.md
Created April 5, 2013 20:39
Bulk DNS record updates with ProBIND (via a few MySQL queries)

Do you have a pre-existing ProBIND installation with thousands of zones and you would like to change the IP address for hundreds of A records?

Here is one way you could do it without spending hours clicking through the GUI. Ok, so I'm circumventing probind for the most part and going straight to MySQL, since probind is basically a CRUD app around a few tables in a databse.

1. Given a list of domains, preview the records you want to update.

@jbgo
jbgo / free-space-on-boot-disk.md
Last active April 19, 2023 20:47
Free up space on /boot disk (ubuntu)

Free disk space when /boot is full (Ubuntu)

TL;DR

dpkg -l linux-image*
uname -r
sudo apt-get remove linux-image-2.6.32-{21,37,38,39,40,41,42,43,44}-server
sudo apt-get autoremove
@jbgo
jbgo / wtf_notepad.md
Last active March 10, 2023 12:53
Safely remove byte order marks (BOM) and carriage returns (^M) from files edited with Notepad on windows

TLDR: File.read(a_file).sub("\xEF\xBB\xBF", "").gsub("\r", "")

I tried using combinations of find/awk/sed, but I ended up corrupting my project files including the git index because I don't understand those commands very well. So instead, I turned to my good old friend ruby. This also has the advantage that I can use it in my program that processes these files. They've been ninja-edited (modfied outside of source control) in the past, which makes it likely that someone will come by and ninja edit them again in the future. But instead of convincing people that it's bad to edit files in notepad or outside of source control, we can just silently fix it on the fly and smile and say "Happy Friday!"

Here is the example of what I'm cleaning up. Thankfully, git's diff viewer is brutally honest and shows these characters. Unfortunately, most editors (including the good ones) simply hide these characters and put them back in when you save the file. The byte order marks were causing browsers to skip CSS declarations

@jbgo
jbgo / debug_system_stack_error.md
Created January 9, 2013 15:08
debug SystemStackError in ruby 1.9

This is how I debug SystemStackError when there is no stack trace.

My first attempt was:

begin
  a_method_that_causes_infinite_recursion_in_a_not_obvious_way
rescue SystemStackError
  puts caller
end
@jbgo
jbgo / fix-vim-error576.md
Created November 28, 2012 15:03
Fixing VIM error "E576: viminfo: Missing '>' in line: ..."

I was getting the error E576: viminfo: Missing '>' in line: [file names] about ten times with various file names whenever I opened or saved a buffer in Vim. This happened both in normal vim and with MacVim. This was followed by the line E136: viminfo: Too many errors, skipping rest of file. Other than these obnoxious messages, Vim itself worked fine.

To fix it, I opened ~/.viminfo and deleted everything in the section labeled # History of marks within files (newest to oldest):. I lost all my history of marks within files, but that was acceptable for me since I was starting a new coding session for the day.

So far, I'm not sure how my viminfo got into this state.

@jbgo
jbgo / etc-init-redis.conf
Created November 27, 2012 17:14
Install latest redis from source (Ubuntu)
description "redis server"
start on runlevel [2345]
stop on runlevel [016]
exec sudo -u redis /opt/redis/redis-server /opt/redis/redis.conf
respawn
@jbgo
jbgo / packet_loss.md
Created August 29, 2012 13:46
Simulating packet loss

Why?

Users were complaining about a feature that would sometimes fail for no apparent reason. After some time investigating the issue, I suspected an unreliable internet connection might be responsible for these failures. In order to test my theory, I wanted to simulate random packet loss on my development machine to see if I then experienced the same failures.

How?

We can use a program called ipfw to simulate packet loss. From the manual, ipfw is an "IP firewall and traffic shaper control program."

It wasn't immediately obvious how to use this program at first, so here is a summary of what I did. Also, the man page tells me it's deprecated, but worked for me today.

@jbgo
jbgo / postgresql_cheatsheet.md
Created August 24, 2012 15:22
PostgreSQL Cheatsheet

This is still a work in progress. I'm just adding things as I come across them.

Common command line tasks

Create database: createdb db_name

Drop database: dropdb db_name

@jbgo
jbgo / render-markdown.md
Created June 19, 2012 15:28
Render markdown READMEs on the fly

This is my new favorite thing to do when I want to read a README file written in markdown. This assumes you are macosx and have the redcarpet gem installed.

alias readme='redcarpet README.md > readme.html; open readme.html'
readme
@jbgo
jbgo / skip_callbacks.rb
Created June 14, 2012 18:40
Update attributes without callbacks
class SomeModel < ActiveRecord::Base
before_save :some_callback
after_save :some_other_callback
# stuff...
def update_attributes_without_callbacks(attributes={})
self.class.where(id: id).update_all(attributes)
end