Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

Archive for April, 2010

Windows powershell. aliases.

Posted by peeterjoot on April 29, 2010


We’ve been instructed here at work that we must now install Windows XP service pack III, since service pack II is going into a non-update mode.  Four reboots later and much time elapsed, I’ve got the service pack and various other recent windows updates that I’d neglected installed.  One of these is the Windows Powershell.  Well, as a command line kind of guy, I couldn’t turn that down.  Has windows gotten its act together and finally produced a usable shell that one wouldn’t have to run something like the slow cygnus bash to avoid cmd.exe?

Here I’ll make some notes about first impressions.  One of these is that we have aliases, some of which appear to be to help a Unix person feel at home:

PS C:\Documents and Settings\Administrator> alias ls

CommandType     Name                                                Definition
———–     —-                                                ———-
Alias           ls                                                  Get-ChildItem

Interestingly, the old style DOS dir command is also an alias:


PS C:\Documents and Settings\Administrator> alias dir

CommandType     Name                                                Definition
———–     —-                                                ———-
Alias           dir                                                 Get-ChildItem

What is this Get-ChildItem.  It appears to be what the powershell help calls a command-let, and it’s behaviour can be viewed with:


get-help Get-ChildItem




get-help Get-ChildItem –detailed




get-help Get-ChildItem –full


This help text shows that this command-let does a lot more than dir or ls.  For example, it has the capability to query the registry, and do recursion, as well as having exclusion and other flags.  For example, if I don’t want to see the *.txt files in my current dir, I can run:

PS C:\Documents and Settings\Administrator> Get-ChildItem -exclude *.txt

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Documents and Settings\Administrator

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
d—-        11/24/2008  10:34 AM            (null)
d—-        11/24/2008  10:34 AM            .jnlp-applet
d—-        11/24/2008  10:34 AM            Bluetooth Software
d—-         4/29/2010  11:16 AM            Desktop
d-r–         4/29/2010   1:00 PM            Favorites
d—-        11/24/2008  10:35 AM            IBM
d—-        11/24/2008  10:33 AM            My Documents
d—-         2/10/2010  11:11 AM            SametimeMeetings
d—-        11/24/2008  10:33 AM            SametimeTranscripts
d-r–         9/17/2009  12:39 AM            Start Menu
d—-          2/9/2010  12:18 PM            Tracing
-a—         2/28/2010   9:50 AM      11332 gsview32.ini
-a—         7/30/2009   2:59 PM      46520 install.xml
-a—         3/22/2010   6:15 PM      17437 _viminfo

This little beastie of a command appears to be something of a hybrid of ls, and find.


How do we create an alias?

get-help alias | more

This help shows that we can do some interesting queries, like seeing what aliases all map to the Get-ChildItem above.  Example:


PS C:\Documents and Settings\Administrator> get-item -path alias:* | where-object {$_.Definition -eq "Get-Childitem"}

CommandType     Name                                                Definition
———–     —-                                                ———-
Alias           gci                                                 Get-ChildItem
Alias           ls                                                  Get-ChildItem
Alias           dir                                                 Get-ChildItem

and also provides an example of creating one:


PS C:\Documents and Settings\Administrator> new-item -path alias:np -value c:\windows\notepad.exe

CommandType     Name                                                Definition
———–     —-                                                ———-
Alias           np                                                  c:\windows\notepad.exe

The syntax isn’t exactly obvious seeming like the Unix alias builtin, but it appears usable.  Now that we have an alias, putting it somewhere for use in our shell start up is the next logical step.  This appears to do the job


PS C:\Documents and Settings\Administrator> export-alias -name np,note blah
PS C:\Documents and Settings\Administrator> cat blah
# Alias File
# Exported by : Peeter
# Date/Time : Thursday, April 29, 2010 2:36:40 PM
# Machine : JOOT


with import-alias blah, to get them back later when we start a new shell again. 

Posted in perl and general scripting hackery | Tagged: | Leave a Comment »

Some gdb dumping examples.

Posted by peeterjoot on April 28, 2010

I often forget how to dump memory in raw form with various debuggers. Here’s a quick note to myself of how to do it in gdb

As bytes (in hex):

(gdb) x/256xb 0x73d2e0
0x73d2e0:       0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0x73d2e8:       0x01    0x00    0x00    0x00    0x00    0x00    0x00    0x00
0x73d2f0:       0x01    0x40    0x00    0x00    0x00    0x00    0x00    0x00
0x73d3d8:       0x00    0x00    0x00    0x00    0x00    0x00    0x00    0xaa

As 4-byte “words”:

(gdb) x/64xw 0x73d2e0
0x73d2e0:       0x00000000      0x00000000      0x00000001      0x00000000
0x73d2f0:       0x00004001      0x00000000      0x00000000      0x00000000
0x73d300:       0x00000000      0x00000000      0x00000000      0x00000000
0x73d310:       0x00000000      0x00000000      0x00010001      0x00040013
0x73d3d0:       0x00000000      0x00000000      0x00000000      0xaa000000

Note that the repeat count isn’t the total number of bytes to dump, but the total number of objects in the size specification:

(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.

Defaults for format and size letters are those previously used.
Default count is 1.  Default address is following last thing printed
with this command or "print".

Posted in C/C++ development and debugging. | Tagged: , | Leave a Comment »

Byron and Fuller’s QM treatment.b

Posted by peeterjoot on April 24, 2010

I’d purchased the Dover book Mathematics-Classical-Quantum-Physics a while back, and set myself to reading some of the QM treatment in this book recently.  Damn.  With so much else in this book so eminently practical seeming (lots of details on special functions, complex numbers, green’s functions, …), I’d not expected such an abstract treatment of QM.  This book takes an axiomatic approach, which I’ve seen in other places, but does so in the context of Hilbert space and Stieljes integrals, and the spectral theorem for self adjoint operators expressed in terms of an operator valued resolution of the identity (something roughly akin to a requirement to calculate a delta function for the operator).  I have to admit that this is hard to get ones head around.  For such an abstract treatment, there are really not enough problems for me to be able to grasp this well, and the ones that are included are a little too hard seeming.  Understanding how to relate this to some of the much simpler QM treatments I’ve seen is also not clear.

I think this is something to revisit later after tackling QM in a more conventional, physics based way.

Posted in Incoherent ramblings | Leave a Comment »