The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

Archive for January, 2012

The calculators that got me into programming (via: calculators : Algorithms for the masses – julian m bucknall)

Posted by jpluimers on 2012/01/31

I hadn’t visited Julian M Bucknall’s blog for a while, so I just found out he is a calculator collector, and posted a few calculator posts.

He’s much better at writing and narrating than I am, but lets give it a try to see how his posts reminded me of my high school days, what calculators I used back then and how it got me into computing.

Back since I learned to count, math related subjects always worked better for me than for instance language related ones.

It might have to do with my dad. He was a financial economist, so in his job he was juggling with numbers. At home there were ledgers for bookkeeping, slide rules (I inherited his old slide rule, which I still have somewhere in our basement), and over time various types of calculators. He used calculators in the 70s, programmable calculators and a HP 12C programmable financial calculator in the early 80s and small handheld computers in the mid 80s. I remember teaching him both Lotus 1-2-3 and Microsoft Excel later on (at work they didn’t have Visicalc, as they had an Exidy Sorcerer at work that didn’t do spreadsheets).

I have a slightly younger brother with an IQ of almost 50, so my dad bought him a Little Professor in the early 80s to see if his counting skills improved. It didn’t work; he still cannot calculate beyond 20 most of the times and rarely beyond 100. But it was a nice experiment. And he has skills other people don’t have.

Back then, my father worked for the Dutch Ministry of Economic Affairs in working on the subject of consumer loans (he was a strong proponent of legislation protecting individuals from getting bad loans, and very much in favour of publishing netto costs for consumer credit; in fact he was among the first to notice that Dirk Scheringa was trying to lure people in way too much debt against way too high interest rates).

In his department, they standardized on Texas Instruments financial calculators. He had a Texas Instruments TI-59. It was programmable, and took him forever to program, but he was very handy at it. The TI-59 had off-line storage through magnetic cards (which was quite unique, the HP 65 – which was also programmable – had it first, but was twice as expensive). One of the cool programmability features was that it could record keystrokes like they were macros. That alone could speed up work a lot. Finally you could fit TI-59 ROM modules, including one with extra math functions. Thad one made his life a lot easier.

I found the TI-59 interesting, but my English wasn’t good enough yet to be able to learn programming with it. Back then in The Netherlands, you didn’t learn English at primary school, so the first time I got taught English was at age 12, and the first time I got German and French was at age 14.

Ever since I was a little kid, we would go to Germany on holidays (it’s a long but and nice story, maybe in a later blog), with almost yearly camping near Almensee, Bad Dürkheim. The result was that – unlike my school mates – I spoke German when going to high school, and learned that super markets – like hit.de – in Germany would sell way outside the range of grocery shops did in The Netherlands: magazines, music on LP/EP/Single/Casette, household tools, etc.

One of the things back then was that technical literature was either German or English. And tech stuff was way cheaper and abundant in Germany than in The Netherlands.

So when going to high school, I spoke German, and when entering the second class, I needed an electronic calculator. When I saw what they offered at the school and Dutch shops and the price they asked for calculators, I quickly decided I wanted to buy my own calculator during the next summary holiday in Germany.
Most kids getting their calculator from school either had calculators with VFD displays (which ate batteries like crazy) like the the Casio FX-20 or “simple” scientific LCD calculators like the Texas Instruments TI-30LCD (with an ugly hard plastic enclosure and nasty click type buttons). Both had basic scientific calculations, like Sin, Cos, Tan, Log, Ln (and their inverse), square, square root, one over, y powered by x, one memory and a few other bits. But only 8 displayable digits (which sucks when you loose 2 because of exponential notation). Lots of functionality was lacking of which I didn’t know the details back then, but I saw people in senior years struggling with them like mad working around the limitations.

I wanted something better, which was tough to get, as the best you could buy in The Netherlands were the Casio FX-82 and Casio FX-100, which were at least twice as expensive as the FX-20 and just as cluncky. So only the kids with rich parents had them. On top of the FX-20 they had some compelling features like fractions (only the FX-100), representations (scientific, fixed decimal, engineering, normal), trigonometric functions in degrees and radians, 6 levels of parentheses, statistics functions, polar to rectangular conversion and back, and a bunch more smaller things. They had either 8+2 (FX-82) or 10+2 (FX-100) digits which was neat: finally you could see the precision in which they were operating. In fact they internally operated at 12 digits which you could see by multiplying with 10, then subtracting the integer part.

I recently found out that the successors of these machines (FX-260 at CasioEducation.com) are still being sold, including a manual describing the FX-82Solar, FX-85B, FX-260Solar and FX-280 which basically says there is almost no changed functionality since the FX-82. How’s that for 30 years of progress :)

The next summer holiday, I did a price comparison. Casio calculators in Germany were at least 30 percent cheaper than in The Netherlands, and there were even more choices than the summer before especially in department stores like Karstadt (now Arcandor and in bankruptcy). I was like a kid in a candy store, just the candies were a bit more expensive.

So I used some of the money I earned the summer before (peeling flower bulbs) in Germany during our holiday to buy a Casio FX 550 (on the left), which had 10+2 digits, whereas the Casio FX 350 (on the right) had 8+2. They had almost identical functionality to the FX-82 and FX-100 with one tiny addition: hyperbolic trigonometric functions. Buth they didn’t use AAA batteries, so they were not as clunky. And both had fractions (which the FX-82 hadn’t).

In the mean time, they department where my dad worked had switched from his Texas Instruments TI-59 to a Sharp PC-1210, which was the predecessor of the Sharp PC-1211 and shared the same peripherals (casette interface – which my dad had – and printer – which my dad didn’t have). The  TRS-80 PC1 was in fact a Sharp PC-1211 with a different label. Radio Shack was very popular in the UK and US, whereas Sharp was very popular in the rest of the world. Note that the TRS-80 pocket computer is very different from the TRS-80 Model I micro computer system from 1977.

I was 13 now, and my English was slightly better than non existent, so I could help my dad program his Sharp PC 1210 pocket computer. It was fun, as I learned the BASIC programming language, and how to cram things like a small trinangle calculation program (input 3 properties of a triangle, then calculate the other 3) into 400 bytes of programmable memory.

Since it was my first experience to programming, it was also my first encounter to bugs, both of my own and of the PC-1210 itself. For instance, it could overflow its programmable memory, thereby changing some of the variables (that were somehow overlapping in storage), allowing you to display symbols that could not be entered by keyboard, nor converted by functions.

In the mean time, we were getting more advanced math (with a bit of statistics), and started with economics (both business economics and general economics), chemistry (which I later tried to study at university) and physics. That with my exposure to binary and hexadecimal got me to buy another calculator: a Casio FX-115. Next to decimal, it did binary, octal and hexadecimal including conversions between them and the operators AND, OR, XOR, NOT, XNOR and negation. The big drawback was that it was solar only, and would not work in low light conditions.

At high school we had only a few really good match teachers. One of them taught me that 22/7 and 355/113 are continuous fractions estimating pi, and how to approach problems in a structural approach (analyze, deduce, etc). Another one introduced me into the computer lab (originally meant for the 2 senior years, but they let me in anyway).

There they had Apple ][ Europlus machines: a whopping 10 of them for a school with 1000 students was magnificent in the early 80s. 2 of them had a Z80 They ran Applesoft BASIC and Integer BASIC from ROM so my BASIC knowledge from the Sharp PC-1210 came in handy. Also two of the machines had a Z-80 Softcard in it that not only allowed it to display 80 columns, but also supported 16k of bank switched memory, and a Zilog Z80 processor that ran CP/M. There was a Turbo Pascal 1.0 for it that was way better than the optional Apple Pascal (which was based on UCSD Pascal and much slower than Turbo Pascal). That really got me into programming, on which I will write later (probably much later <g>) and gave me a big Deja Vu when seeing virtual machine based programming environments like the Java VM and .NET CLR that are essentially based on the p-code systems on which UCSD Pascal was based.

After lending the Casio 115M to a school mate, it disappeared (getting the money back through insurance was a difficult thing because you could not get them in The Netherlands, and the hoopla of having them accept a Germany cash receipt in stead of a full written receipt was a pain) led me to my final calculator which I got during the autumn break: a Casio 415M dual power calculator: both solar and a battery. It was almost identical to the Casio 415, I think the only difference was the dual power. As you can see on a more elaborate Casio 415M page, it had extra keys in the cover that added many functions: all kinds of conversions (temperature, volume, weight, pressure, etc), physical constants (gravity, lightspeed, Avogadros number, etc). I only recently disposed of it, as the flat cable between the cover and the machine broke. How’s that for a 25 year old piece of equipment!

Oh while on the Casio topic: high school was also the place where I met a lot of international people that followed International Baccalaureate, and where I read The Hitchhiker’s Guide to the Galaxy just two years after I bought a neat Casio Universal Calendar digital watch. My first and last :)

–jeroen

via: calculators : Algorithms for the masses – julian m bucknall.

calculator research sources:

Posted in About, Development, History, Personal, Software Development | Leave a Comment »

An expedition camera backpack, the LowePro DZ100 « Stephen’s Stuff

Posted by jpluimers on 2012/01/30

Not long before our Antarctic trip about 10 weeks ago, I bought myself a waterproof expedition grade backpack: the LowePro DryZone 100 through the Kamera Express Super Store in Rotterdam.

It is a great bag, and the DryZone works really well, provided you lubricated the TIZIP watertight zipper before you use the bag a couple of times, and keep doing that regularly.

The little piece of paper that guides you through it is not that well written, but luckily there are a few on-line guides how to do this properly.

Make sure you always close the TIZIP zipper to the end, that is the only way it will be completely watertight.

There are many reviews of this bag (for instance here and here), so I will keep it short:

  • It is watertight
  • Carrying it by hand and on your back for a full day is a breeze, even when it is completely full
  • Grabbing your stuff is a bit time consuming: opening the TIZIP takes a while
  • It fits an awful lot of equipment
  • It won’t tip over when you put on the ground in the upright position

My recommendation is to buy the yellow/black color combination, not the grey/black color combination.
Yellow is easier to find when you drop it in the water.
Though on our antarctic trip, anything other than white was easy to find :)

This is what Nikon stuff I took to the Antarctic in this bag:

(Thanks Ken Rockwell for all the nice reviews of all these bodies and lenses.
Yes I know there are better lenses and better bodies, and an easier Easytag bluetooth GPS module that pairs with receivers on multiple cameras, but this is what I wanted to afford when I bought them piece by piece).

At the time I bought the DZ100 backpack, you could not get the DZ200 in The Netherlands. The DZ200 is about 30% bigger (volume wise).

–jeroen

via: An expedition camera backpack, the LowePro DZ100 « Stephen’s Stuff.

Posted in About, LifeHacker, Personal, Power User | Leave a Comment »

automatic logon in Windows 2003

Posted by jpluimers on 2012/01/27

At a client that still runs Windows Server 2003 (despite the fact that it is in the extended support phase now), I needed to enable automatic logon (one of the tools they run sometimes fails when nobody is logged on).

This was a bit more tricky than just reading [WayBack] How to turn on automatic logon in Windows (now at How to turn on automatic logon in Windows) and following these steps:

To use Registry Editor (Regedt32.exe) to turn on automatic logon, follow these steps:

  1. Click Start, and then click Run.
  2. In the Open box, type Regedt32.exe, and then press ENTER.
  3. Locate the following subkey in the registry:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
  4. Double-click the DefaultUserName entry, type your user name, and then click OK.
  5. Double-click the DefaultPassword entry, type your password, and then click OK.NOTE: If the DefaultPassword value does not exist, it must be added. To add the value, follow these steps:
    1. On the Edit menu, click New, and then point to String Value.
    2. Type DefaultPassword, and then press ENTER.
    3. Double-click DefaultPassword.
    4. In the Edit String dialog, type your password and then click OK.

    NOTE: If no DefaultPassword string is specified, Windows automatically changes the value of the AutoAdminLogon key from 1 (true) to 0 (false), disabling the AutoAdminLogon feature.

  6. On the Edit menu, click New, and then point to String Value.
  7. Type AutoAdminLogon, and then press ENTER.
  8. Double-click AutoAdminLogon.
  9. In the Edit String dialog box, type 1 and then click OK.
  10. Quit Registry Editor.
  11. Click Start, click Shutdown, and then type a reason in the Comment text box.
  12. Click OK to turn off your computer.
  13. Restart your computer. You can now log on automatically.

Since this depends on some registry settings, you need to make sure they are actually set.
And logging on as someone else will reset the DefaultUserName registry setting.

The article points to another article on “AutoAdminLogon looses DefaultUserName” to solve this using REGINI (and optionally REGDMP which can provide sample output for REGINI), but there is a much easier solution using RegEdit which – as Rob van der Woude points out – can be used unattended as well (besides: REGDMP cannot be downloaded any more, and REGINI requires an additional download).

This is how to do force the DefaultUserName to be reset after logon using RegEdit:

  1. Open an explorer Window in “%ALLUSERSPROFILE%\Start Menu\Programs\Startup
  2. Create a batch file “run-RegEdit-DefaultUserName.bat” there with this content:
    regedit /s Administrator-DefaultUserName.reg
  3. Create a text file “Administrator-DefaultUserName.reg” in the same directory with content like this:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
    "DefaultUserName"="Administrator"

Replace “Administrator” with the username you are actually using.

–jeroen

Via: How to turn on automatic logon in Windows.

Read the rest of this entry »

Posted in Power User, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows 9, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016, Windows Vista | 2 Comments »

.NET/C#: Using IDisposable to restore temporary settrings example: TemporaryCursor class

Posted by jpluimers on 2012/01/26

This is WinForms code from a long time ago, but the concept of using an IDisposable interface to do resource cleanup and restore a temporary setting is very valid.

You use the code below like this:

        private void myMethod()
        {
            // set busy cursor
            using (IDisposable waitCursor = new TemporaryCursor(this, System.Windows.Forms.Cursors.WaitCursor))
            {
                // logic that takes a long while
            }
        }

The code below implements the TemporaryCursor class; you can assign any System.Windows.Forms.Cursors item you want.

It restores the cursor upon these three “events”:

Most often the IDispose pattern is being used to make sure that resources get cleaned up. If you think of a wait cursor as a temporary resource, this example becomes much easier to remember.

Of course this is not limited to the System.Windows.Forms realm, you can just as well use this for non-visual temporaries, and other kinds of UIs like ASP.NET, WPF or SilverLight.

using System.Windows.Forms;

namespace bo.Windows.Forms
{
    public class TemporaryCursor : IDisposable
    {
        private Control targetControl;
        private Cursor savedCursor;
        private Cursor temporaryCursor;
        private bool disposed = false;

        public TemporaryCursor(Control targetControl, Cursor temporaryCursor)
        {
            if (null == targetControl)
                throw new ArgumentNullException("targetControl");
            if (null == temporaryCursor)
                throw new ArgumentNullException("temporaryCursor");
            this.targetControl = targetControl;
            this.temporaryCursor = temporaryCursor;
            savedCursor = targetControl.Cursor;
            targetControl.Cursor = temporaryCursor;
            targetControl.HandleDestroyed += new EventHandler(targetControl_HandleDestroyed);
        }

        void targetControl_HandleDestroyed(object sender, EventArgs e)
        {
            if (null != targetControl)
                if (!targetControl.RecreatingHandle)
                    targetControl = null;
        }

        // public so you can call it on the class instance as well as through IDisposable
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (null != targetControl)
                {
                    targetControl.HandleDestroyed -= new EventHandler(targetControl_HandleDestroyed);
                    if (temporaryCursor == targetControl.Cursor)
                        targetControl.Cursor = savedCursor;
                    targetControl = null;
                }
                disposed = true;
            }
        }

        // Finalizer
        ~TemporaryCursor()
        {
            Dispose(false);
        }
    }
}

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools, WinForms | 4 Comments »

C# text file deduping based on trimmed lines (via: Stack Overflow)

Posted by jpluimers on 2012/01/25

A while ago, I needed to analyze a bunch of files based on the unique trimmed lines in them.

I based my code on the C# Tee filter and the StackOverflow example of C# deduping based on split.

It is a bit more extensive than strictly needed, as it has a few more commandline arguments that come in handy when processing files on the console:

DeDupe - Dedupes a file into unique lines (only the first occurance of a line is kept) standard output
Lines are terminated by CRLF sequences
C# implementation januari 5th, 2012 by Jeroen Wiert Pluimers (https://wiert.wordpress.com),

DeDupe [-i | --ignore] [-t | --trim] [-f | --flush] [-l | --literal] [-? | --h | --help | /?] [file0] [...]
   Example:
 DeDupe --trim file0.txt file1.txt
   Dedupes the appended content of file0.txt and file1.txt into standard output

-t | --trim                  Will trim the lines before considering duplicates
-f | --flush                 Flushes files every CRLF
                               (setting is per tee instance)
-i | --ignore                Ignore cancel Ctrl+C keypress: see UnixUtils tee
-l | --literal               Stop recognizing flags, force all following filenames literally
-? | --h  | /? | --help      Displays this message and immediately quits

Duplicate filenames are quietly ignored.
If no input filenames are specified, then standard input is used
Press Ctrl+Z (End of File character) then Enter to abort.

Here is the source code:

using System;
using System.IO;
using System.Collections.Generic;

namespace DeDupe
{
    class Program
    {
        static void help()
        {
            Console.Error.WriteLine("DeDupe - Dedupes a file into unique lines (only the first occurance of a line is kept) standard output");
            Console.Error.WriteLine("Lines are terminated by CRLF sequences");
            Console.Error.WriteLine("C# implementation januari 5th, 2012 by Jeroen Wiert Pluimers (https://wiert.wordpress.com),");
            Console.Error.WriteLine("");
            Console.Error.WriteLine("DeDupe [-i | --ignore] [-t | --trim] [-f | --flush] [-l | --literal] [-? | --h | --help | /?] [file0] [...]");
            Console.Error.WriteLine("   Example:");
            Console.Error.WriteLine(" DeDupe --trim file0.txt file1.txt");
            Console.Error.WriteLine("   Dedupes the appended content of file0.txt and file1.txt into standard output");
            Console.Error.WriteLine("");
            Console.Error.WriteLine("-t | --trim                  Will trim the lines before considering duplicates");
            Console.Error.WriteLine("-f | --flush                 Flushes files every CRLF");
            Console.Error.WriteLine("                               (setting is per tee instance)");
            Console.Error.WriteLine("-i | --ignore                Ignore cancel Ctrl+C keypress: see UnixUtils tee");
            Console.Error.WriteLine("-l | --literal               Stop recognizing flags, force all following filenames literally");
            Console.Error.WriteLine("-? | --h  | /? | --help      Displays this message and immediately quits");
            Console.Error.WriteLine("");
            Console.Error.WriteLine("Duplicate filenames are quietly ignored.");
            Console.Error.WriteLine("If no input filenames are specified, then standard input is used");
            Console.Error.WriteLine("Press Ctrl+Z (End of File character) then Enter to abort.");
        }

        static void OnCancelKeyPressed(Object sender, ConsoleCancelEventArgs args)
        {
            // Set the Cancel property to true to prevent the process from
            // terminating.
            args.Cancel = true;
        }

        static List<String> filenames = new List<String>();

        static void addFilename(string value)
        {
            if (-1 == filenames.IndexOf(value))
                filenames.Add(value);
        }

        static bool trimLines = false;
        static bool flushFiles = false;
        static bool stopInterpretingFlags = false;
        static bool ignoreCtrlC = false;

        static int Main(string[] args)
        {
            try
            {

                foreach (string arg in args)
                {
                    //Since we're already parsing.... might as well check for flags:
                    if (stopInterpretingFlags)  //Stop interpreting flags, assume is filename
                    {
                        addFilename(arg);
                    }
                    else if (arg.Equals("/?") || arg.Equals("-?") || arg.Equals("-h") || arg.Equals("--help"))
                    {
                        help();
                        return 1; //Quit immediately
                    }
                    else if (arg.Equals("-t") || arg.Equals("--trim"))
                    {
                        trimLines = true;
                    }
                    else if (arg.Equals("-f") || arg.Equals("--flush"))
                    {
                        flushFiles = true;
                    }
                    else if (arg.Equals("-i") || arg.Equals("--ignore"))
                    {
                        ignoreCtrlC = true;
                    }
                    else if (arg.Equals("-l") || arg.Equals("--literal"))
                    {
                        stopInterpretingFlags = true;
                    }
                    else
                    {	//If it isn't any of the above, it's a filename
                        addFilename(arg);
                    }
                    //Add more flags as necessary, just remember to SKIP adding them to the file processing stream!
                }

                if (ignoreCtrlC) //Implement the Ctrl+C fix selectively (mirror UnixUtils tee behavior)
                    Console.CancelKeyPress += OnCancelKeyPressed;

                HashSet<string> keys = new HashSet<string>();
                Int64 index = 0;

                using (StreamWriter writer = new StreamWriter(Console.OpenStandardOutput()))
                {
                    if (filenames.Count == 0)
                        using (StreamReader reader = new StreamReader(Console.OpenStandardInput()))
                        {
                            processInputFileReader(keys, writer, reader, ref index);
                        }
                    else
                        foreach (String filename in filenames)
                        {
                            using (StreamReader reader = new StreamReader(filename))
                            {
                                processInputFileReader(keys, writer, reader, ref index);
                            }
                        }
                    writer.Flush();
                }

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(String.Concat("DeDupe: ", ex.Message));  // Send error messages to stderr
            }

            return 0;
        }

        private static void processInputFileReader(HashSet<string> keys, StreamWriter writer, StreamReader reader, ref Int64 index)
        {
            string line = readLine(reader);
            while (!string.IsNullOrEmpty(line))
            {
                string candidate = line;
                if (keys.Add(candidate))
                {
                    writer.WriteLine(line);
                    index += line.Length + Environment.NewLine.Length;
                    if (flushFiles)
                        writer.Flush();
                }

                line = readLine(reader);
            }
        }

        private static string readLine(StreamReader reader)
        {
            string line = reader.ReadLine();
            if (null != line)
                if (trimLines)
                    line = line.Trim();
            return line;
        }
    }
}

–jeroen

via: C# text file deduping based on split – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development | 4 Comments »