SQL Fast Column Add

I found a fast way to add a new column to a table.

MySQL

  1. Create the new table like the old table (foo), but with the new column you want in it. Make the new table with a different name (foo_new):

  2. Add the records from the old table into the new table:

     INSERT INTO foo_new (col1, col2, col3)
          SELECT col1, col2, col3 FROM foo
    
  3. If you have a lot of records, you can disable index updates during insert:

2013-05-23    
Duplicate an SD Card in OS X

I made these notes as a result of my experimentation with a Raspberry Pi. I kept messing up the software on the SD card and needed to start over, but it took a long time to go through all of the RPi setup steps. By copying the partitions, I was able to restore relatively quickly.

Get the info of each partition you want to copy on your SD card using diskutil:

2013-04-28    
Permutation Generator

This little program uses currying to create a nested function reference that prints out a table with all possible permutations of the @states array in as many columns as you like.

#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';

## Scott Wiersdorf
## Created: Sat Aug 18 14:29:03 MDT 2012

## permutation/truth table generator

my $inputs = shift @ARGV || 3;  ## table columns
my @states = ('T', 'F', '-');   ## possible states

my $func = sub { say join "\t" => @_ };
for (1..$inputs) {
    $func = loop_maker($func);
}
$func->();

exit;

sub loop_maker {
    my $inner = shift;

    return sub {
        for my $state ( @states ) {
            $inner->(@_, $state);
        }
    };
}

The output with an argument of ‘2’ looks like:

2012-08-24    
Miscellaneous System Administration Notes

Some miscellaneous notes I may split out into separate posts later… don’t bookmark this one.

View open network connections on OS X

sudo lsof -lnP +M -i4

The options:

-l      don't convert uids to login
-n      dont' convert network numbers to to hostnames
-P      don't convert port numbers to service names
+M      enable portmapping
-i4     look for IPv4 connections

See also nettop. 3rd party apps include Little Snitch and RubberNet.

2012-08-15    
Perl SSL Debugging

I just spent about 3 hours trying to figure out why a Mojolicious daemon wasn’t permitting SSL connections. Here’s what I checked:

  • the server was accessible (iptables, routing, etc.)
  • the port was accessible (I could set mojo’s listen to http://*:443) and it would respond fine on my laptop
  • the entire /usr/local hierarchy, /etc and /home/scott were identical to my development environment (save the machine specific differences) and had the same permissions and ownership.

So basically at this point I narrowed it down to SSL. Something in the SSL setup wasn’t correct.

2012-07-06    
LaTeX Notes

Here are a few notes I’ve made when using LaTeX:

Hyphens

For two literal hyphens, separate them with {}, for example:

The \texttt{-{}-delete} flag should be set.

Underscores

Underscores are special; escape them if you want to use them literally:

Check the \texttt{authorized\_keys} file.
2012-06-27    
Perl Hash Reference Slices

Working with Perl’s references can sometimes be confusing. This document illustrates several ways to efficiently take a slice of a hash reference.

Here is a hash reference and an array of keys called @order:

my $row = { foo => 'bar',
            baz => 'blech',
            one => 'uno',
            tres => 'three',
            cuatro => 'four or so' };
my @order = qw(one tres cuatro baz foo);

Here is one way to get a list of values in the order of @order:

2012-05-08    
git notes

Some notes about git. As with all my technical posts, some or all of this may be out of date. Consider it, then, courage to believe that there may be a solution to your problem in terms you can understand.

I have a local repository I want to make into a remote repository

Here’s our local repository:

local $ git init .
local $ git add .
local $ git commit . -m "- initial commit"

Nice. Now make an empty repo on the remote server:

2012-03-28    
yum notes

Some notes I kept when I was learning how to use yum.

Installing a package that has been excluded

The file /etc/yum.conf may contain an ’excludes’ line that will disallow updates of any of packages listed. To bypass this, you can comment out those packages in /etc/yum.conf, or you can one-off it like this:

yum --disableexcludes all install gcc

Finding which repo has the file you need

yum provides '*apxs*'

You may need to add ‘–disableexcludes all’ too.

2012-03-13    
iptables notes

Here are some notes I keep for myself when I play with iptables (I don’t use it often enough to remember how it works):

List all rules

# iptables -L

See the rules and their numbers

# service iptables status

Delete a rule

# iptables -D CHAIN NUM

E.g.:

# iptables -D INPUT 12

Add a new rule at the bottom of the chain

# iptables -A INPUT -i eth0 -p tcp --dport 8888 -j ACCEPT

Insert a new rule in a particular place

This inserts a rule in position 6; the rule that was formerly in 6th position will be bumped down (and all rules below it):

2012-03-09