Archive for category Development

Tabs in Vim

Did you know vim supports tabs?

try vim -p foo bar to open the files foo and bar in tabs.

alternatively, the :tabnew bar command opens the file bar in a new tab

:tabs lists the tabs open.

:tabnext to visit the next tab.

For more information, visit the vimdoc site.

, ,

No Comments

Blog Upgrades: Scaling Images

I hacked this theme I’m using a little to hide/show the sidebar. This allows me to put larger photos on my blog posts. Some day when I have some free time I’ll make my own theme which incorporates a fancier version of this… but here’s what this hack can do:

Example 1: I can have a link at the top of a blog post to hide the sidebar and grow the image.

This post contains hi-res images: Please hide the sidebar by clicking HERE.
#72 Flying above SLO

Example 2: I have a toggle button on top of the sidebar to show/hide on any post.

(click on it!)

Example 3: I can link to a blog post with the sidebar hidden by setting hide=1

Link back to this page with sidebar hidden
LInk back to this page with sidebar showing

Incase anyone is interested, this is the code I used to resize the images. This code uses on the moo tools framework. The resize_all function takes an integer sz for width and a boolean instant (optional). The instant variable allows you to resize the image without the moo transition effects (this would be useful if you wanted the images resized on load).

const SZ_SMALL = 633;
const SZ_LARGE = 900;
function resize_all(sz, instant){
   if (null == sz){
      sz = SZ_SMALL;
   }
   if (null == instant){
      instant = false;
   }
   for (x=0; x<document.images.length; x++){

      h = document.images[x].height;
      w = document.images[x].width;

      if (w > 600){ // ignore tiny images
         factor = sz / w;

         nh = factor * h;
         nw = sz;

         if (true == instant){
            document.images[x].height = nh;
            document.images[x].width = nw;
         }
         else{
            document.images[x].set('morph',{duration: 'short',});
            document.images[x].morph({height: nh, width: nw});
         }
      }
   }
}

, , , , , , , , , , , , , , ,

No Comments

Ignoring .svn directories with grep

Trying a recursive grep?
grep -RnH (string) (path) gets you all the occurrences of (string) in (path) with line numbers but if you’re working with an SVN folder, a bunch of hits will come up from the .svn folder. Thats pretty annoying… the fix is using the exclude flag.

Try:
grep --exclude *\.svn* -RnH (string) (path)

Beautiful.

, , , , , , , , , ,

2 Comments

Recovering files and folders in SVN

To restore a file or folder from a previous revision (that has been deleted or modified):

svn cp svn://path/to/folder/or/file@rev /path/to/dest

The source has to be the full URI to the file or folder you wish to restore and the destination can simply be ‘.’ (this folder).

, , , ,

No Comments

Notes on Multithreaded Debugging with GDB

For the past few weeks I’ve been debugging a JNI DLL with GDB for work… here are a few things I’ve learned.

I was using Cygwin in Windows XP for gdb and Netbeans for java.

Some basic stuff that you’re probably already familiar with if you use gdb:
b symbol – break at symbol
b symbol:line – break at line in symbol
c – continue
s – step
n – do not enter functions/calls, step
p – print

Multithread/DLL/JNI related stuff:

Basically how I went about debugging the dll’s in the java program was by adding a breakpoint early on in the java application (after the dll has been loaded). Once the breakpoint is hit, I launch gdb and attach to the java.exe process. At this point I can set all the necessary breakpoints in the DLL and continue in gdb then continue in java.

To attach gdb to a process, the command is: gdb --pid=1234

To get a backtrace from all threads: thread apply all bt full

To switch threads: thread threadno

To list dll functions: info functions !

To list all functions matching a regex: info functions regex

Did I miss anything?

, ,

No Comments

Automated MYSQL Backups using mysqldump

This is a short walk though for building a script to automate mysqldump and copying the backups offsite. I used this script to backup the database for the RSVP system I developed for our Computer Science Awards Banquet. A future improvement for this script is using rdiff-backup but currently I just needed something to work… quickly… so here it goes:

STEP 1: Create a user with LOCK TABLES and SELECT privileges to the database you want to backup. I made mine local access only with no password but if you’re paranoid, you can pass the password to mysqldump with the –password flag.

STEP 2: If you wish to do offsite backup, use ssh-keygen to create a key pair for your sqldb server to connect to your offsite backup server. This will allow the scp to be automated (and not prompt for a password).
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bkupusr/.ssh/id_rsa):
Created directory '/home/bkupusr/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/bkupusr/.ssh/id_rsa.
Your public key has been saved in /home/bkupusr/.ssh/id_rsa.pub.
The key fingerprint is:
a2:b2:aw:w2:63:25:2a:62:fs:d5:ff:fd:11:f1:aa:60 bkupusr@sqlhost

Copy the /home/bkupusr/.ssh/id_rsa.pub. from the sqlhost to the bkuphost’s /home/bkupusr/.ssh/authorized_keys2 file. Make sure the contents of id_rsa.pub take up exactly one line.

STEP 3: Create a script… like the following:
#!/bin/sh
offsitehost=bkuphost
offsiteuser=bkupusr
user=bkupusr
db=dbtobackup
date=`date +%m%d%Y-%H%M`
file="/var/backup/csrsvp-bkup-$date.sql.gz"
mysqldump --user=$user --databases $db | gzip > $file
scp $file $offsiteuser@$offsitehost:~/backup

This script appends a timestamp to the backup file to differentiate between previous backups.

STEP 4: And add the script to your crontab.
crontab -e

On the hour:


0 * * * * ./bkupdb.sh >/dev/null 2>&1

, , , , , , ,

No Comments

Collaboration Tools

Collaborative Editors

EtherPad (http://etherpad.com/) – Great for editing plaintext documents (or latex).
CollabEdit (http://collabedit.com/) – Great for editing source code. Has syntax highlighting for several common languages.

Collaborative Whiteboards

Imagination Cubed (http://www.imaginationcubed.com/) – Great for just sketching ideas
Dabble Board (http://www.dabbleboard.com/) – Great for working collaboratively on diagrams, etc.

, , , , ,

No Comments

Mercurial

For a class I’m taking next quarter, I was looking for a lightweight repository I could host on my shared host which would replace SVN.  I came across Mercurial and after playing around with it a bit, I think it may prove to be a very powerful tool.  This tool will work well for this project because there will only be two people working on the project and the complications of using SVN will only inhibit productivity.  The big idea for Mercurial is getting rid fo the central repository.  Instead, each client “clones” the repository and works off their own local repository.  When they’re done making changes, they “push” their work back to the central repository.  When changes have been made by other users, you “pull” those changes.  see the quick start.

Mercurial Quick Start

 

Quick Start Guide

The key feature I really like about Mercurial for this project is the fact that it is very lightweight.  It works without having to modify Apache!  This allows me to use my shared host to host my repository!  Something you can’t do with SVN.  All it is is a CGI script.  See our repository: http://www.prenticew.com/hg/evil.

, , ,

No Comments