Subscribe RSS

Archive for December, 2008

Multiple copy and paste in OS X Dec 31

PTh Pasteboard

This excellent piece of software allows you to have multiple clipboards. I find this an essential piece of software to aid development. Being able to copy multiple things in an application before switching apps and pasting is so useful.

I’ve set this up to allow my F keys to quickly access the last few copy buffers. Sweet. Why doesnt this come as standard on a Mac?”

Get the software, PTHPasteBoard from PTH Consulting. Its free, although you can purchase the pro version to enable filtering.

Uploading a binary file into MySQL Dec 30

Far more fun than bash

If your MySQL database is running on a remote server then it can be quite a job to load a binary file (such as a jpg, movie or zip file) directly into the database when you have no file access to that server.

This bash script gets round the problem by converting the file to HEX and uploading it to the database:

#!/bin/bash
#Uploads a file (parm 2) to a database with id=parm 1

#INITIALISATION=====
#the id in the SQL table to update
ID=$1

#filename of file to upload
SOURCE=$2

#Some internal initialisation
TMPFILE="$SOURCE.hex"
SQL="/PATH_to_MYSQL/mysql -uUSERNAME -pPASSWORD DATABASENAME -BNe"

# PROCESS===========
#Let the user know whats going on
echo "Uploading '${SOURCE}' to database with 'id=${ID}'"

#Convert the file to a hexed version
/usr/bin/hexdump -ve '1/1 "%02X"' ${HEXPARMS} ${SOURCE} > ${TMPFILE}

#Upload into the database, unhexing as we go
$SQL "update files set data=unhex('`cat ${TMPFILE}`') where id='$1'"

# CLEANUP============
#Tidy up
rm -f ${TMPFILE}

echo "Upload completed."
Category: SQL  | Tags: , , ,  | Leave a Comment
Useful VI commands Dec 30
Shes not using vi

:set hold-board-look-pretty

I use vi/vim quite a lot, heres a useful list of commands. Thanks to these people for the original: here

:set paste
turn off all auto-formatting. Use before pasting  text

:set nu
show line numbers.

:set ic
ignore case differences when searching.

:set ai
set automatic indent.

:set sm
show matching ( or { with ) or } in insert mode.

---------------

down-arrow up-arrow
move down/up 1 line.

right-arrow left-arrow
move right/left 1 character column.

0  $
go to 1st/last column of current line.

return
go down to 1st printable character of next line.

nw  nb
move right/left n words (1 word if n omitted).

ng
go to line n (end of file if n omitted).

ctrl-f  ctrl-b
page forward/backward 1 screen.

ctrl-d  ctrl-u
page forward/backward half a screen.

[[  ]]
go to beginning of current/next c function.

/expressionreturn
search forwards for expression.

?expressionreturn
search backwards for expression.

n  n
repeat last / or ? command in same/reverse direction.

ytarget
copy (yank) text up to target to buffer.

y
copy current line to buffer.

itextesc
insert text before cursor.

otextesc
open new line below cursor and insert text.

r
replace character under cursor with next typed.

rtextesc
replace text.

backspace
in insert mode, delete character before cursor.

x  x
delete character under/before cursor.

nx
delete n characters under and to right of cursor.

nx
delete n characters before cursor.

dd
delete current line.

ndd
delete n lines.

d
delete from cursor to end of line.

p  p
put back yanked or deleted text below/above current line.

j
join current and next lines.

:m,n s/old/new/gc
global replace (g=every occurrence on line, c=prompt);

m=.
means from current position, n=$ means to eof.

u
undo last change.

--------------

:q
quit, provided no changes were made.

:q!
quit without saving.

:w
save (write) changes.

:m,n w file
save lines m through n (default=all) to file.

:x
save changes and quit.
Category: Linux  | Tags: , ,  | Leave a Comment
Mac OS X DNS Flush Dec 11

Local DNS cache need refreshing? type this handy command into the terminal

dscacheutil -flushcache

Top tip: Close Safari before running the above!
Category: OS X Tips  | Tags: ,  | Leave a Comment