Recent posts (max 20) - Browse or Archive for more

MATLAB objects and subsref

Oh MATLAB, why do you have to be so obtuse about what you are doing??? I understand that OO stuff is being shoved into a language that didn't originally support it, but WHY isn't it just documented better?

Problem: All of a sudden, my method calls from outside the class stopped working.

Background: All the documentation says that if you have a (dependent) property and there is public access to it, the methods get.propname(obj) and set.propname(obj, val) will be automatically called for you. This is true.

At least, it was until I decided I wanted my class to be able to return more than one value at a time. Once I defined at subsref() method, all external access died and now goes through it instead. EVERYTHING. So you must handle all your own public methods, etc, with useless wrapper logic. MATLAB doesn't do something intelligent like, "well, let me see... OK, there's a get.propname() so I'll call that." Nope. Instead, I need to do:

% (All within a "classdef")
function ar = subsref(obj, subs)
  switch subs(1).type
    case '.'
      switch subs(1).subs
        case 'single_val'
          ar = obj.single_val; % which DOES call the get.single_val() method!!!
      end % subs
    case '()'
      % actually do the stuff I wanted to do with ranges here
  end % type
end % subsref

This really confused me and I didn't find much on their website that was helpful about it either.

Using UltraCompare with TortoiseSVN

From "Nick's Head Sphere"

Diff:
C:\Program Files\IDM Computer Solutions\UltraCompare\UC.exe -t %base %mine
Merge:
C:\Program Files\IDM Computer Solutions\UltraCompare\UC.exe -rom %theirs %mine %merged

MATLAB: Please dbstop here

I am doing a lot with MATLAB at work. I wanted the equivalent of a command that doesn't exist: dbstop here or dbstop now. Came up with two possible solutions with the help of the MathWorks tech support.

1: (from MATLAB documentation)

dbstop if warning 'MFILE:stop';
% Then later:
if ~isequal(input, expected_input), warning('MFILE:stop','Boom!'), end;
% At the end (or else things seem to slow down)
dbclear if warning 'MFILE:stop';

When it drops into the debugger you can then issue the above dbclear command by hand to get it to stop dropping there.

2: (my way)

This way uses the command keyboard that I didn't know about until tech support told me about it - it is not listed in help dbstop but it is a "see-also" in doc dbstop which is annoying...

breakable=1;
% Then later:
if breakable && ~isequal(input, expected_input), keyboard, end;

When it drops into the debugger (you can still use F5, etc) you can then type breakable=0; to stop it from dropping at that point. It doesn't clutter up the dbstop stack so shouldn't slow down unrelated M-files.

RevRagnarok's Blog

This is not a typical "read my thoughts blog" - instead it is a "I found something that may be useful to be jotted down for myself, and maybe others can benefit from my sweat and tears." So it is more of a brain dump. If you find any of it useful, please feel free to drop me a line at blog using this domain name. The tags should be pretty self-explanatory. Also, most of my useful links are dumped at del.icio.us. And with that disclaimer finished, I now have a "funny stuff, etc" blog on blogspot.

VMWare Client Running on Fedora 9

What a pain! You have to get the latest open-vm-tools from SourceForge. Do a configure and make && make check. But then you cannot actually install the files or VMWare gets pissy.

After the make you need to pack up the kernel files you have created and patch the real VMWare installer with them:

for i in *; do mv ${i} ${i}-only; tar -cf ${i}.tar ${i}-only; done
cp *tar /usr/lib/vmware-tools/modules/source/

Then you can run the standard vmware-tools-config.pl and it will use the source you just upgraded.

This page was assembled from various net resources...

Hidden Directories

So, apparently Vista does something that is actually kind of smart. If a program tries to put preference files, etc into the "Program Files" directory, it dumps them elsewhere so that they are still going to be user specific. (This is all hypothesis!) Anyway I was trying to move my scores from WinXP to Vista for "Snoodoku" and this was the solution. http://www.wordofmousegames.com/forums/showthread.php?t=2134


Well, I found it myself, so figured I'd post the solution for future users.

Apparently, Vista merges two directories when a program is trying to store preference files in the Program Files directory. So the file was actually hidden away in C:\Users\RevRagnarok\AppData\Local\VirtualStore\Program Files\Snoodoku


More info from Microsoft.

Car Repair Pricing

Service Manuals for a BUNCH of stuff

"sudo" for Vista

Subversion from Perl

So I spent about three hours trying to get my perl svn_compress script running and I ran kept running into the damned thing segfaulting!

svn_path_basename: Assertion `is_canonical (path, len)' failed.

I finally found the answer. Apparently, libsvn wants '' as the current directory, not '.' like every other program since the beginning of time (Jan 1, 1970, right?).

Three hours.

Where I read the answer. Pasted here:

Peter Samuelson wrote:
> [Julian Gilbey]
>> burnside:~/debian/tex/tetex-bin $ perl -MSVN::Client -e \
>>   'sub print_names { print "<$_[0]>\n"; } $ctx=new SVN::Client;
>>   $ctx->status("", "BASE", \&print_names, 1, 1, 0, 1);' | head -5
>> <>
>> <.pc>
>> <.pc/.version>
>> <configure>
>> <INSTALL.generic>
>
> I reproduced your bugs with subversion 1.3.0-5, so I can properly
> discuss it with upstream.  Unfortunately, I don't know much about the
> Perl bindings.  But comparing "svn status" with your command, it does
> seem to correspond to the "." entry.  I wonder if that is even
> considered a bug.  I mean, if you prefix each entry with $(pwd)/, it is
> fine.
>
>
>> perl: /tmp/buildd/subversion-1.2.3dfsg1/subversion/libsvn_subr/path.c:377:
>> svn_path_basename: Assertion `is_canonical (path, len)' failed.
>
> Right, that's definitely a bug.  Even if this isn't something the perl
> bindings can fix on their own, they should carp or something.
Hi. This is an issue that gets kicked around on dev at svn from time to
time, and usually ends up with the thread fizzling out sooner or later,
with no concrete action being taken, due to a lack of an obvious right
way to proceed. I'll sum up the situation...
There exist a number of path manipulation functions (svn_path_*) which
do not conform to the usual style returning an error status as the
return value, and output data via output pointer parameters. Instead
they return data directly as the return value, and are supposed to only
ever be able to experience errors that merit assert() or abort().
Subversion defines a 'canonical path' format, and most of the functions
(apart from the canonicalizer itself, obviously!) assert that the input
path looks like a canonical path.
Various groups of C programmers will conduct heated debates on whether
this is good programming practice, or an annoyance, but that is
irrelevant where the bindings are concerned, since assert()-ing out of a
scripting language interpreter is clearly bad.
There is a fairly obvious, though non-trivial, solution:
Make the bindings test all input paths (presumably using a path-specific
SWIG "in" typemap) using the same logic as is_canonical, and
canonicalize if necessary. The problem, though, is that discussions of
this nature tend to get intertwined with the parallel issue of whether
the C code is being generally unhelpful in this situation, and should be
changed too.
OK, now you know the background.
Feel free to prod dev at svn to raise awareness of this problem which has
sadly lain dormant for far too long.
Max.
Aside:
The canonical form (IIRC) is mostly common sense stuff:
* no repeated slashes
* no internal /../ sequences
* no trailing slash
BUT it has one weird rule:
* the canonical form of "." is ""

Today I created a yum repository

This is what happens when you are at work and you have ISOs for the 6 CDs of CentOS 5.2 but NOT the DVD, and no connection to the 'net... I couldn't use the 5.2 installer thanks to this bug (it's an embedded Celeron 650). Since I went thru all the work, I also then imported the directory as a "shared folder" under VMWare player and then did the same upgrade path on that machine (I want it to mirror the embedded machine for all versions of everything, except it also has the gcc suite, etc).

One Time Only

(This can be done on any Linux machine with the external drive connected)

  • I mounted the external drive under Linux and there are the 6 ISO CDs. I mounted each and then upgraded what was on it that we already had installed.
  • cd /media/ext_drive/<install dir>
  • mkdir mnt
  • mount -o ro,loop <CDFILE>.iso mnt
  • cp -urv mnt/CentOS .
    • If I were doing this again, I may mount the 6 as /mnt1 thru /mnt6 and then try to use cp -l to make links?
    • (Optionally in another window to watch progress: watch -d 'lsof -c cp -s | cut -c37- | grep rpm ' )
  • umount mnt
  • (Repeat for all 6 - this gives us a CentOS subdir with all the RPMs. If I had the DVD instead of the 6 CDs, this would've been easier)
  • Now we will make this new directory into an "official" repository
  • cd CentOS
  • rpm -i createrepo*rpm (glad that was there!)
  • mkdir repo_cache
  • createrepo -v -p -d -c repo_cache --update --skip-stat .
    • This step takes forever (even longer than the copying above)
    • With a DVD image, this is most likely not even needed!

Every Target Machine

  • We need to disable all the remote repositories:
    • Edit /etc/yum.repos.d/CentOS-Base.repo and add enabled=0 to every section
    • Edit /etc/yum.repos.d/CentOS-Media.repo and change to enabled=1
      • Depending on where the external hard drive is, baseurl will need an added path to it
        • When I did it, it was file:///media/ext_drive/LinuxInstallers/CentOS-5.2-i386-bin-1to6/CentOS/
      • There is a known bug in 5.1 - the GPG signature key should be RPM-GPG-KEY-CentOS-5 (not "beta")
  • yum clean all
  • yum install yum-protect-packages
  • yum upgrade yum
  • yum clean all
  • yum upgrade --exclude=kernel\* -y | tee upgrade.log
    • (Optionally in another window to watch progress: watch -n1 'lsof -c yum -s | cut -c43- | grep rpm ' )
  • grep warn upgrade.log
    • For this, you need to diff each file with the .rpmnew file or .rpmold file and merge them together.
  • Reboot!

Stopping a Windows Executable from Running

To prevent a file from being created, in the past I have created a folder with the same name. This lets you stop a file from running (the example used is a worm executable):

1. Create a registry key with the name of the process you want to prevent to execute. Ex.: calc.exe

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe

2. Under this new key you've just created, create a SZ value called "Debugger" and set it to the following value:

SZ Debugger = "cmd.exe /c echo  %time% %date% calc.exe >> c:\ExecBlocked.log"

From http://blogs.technet.com/marcelofartura/archive/2006/10/24/a-virus-infection-contolling-the-outbreak-tip.aspx with slight mods by me.

Random Unix/Linux Tips

Yeah, that's pretty much the subtitle of this blog, but I found another that has similar stuff:

http://users.softlab.ece.ntua.gr/~ttsiod/tricks.html

My favs (I'm copying in case the site goes down):

Convert a static lib (.a) into a dynamic one (.so)

gcc -shared -o libXxf86vm.so.1.0 \
	-Wl,-soname,libXxf86vm.so.1 \
	-Wl,--whole-archive,libXxf86vm.a,--no-whole-archive

Create PNGs from a pdf presentation

gs -dSAFER -dBATCH -dNOPAUSE -dTextAlphaBits=4 \
    -dGraphicsAlphaBits=4 \
    -r85 -q -sDEVICE=png16m -sOutputFile=icfp-pg%02d.png \
    PhDPresentation.pdf

Read a damaged CD/DVD valid parts and get the rest with rsync

As is often the case, when I bring some burned CD/DVD
from work, I find out that its bad at some offset.
I came up with this Perl script:
---------------------------------------
#!/usr/bin/perl -w
use strict;
my $i=0;
select((select(STDOUT), $| = 1)[0]);
unlink("data");
system("dd if=/dev/zero of=zero bs=2K count=1");
my $step = 1;
print "Sector:             ";
while(1) {
 system("dd if=/cdrom/BadSector of=sector bs=2K skip=$i".
    "count=1 >/dev/null 2>&1");
 if ($? == 0) {
     print sprintf("\b\b\b\b\b\b\b\b%08d", $i);
     system("cat sector >> data");
     $step = 1;
     $i += $step;
 } else {
     system("cat zero >> data");
     $step += $step;
     $i += $step;
     print "\nJumped over $step\nSector:             ";
 }
}
-----------------------------
With the CD/DVD mounted on /cdrom/, it will slowly but
effectively copy sector by sector of the file mentioned
in the 'dd' line into the file called 'data'. Reading
sector-sector proves to be enough to correct a multitude
of read-errors on my DVD reader, but even if that isn't
enough, it will quickly jump over the problem areas
in the DVD, writing blank 'sectors' to mark the jumps.
After that, rsync can save the day:
rsync -vvv -B 131072 -e ssh \
	login@xxx.yyy.zzz.kkk:/path/todata data

"Hidden" Search Feature in File Open dialog

OK, I've been using Windows for years and I really thought I knew almost every shortcut. I Alt-Tab like there's no tomorrow (and occasionally remember to Win-Tab on wifey's laptop w/Vista). Win-R hourly (typing cmd or calc is quicker than finding it on the menu). Win-E any time a USB drive is nearby. Anyway, apparently you can do searches within a "File Open" dialog. Obviously, I knew most programs add a pull-down with file types. But on a whim, I was in UltraEdit the other day and type *vhd and wow it limited the selection to the VHDL files. *.v worked too, but acted like *.v* - however *.l and *.l?? showed the second one acting as I would expect (matching only 3 letter extensions starting with l - .lock was hidden). I tried it in a few other programs like Gimp and it seems to be part of the standard Windows UI. This is XP, I don't have access to any 2000 machines anymore, but no idea when it came about. (As shown before), I hate it when something I'm looking for is right under my nose!

Extra Secure Remote Desktop

I have been using Microsoft's Remote Desktop for a few years now (pretty much since I switched to XP). It's decent, and I like that it retains sessions unlike TightVNC, which is what I had used before. By using a SSH tunnel, I feel confident that my connection is secure and I am willing to visit my banks, etc. using my desktop machine via my laptop on a wireless network. Here's what I did:

On the server (in this case my desktop):

  • Installed the Cygwin build of SSHD as a service
    • Many guides are available, just search with Google above keywords like "cygwin sshd". But in a nutshell:
      • Install cygwin (duh) - include openssh (under Net) and cygrunsrv (under Admin)
      • Set up sshd: "ssh-host-config -y"
      • Start it as a service: "cygrunsrv -S sshd"
  • Allow Remote Desktop usage:
    • Right click on "My Computer" and choose "Properties"
    • Go to the "Remote" tab
    • Make sure that "Allow users to connect remotely to this computer." is checked

On the client (in this case my laptop):

  • You need a way to setup an ssh tunnel. You can use Cygwin's ssh, PuTTY, or my favorite MyEnTunnel. I previously selected MyEnTunnel for some work-related stuff, so I was able to simply add a "Profile".
  • The key is that you want a tunnel from your machine's 3390 to the remote (server) machine's port 3389 (or any other port on your local machine of your choosing). With MyEnTunnel, it is this simple:
    • Profile Page 1 Profile Page 2
  • Once MyEnTunnel has established a connection (a green padlock), you can connect.
  • Start -> Run -> "mstsc"
    • MSTSC setup
  • As you can see, mstsc has no idea what machine you are connecting to. As far as it knows, you connect to localhost which is your machine, which MyEnTunnel then encrypts (using PuTTY's plink) and sends to the remote machine's sshd daemon which forwards it to Windows XP listening for the Remote Desktop connection.
    • (Client:Outgoing port) -> (Client:3390) -> (Client:22) -> [encrypted link] -> (Server:22) -> (Server:3389)

Compressing Subversion checkouts

I'll let the file intro explain itself:

# "Disk space is cheap!" - SVN Authors
# "Except when backing it up!" - RevRagnarok

# This script will drastically reduce the size of an svn checkout so you can back up the folder.
# It will include a script to re-expand the directory with NO interaction with the server.
# It will also (optionally) write a script /tmp/svn_uncompress.sh that will restore all compressed
#   folders.

Something to check out in the future: http://scord.sourceforge.net/


Update 3 Apr 08: Updated the script to touch a file saying it ran so it won't run again. Also have it dump a tiny "readme" file to let somebody else know what is going on.
Update 4 Apr 08: Fixed bug with deep paths.
Update 22 Aug 08: Huge changes, now using "proper" native calls.

Compressing VMWare images

Wow, I thought I've posted this stuff before but could not find it when searching earlier today.

But that's OK because I've done something new today versus the many previous years (the "special case" below).

Anyway, the quickest way to reduce the size of a VMWare image (note: I am not talking about the physical space, I mean the size when you compress the image in the host OS, for example with tar with bzip2):

Reducing VM Image Size (Standard)

  1. telinit 1 # Drops you to single user and shuts down most other stuff
  2. Delete any files you don't need. This includes most of /tmp/
  3. dd if=/dev/zero of=delme bs=102400 || rm -rf delme # This will fill the unused space on the hard drive image with zeros. If you have VMWare set to expand-on-the-fly, it will maximize the size on the host OS, which may not be what you want. Use mount to show which partitions are being used - you need to do this for each partition (e.g. /boot). This is the "meat" of the issue. Do not background this process and then try to do the other partitions in parallel - remember, they are the same physical disk on the host OS and you will thrash your hard drive like crazy (been there).
  4. Check where your swap space is defined - it's in /etc/fstab
  5. swapoff -a # Turns off all swap space (you don't need it right now)
  6. dd if=/dev/zero of=/dev/yourswappartition bs=1024
  7. If /etc/fstab mounted the swap by label:
    • mkswap -L SWAPLabel /dev/yourswappartition
  8. If /etc/fstab mounted by partition alone:
    • mkswap /dev/yourswappartition
  9. You don't need to turn the swap back on, on the next boot of the VM it will be handled since you ran mkswap.
  10. shutdown -h now

Reducing VM Image Size (Special Case)

The special case is what I ran into today. I backed up my work trac/svn VM server as usual. However, I told another customer that I would give them a server. So I need to remove the subversion repository and trac environment. Option 1: Delete them, and then redo all the dd stuff from above, which would be O(free space) vs O(repository). Since "free space" >> "repository", I was trying to avoid that. Option 2: Zero out the files that I don't want anymore. This has the advantage of still reclaiming the gigabytes of space while not waiting for all empty space to be removed. The secret was using the shred command:

find -type f | xargs shred -u -v -n 1 --random-source=/dev/zero

For those trying to understand it better, that is "find all files (that are files) and then pass the list to shred as parameters along with: delete the file when done (-u), tell me everything you do (-v), overwrite the file only once instead of the usual 25 (-n 1), and instead of using /dev/random for your "random" data, just use /dev/zero (--random-source=/dev/zero). Note that using dd directly would have been a pain because I would have to know the size of each file (hundreds) but also it would truncate-on-write meaning that the data being written is not guaranteed to be the actual data we wanted to blank out. That defeats the purpose!

Making This Obsolete

I need to check out this Zerotools package as soon as I can since it seems to do a similar thing all the time.

How to restore a Windows restore point from Linux

Of course, the Ubuntu chest-thumping is kinda annoying and irrelevant. In fact, I would try to find any Live CD with NTFS support (Fedora maybe?) That's all you really need.

In fact it would've been easier for him to check the GRUB config file ;)

http://www.arsgeek.com/?p=3637

Pretty "Diff" in Linux

OK, this is a sad day. I like my Windows utility more than my Linux one. Hopefully somebody out there can point me in the right direction.

I want a graphical diff that looks good. I am used to the beautiful ones in trac and TortoiseMerge (part of TortoiseSVN). I am hoping for something that is available in a default Fedora install that I just haven't seen, or one I can yum install from a virgin install (rules out xxdiff and fldiff). colordiff shows the lines in color but doesn't do colors within the lines.

This is the closest I have found:

pdiff file1 file2 -o - | kghostview -

If anybody has a better one that is easy to use from the command line (so not something like from within emacs or eclipse) then please let me know.

VGA Console modes for laptops

Finally found a table explaining the vga "modes" that the Linux kernel handles. For some reason, on my work laptop (Dell M1710) only gets 0x31B but 0x31F doesn't work.