Mac OSX save file dialog expansion

mac osx

On Mac OSX, to change the Save As dialog to ensure that it always expanded, you can run a command from Terminal that will permanently change the setting. I prefer to have a Windows style Save dialog that gives me a list of all of the files and folders, as opposed to the default in Mac OSX that shows just the last/default directory.

defaults write -g NSNavPanelExpandedStateForSaveMode -bool TRUE

screen

linux, screen

I noticed that sometimes even if I would scp files from server to server, the connection would eventually timeout as soon as I logged out of the machine.

One solution is to use the excellent application ‘screen’. This allows you to multiplex more than one virtual console, keeping the terminal alive even if you are disconnected on your connection.

To create a screen, simply run:

screen -R "some_terminal_name"

When you want to return to the original window, you can hold CTRL+A+D. That takes you back to your original terminal. IF you want to return to the screen again, use the same command as mentioned above.

Using perl to remove duplicates from an array

perl

I needed to remove duplicate elements from an array in Perl. The internet has a range of different ways to do this, but I found the best and quickest way to do so was to use a temporary hash.

push @data, $some_fancy_variable;
my %temp_hash = map { $_, 0 } @data;
@unique = keys %temp_hash;

Leaving the new @unique array with the duplicates removed.

 

Fun with exim

exim, linux

exim is a mail transfer agent for Unix environments. exim follows the sendmail design model, and is highly configurable with many features.

Some of my favourite commands are:

exim -bp | exiqsumm
- Generates a summary about all of the messages currently in the queue, including total and time spent in the queue
exiwhat
- Shows what exim is currently doing
exim -Mrm <message-id>
- Remove a message from the queue
exiqgrep -z -i | xargs exim -Mrm
- Delete all frozen messages from the queue

SCP over a proxy/tunnel to a target machine, from your local machine

bash, ssh

For a work project, I was required to take copies of files from one machine at one data center, and copy those files [via scp] through a tunnel and a bastion server at another data center, and then onto a variety of different machines there.

This proved to be a little trickier than I thought, but ~/.ssh/config can be easily setup to ensure that you can access remote machines via proxies very quickly and easily.

If you do not have a ~/.ssh/config file, it is OK to create it. Just ensure that, if you receive “bad owner or permissions” for your ~/.ssh/config file, you adjust them to fix:

chmod 600 ~/.ssh/config

After that, you need to then start adjusting the config file. From my local machine, I setup the following rules:

Host target_host
 User my_username
 HostName target_host
 ProxyCommand ssh my_username@proxy_machine nc %h %p 2> /dev/null

Using these rules, I was able to ssh into the machine by using just ssh target_host from my local.

On the proxy machine and target hosts, you can also easily add some ssh keys so that you can copy files without the need for a password.