Wednesday
Jun102009

Time Machine

Not technically needing installation on a new Mac, but does need to be activated.  I keep two active backups of my main laptop, one in Time Machine (built in to OSX) and one with carbon copy cloner.

Wednesday
Jun102009

Carbon Copy Cloner

Aside from Time Machine I also keep a Carbon Copy Cloner backup of my laptop's hard drive.  It is set up to automatically start an incremental backup any time I plug in that particular hard drive.

http://www.bombich.com/software/ccc.html

20111126:  At some point, for reasons I forget, I moved away from Carbon Copy Cloner to SuperDuper.

Thursday
May142009

Subversion (SVN) cheat sheet

My subversion server is set up on my bluehost account and I primarily access it via ssh.  Here are the most useful commands (or ones I forget most often):

Before all of the following commands I need to set the SVN_ROOT_PATH parameter (I’ve actually added this to my .bashrc file):

export SVN_ROOT_PATH="username@bluehostaccount.com/home1/username/SVNROOT"

Also, note that if you need to do any of these locally on the bluehost account, replace the svn+ssh:// with file:///

Create the repository (first log in to bluehost account), which I’ve chosen to name SVNROOT:

svnadmin create SVNROOT

List all projects (directories) in the repository:

svn list svn+ssh://$SVN_ROOT_PATH

Import a directory (named ‘props’ here):

svn import props svn+ssh://$SVN_ROOT_PATH/props -m "initial import of props directory"

Export a directory

svn export svn+ssh://$SVN_ROOT_PATH/idl idl

Check out a directory:

svn co svn+ssh://$SVN_ROOT_PATH/idl idl
svn co svn+ssh://$SVN_ROOT_PATH/py/tmt/trunk/src/tmt tmt

Delete a file for real:

svn delete -m "Deleting for real" svn+ssh://$SVN_ROOT_PATH/pathtodelete

Modify which files in a directory are ignored:

svn propedit svn:ignore .

Create a new project is really just creating a new directory:

svn mkdir svn+ssh://$SVN_ROOT_PATH/NewProjectName

Within a checked out working copy (many of these can be run either just sitting in a directory, or by specifying a filename or directory):

Status of current directory:

svn status

Add a file (can use unix wildcards; need to commit after adding!):

svn add filename

Make a directory (need to commit after!)

svn mkdir newdir

Move a file or directory (need to commit after!)

svn oldname newname

Commit to repository:

svn commit

Examine differences between working copy and repository copy:

svn diff filename

Delete a file (previous versions remain untouched in the repository):

svn rm filetodelete

Update from repository:

svn update
Monday
May112009

Ack! My SVN repository moved and I need to update my checked out copy!

So, in the ideal world your SVN repository would not move without some notice ahead of time. Then one could in an orderly fashion check your working copies in and once the repository is moved check new copies out. Well, as so frequently happens, we do not live in an ideal world. Apparently some weeks ago (I haven't been doing much coding recently, so I'm not sure when) my home directory on my bluehost account was changed from /home/... to /home1/... and SVN stopped working. (I initially blamed this on my end, because the error message was opaque and it took me a while to realize the error message was generated from the server side. So, this shift led to two problems: I had to recompile SVN and I'm stuck with a bunch of checked out working copies that have had modifications but can no longer be checked in because they point to the wrong location!

Or, as I just learned (20101122) have a look into:

svn switch --relocate

My old method: So, I need some semi-automated way to find and replace every instance of /home/USERNAME with /home1/USERNAME in these working copies. Here's a python script I wrote to take care of the problem:

#!/usr/bin/python
import sys
import os
import shutil
if len(sys.argv) != 2:
    print """
Script to modify every instance of a phrase within every file recursively found within a directory. You must specify the directory, even if you just use . to signify current dir. e.g.: ./mv_svn_copy.py . ./mv_svn_copy.py ~/mydir 
"""
    sys.exit()
#the replace XXX with @ thing is so we do not have the actual string
#in this file, in case this file happens to be in the directory you're updating!
OLDstring = "usernameXXXserver.org/home/username/"
NEWstring = "usernameXXXserver.org/home1/username/"
OLDstring = OLDstring.replace("XXX","@")
NEWstring = NEWstring.replace("XXX","@")
workingdir = sys.argv[1]
grepString = "grep -r -l "+'"'+OLDstring+'" '+workingdir

OH, I give up for now editing the hash that wordpress made of my code...

grep_output = os.popen(grepString) filelist = [] <span class="keyword">for</span> a <span class="keyword">in</span> grep_output:     filelist.append(a.replace(<span class="string">'<span class="escape">\n</span>'</span>,<span class="string">''</span>))  OLDstring4sed = OLDstring.replace(<span class="string">'/'</span>,<span class="string">'<span class="escape">\/</span>'</span>) NEWstring4sed = NEWstring.replace(<span class="string">'/'</span>,<span class="string">'<span class="escape">\/</span>'</span>)  <span class="keyword">for</span> filename <span class="keyword">in</span> filelist:     sedString = ( <span class="string">"sed -e 's/"</span> + OLDstring4sed + <span class="string">"/"</span> + NEWstring4sed + <span class="string">"/g' "</span> +                   filename.replace(<span class="string">" "</span>,<span class="string">"<span class="escape">\ </span>"</span>) + <span class="string">" &gt; "</span> +                   filename.replace(<span class="string">" "</span>,<span class="string">"<span class="escape">\ </span>"</span>) + <span class="string">".temp"</span> )     trash = os.popen( sedString )     <span class="keyword">for</span> atrash <span class="keyword">in</span> trash:         <span class="keyword">None</span> shutil.copystat( filename, filename + <span class="string">".temp"</span> )     shutil.move( filename + <span class="string">".temp"</span>, filename )</p>
Monday
May112009

Syntax highlighting in Wordpress

20111126: Obsolete since I moved away from Wordpress.

cd to your wp-content/plugins directory

wget http://downloads.wordpress.org/plugin/wp-dojox-syntax-highlighter.0.2.zip

unzip the file

enable the plugin in WP-admin

Paste your code between <pre><code lang="python"> and </code></pre>, e.g.:

 
#!/usr/bin/python

for a in range(10):
print a


 

Hmmm...well, that still leaves a little something to be desired, but much better than my first attempt.