2009-03-26

Objective C W.I.P

The @ symbol (or at symbol)

anything preceeded with an @ is a compiler directive. keywords have specific meanings too numerous to list.

@"a string"
an immutable/constant string.

@32
an immutable/constant int.

Labels:

2009-03-21

Basic Non-destructive Backup with rsync (good for music & photos)

#!/bin/bash

EMAIL="me@myemailhost.com"
HOSTNAME="fileserver"
LOCAL_PATH="/mnt/data/photos/"
REMOTE_PATH="/Users/lucas/Pictures/iPhoto\ Library"
REMOTE_HOST="hackintosh"
WHAT="photos"

#if we've said to delete files that are missing in the remote copy, do so and exit
if [ $# -eq 1 ]; then
  if [ $1 == delete ];then
    rsync -ai --delete "$REMOTE_HOST":"$REMOTE_PATH" "$LOCAL_PATH"
    exit
  fi
fi

#otherwise backup changes
rsync -ai "$REMOTE_HOME":"$REMOTE_PATH" "$LOCAL_PATH" |mail -e -s "$HOSTNAME: $WHAT backed-up" $EMAIL

#and make a list of files that have been deleted in the remote copy
rsync -ain --delete "$REMOTE_HOME":"$REMOTE_PATH" "$LOCAL_PATH" |mail -e -s "$HOSTNAME: $WHAT to delete" $EMAIL



i have cron on my fileserver set to run this script every night (and another very similar one for my music). I just go about my business on my desktop using iphoto and itunes as normal and everything is replicated on my fileserver within 24 hours with email notification of what is copied or should be deleted from the backups. If I accidentally delete something from either library on my desktop, the files will still be sitting on my fileserver unharmed until I manually run the script with the "delete" argument.

Labels: , ,

find and execute

find -name "*.rar" -exec unrar e {} \;
recursively searches for rar files, extracts the contents of each. matching filenames are substitutes in for the {} and executed, one at a time. this can be slower than piping the results of find to xargs, but doesnt fail when the executed command can only work on one file at a time.

Labels: ,

.bash_profile

export EDITIOR=vim
sets vim to be the default editor. it's probably not kosher to leave off the path, but it varies a lot between systems, so i just trust it's going to be available within $PATH

complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
I'll happily admit this is voodoo to me, I could probably dissect how it works but i dont really care. takes hosts found in ~/.ssh/known_hosts and autocompletes them like filenames


alias ls='ls -FG'
alias ll='ls -FGl'
alias la='ls -aFGl'

colourful ls' with symbols to denote executable files and directories


alias h='history'
alias hg='history|grep'

less keystrokes for history and search of history means I use it more often

alias cp='cp -v'
I like to know the progress of long copy operations

alias df='df -H'
alias du='du -H'

who cares about bytes when you're dealing with hundreds of gigabytes. human readable please!

alias rm='rm -i'
saves me from brainfarts. overridden by rm -f

alias curl-easy="curl -C - -O "
an alias to make curl work more like fetch or wget. resumes automatically, saves the downloaded data named the same as it is on the server

Labels: ,

.inputrc

ok, this one is super short

set completion-ignore-case On
makes bash tab completion ignore case for file and directory names

Labels: ,

VIM

commands

:%s/find/replace/g
finds and replaces all instances in file

:%s/find/replace/gi
finds and replaces all instances in file (ignore case)

:%s/find/replace/gc
finds and replaces all instances in file (confirm each replacement)

:%g/search/s/find/replace
searches the whole file for lines with "search" in them, then runs a substitution s/find/replace on only those lines

:s/\(\d\d\)-\(\d\d\)-\(\d\d\d\d\)/\3-\1-\2
finds a date presumed to be in the broken US format (MM-dd-yyyy) and rearranges it into iso format (yyyy-MM-dd.
the key points in this are the \( and \) surround a part of the searched text we want to reuse in out substitution, and \1, \2, etc refer back to these parts of the text

:let i=10 | 'a,'bg/abc/s/def/\=i/ |let i=i+1
for the range between 'a and 'b, for lines with the string "abc" on them, replace the first occurance of "def" with an incrementing number starting from 10. I commonly have "abc" and "def" set to the same thing (for some reason it doesnt increment if you leave out the "g/abc/" part).



shortcuts

C^p
autocomplete words

z=
show spelling suggestions

zg
add to dictionary



split panes

C^w, n
new pane

:sp filename.txt
open filename.txt in a new pane

:vsp filename.txt
open filename.txt in a new vertical pane

C^w, w
cycle through panes

C^w, down arrow
select pane below

C^w, up arrow
select pane above

C^w, =
all panes equal height

C^w, +
increase selected pane height by 1

C^w, -
decrease selected pane height by 1



VIM RegEx stuff

^
start of line

$
end of line

C^v + C^m
the ^M character that windows users leave on the end of lines



.vimrc
:map <F5> :setlocal spell! spelllang=en_au
:imap <F5> <ESC>:setlocal spell! spelllang=en_au

Use F5 to toggle en_au spelling checker

:map <C-a> 0
:map <C-e> $
:cmap <C-a> <home>
:cmap <C-e> <end>
:imap <C-e> <ESC>$i<right>
:imap <C-a> <ESC>0i

Use Ctrl-a/Ctrl-e to move to the start/end of a line, emacs style i believe

set background=dark
tells vim that your terminal has a dark background, dont use light colours for text

set backspace=indent,eol,start
backspace over anything instead of that broken backspace some distros seem to include

set backup
set backupdir=~/tmp/vim

keep backup files somewhere neat and tidy, instead of having tilde files all over the place

set hlsearch
search highlights all matching terms

set ignorecase
case insensitive searching

set infercase
auto-completion automatically adjusts case of keywords

set number
line numbers

set showmatch
highlights the matching brace briefly when highlighted

set cursorcolumn
set cursorline
hi cursorcolumn ctermbg=red

turns on a row and column highlight to make it easy to find the cursor

set expandtab
set tabstop=2

switches to soft tabs, 2 characters wide

Labels:

Blog purpose

If you're reading this, you're probably a bot, or wondering what the hell this random collection of unrelated crap is for. basically, it's not really intended for anyone but myself, but left public just in case it can be useful to anyone else. not worth adding to your rss client, but if I show up as a result for something you're searching for I may be of help