Matlab: date and time

Using now or now() command in Matlab can return current date and time as a serial date number. It is counting how many days has passed A.D.

>> now
ans =
7.3449e+05

Remember there are 365.2422 days in a year.

In case of generating a string, use

>> datestr(now,30)
ans =
20101214T122614
>> datestr(now,31)
ans =
2010-12-14 12:26:22

Format 30 can be used in file names, while format 31 can be used in dates inserted in text. Or you can define your own format:

>> datestr(now,'mmddyyyy')
ans =
12142010

Posted in matlab | Leave a comment

xargs

I want to delete all the .svn folders recursively from current working directory

find . -name .svn -print0 | xargs -0 rm -rf

I want to copy all files within pwd except those with .dat or .out suffix to another folder destination_folder

ls | grep -v [dat\|out]$ | xargs -I {} cp {} destination_folder

Posted in bash | Leave a comment

SVN: broken pipeline when printing truncated log

At least in svn, version 1.4.4 (r25188), this happens.

$ svn log -v | head -20
After printing a few lines, one error msg pops out.
svn: Write error: Broken pipe

The “broken pipe” msg is related to SIGPIPE, a signal sent usually because there is no reader down the pipe to accept what the printer is trying to write. This seems to be one unfriendly feature/bug in svn which lots of users have complained.

This does not affect the output results though. Just ignore the error msg at this stage.

Posted in subversion | Leave a comment

SVN: restore deleted files

One good thing about subversion(svn) is that it does not only keep track of changes you make, it also offers the flexibility to roll back to previous versions. Restoring deleted files is one extreme case in this sense.

For example I want to recover the file filen.txt at r25.


$ svn update -r 24 file.txt
A file.txt
Updated to revision 24.

This will pull file.txt from the repository down to local working directory, but it will disappear after you do another update.


$ svn update
D file.txt
Updated to revision 25.

One way to avoid this is to use full path name in repository.

$ svn copy -r 56 svn://svn.imager.umro/masdar/trunk/mantis/mantis2_Gechuan/file.txt file.txt
A file.txt
$ svn st
A + file.txt
$ svn commit -m 'recover file.txt'
Adding mantis2_Gechuan/file.txt

Committed revision 26.

Of course there are other more clumsy ways to do this. You can pull down the file from repo using relative path, change it, commit, then change it back, commit. This causes unnecessary log entries and can be confusing as time elapses.

The fourth column is `+' when we do svn st. This item is “scheduled with addition-of-history” according to the svn red book, which means it came with its own history that can be rolled back upon. c.f. here.

The fourth column will only show whitespace or a + which means that the file or directory is scheduled to be added or modified with additional attached history. This typically happens when you svn move or svn copy a file or directory. If you see A +, this means the item is scheduled for addition-with-history. It could be a file, or the root of a copied directory. + means the item is part of a subtree scheduled for addition-with-history, i.e. some parent got copied, and it’s just coming along for the ride. M + means the item is part of a subtree scheduled for addition-with-history, and it has local modifications. When you commit, first the parent will be added-with-history (copied), which means this file will automatically exist in the copy. Then the local modifications will be uploaded into the copy.

In case of wanting to recover a file a long time ago, use
svn log --verbose | grep -A5 -B5 file.txt
to show relevant log parts.

related links:
http://sachachua.com/blog/2008/09/subversion-restore-deleted-files/
http://www.mokisystems.com/blog/recover-a-deleted-file-in-subversion/
http://m0j0.wordpress.com/2007/10/25/recovering-deleted-files-from-an-svn-repository/

Posted in subversion | Tagged | Leave a comment

Hello world!

I am starting this blog to log every bit of techniques I learned related to computers, hoping that it will benefit me in future and others who have the same problems.

Posted in Uncategorized | Leave a comment