Archive for category Development
Tabs in Vim
Posted by Prentice Wongvibulsin in Development on September 16, 2009
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.
Ignoring .svn directories with grep
Posted by Prentice Wongvibulsin in Development on August 20, 2009
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.
Recovering files and folders in SVN
Posted by Prentice Wongvibulsin in Development on August 10, 2009
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).
Notes on Multithreaded Debugging with GDB
Posted by Prentice Wongvibulsin in Development on August 4, 2009
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?
Automated MYSQL Backups using mysqldump
Posted by Prentice Wongvibulsin in Development on May 10, 2009
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
Collaboration Tools
Posted by Prentice Wongvibulsin in Development, Technology/Computers on May 4, 2009
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.
Mercurial
Posted by Prentice Wongvibulsin in Development, My Projects, Programming, School Related on April 1, 2008
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.
![]()
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.
