The Wiert Corner – irregular stream of Wiert stuff

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

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20120216-Word-Convert-To-Text

    MPS_6399

    MPS_6398

    More Photos
  • Pages

  • All categories

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

    Join 384 other followers

Archive for the ‘Software Development’ Category

WordPress XML sourcecode help needed; forum posts gets deleted.

Posted by jpluimers on 2012/02/23

Please one of the WordPress.com support people, contact me through my contact form.

I tried posting this question, but as you can see it is marked as ‘Topic Closed, This topic has been closed to new replies’, and looks empty on your forums’:

Please stop deleting the XML from my

</h1>
Since WordPress deletes anything but the most basic XML from [sourcecode language='xml']

tags:

See http://wiert.files.wordpress.com/2012/02/wordpress-html.doc

When I put that in a WordPress post, it deletes the XML.
It does this for anything but the most basic XML.

Please fix that!

–jeroen

Thanks in advance!

–jeroen

Posted in Development, SocialMedia, Software Development, Web Development, WordPress, WordPress | Leave a Comment »

C#/.NET: Assessing the SqlException severity

Posted by jpluimers on 2012/02/22

When handling SqlExceptions in C#, it is wise to assess the Class, as it indicates the severity.

Some classes are user error, others are fatal, etc.

This extension class will help you:

using System;
using System.Data.SqlClient;

namespace bo.MsSql
{
    /// <summary>
    /// see http://msdn.microsoft.com/en-us/library/ms164086.aspx
    /// </summary>
    public static class SqlExceptionSeverety
    {
        public static bool IsInformational(this SqlException sqlException)
        {
            return sqlException.Class < 10;
        }

        public static bool IsUserCorractable(this SqlException sqlException)
        {
            return (sqlException.Class >= 10) && (sqlException.Class < 17);
        }

        public static bool IsSoftwareError(this SqlException sqlException)
        {
            return (sqlException.Class >= 17) && (sqlException.Class < 20);
        }

        public static bool IsFatalSystemProblem(this SqlException sqlException)
        {
            return sqlException.Class >= 20;
        }
    }
}

–jeroen

Posted in .NET, C#, Development, Software Development | Leave a Comment »

FireMonkey and (OS X, iOS, Windows) Link Clearance

Posted by jpluimers on 2012/02/21

Some links that I found useful for doing FireMonkey and development for OS X or iOS:

–jeroen

Posted in Delphi, Development, FireMonkey, OS X FMX, Software Development | 2 Comments »

Funny how StackExchange, StackOverflow, ServerFault, SuperUser and differ in indicating their site outage “We are Offline”

Posted by jpluimers on 2012/02/18

Tonight these most StackExchange sites have maintenance, including their bogs and meta sites (the chat sites like http://chat.stackoverflow.com/ are on-line). I checked these to be off-line, most of the bigger table below are offline too.

Later I will amend this post with the HTML and try to get some site previews too.

A bit later I got this kind of message from Chrome, that tried to protect one of the sites:

Error 139 (net::ERR_TEMPORARILY_THROTTLED): Requests to the server have been temporarily throttled.

Note that http://askubuntu.com/ is up and running :) Read the rest of this entry »

Posted in Development, Pingback, Stackoverflow, Web Development | Leave a Comment »

Free .NET Decompiler – JustDecompile from Telerik

Posted by jpluimers on 2012/02/17

Interesting:

JustDecompile is a new, free developer productivity tool for easy .NET assembly browsing and decompiling.

–jeroen

via: Free .NET Decompiler – JustDecompile.

Posted in .NET, Software Development, Development, C#, C# 2.0, C# 3.0, C# 4.0, VB.NET | Leave a Comment »

Jason Southwell (from arcana) just published DuckDuckDelphi: a unit to do Duck typing in Delphi XE2 (not XE)

Posted by jpluimers on 2012/02/16

If you haven’t seen Jason announce this in the general Delphi 3rd party newsgroup or his announcement thread on the FaceBook Delphi Developer group yet, this is a definitive must read:

Jason Southwell (from arcana) just published DuckDuckDelphi: a unit to do Duck typing in Delphi XE2 (not XE):

Duck Duck Delphi

DuckDuckDelphi is an Open Source (MIT License) unit for Delphi XE2 which adds duck typing functionality to a normally strongly typed language.

Great stuff that makes a truckload of my code so much easier to maintain.

–jeroen

via arcana – DuckDuckDelphi.

(Edit: 1400 UTC+1 Sorry, wrong boolean; wrote “and” but should be “not” XE).

Posted in Delphi, Delphi XE2, Development, Software Development | 8 Comments »

There is a great Android Design – UI Overview site, but no great UI design tools for Android

Posted by jpluimers on 2012/02/15

Recently the Android Design site was launched with great explanation on how to properly design UIs for Android Apps.

Like Apple’s iOS Human Interface Guidelines and Microsoft’s User Experience Design Guidelines for Windows Phone they are a must for any mobile developer.

Together with sites like Android UI Design Patterns, and mockup stencil tools, more Android UI mockup sketch tools and stencils allow you to give prospective users an impression on how an app might be looking like when developed.

What is lacking is a set of real Android GUI design tools. The kind of tools like the Xcode Interface Builder for iOS, or Expression Blend for Windows Phone that – together with iOS PSD templates or Windows Phone design templates (and more templates) – give you a killer start.

Also note Delphi XE2 that has a great UI designer which has consistently covered Windows UI design for 15+ years, including multi-touch and gesture support, and now covers Mac OS X and iOS for HD and 3D apps (but not yet with multi-touch or gesture support).

The only design tool for Android I could find is DroidDraw that emits the XML needed for Android UIs. It is painfully slow and lacks basic things like a property window to edit properties of UI elements.

Given the number of Android app developers, there is much room for improvement.

  • Am I missing something here?
  • What kind of tools are you using?

–jeroen

via: Android Design – UI Overview.

Posted in .NET, Android, Delphi, Development, iOS Development, Mobile Development, Software Development, Windows Phone Development | 6 Comments »

What’s new in .NET Framework 4.5? [poster] (via Heikniemi Hardcoded)

Posted by jpluimers on 2012/02/14

What’s new in .NET Framework 4.5? [poster] (via Heikniemi Hardcoded)I love the “Async ja Await equal to C#” in the picture and the copy-paste re-use in this blog entry from msguy.

Jouni Heikniemi originally posted “What’s new in .NET Framework 4.5 [poster]” on 20111029, then updated the poster on 20111116.

His original poster is Finnish, and his English poster contains a small translation glitch ”Async ja Await equal to C#” (“ja” is Finnish for “and”).

Both posters are PNG filess, so msguy Anil made it into a textual document, including the translation glitch.

I love that, as it shows we are all humans :)

–jeroen

via: Bruno Leonardo Michels – Google+.

Posted in .NET, Software Development, C# 2.0, .NET 4.5, C# 5.0 | 2 Comments »

Batch file to detect Windows version number

Posted by jpluimers on 2012/02/08

Most Batch files for detecting Windows versions try to parse the either the output from VER or the output from SYSTEMINFO, but forget that there many Windows installations are not English. Some even use WMIC, but WMIC is only available for administrators and not available some flavours like XP Home.

Languages issues are always important to watch for. The Dutch Windows XP returns Microsoft Windows XP [versie 5.1.2600] which is just one word different from the English Microsoft Windows XP [Version 5.1.2600]. Other languages may differ even more.

This batch file tries to circumvent the language differences, uses VER and works at least with Dutch and English Windows versions of XP and 7, most likely with many other languages and versions as well.

On a Windows XP SP3 machine, it lists WindowsVersion=5.1.2600 and on a Windows 7 SP1 machine it lists WindowsVersion=6.1.7601.

One possible addition would be to detect x64 or x86.

The detection assumes that VER will emit the version in [angle] brackets, and uses two batch file for loops to get the text in between them using the tokens and delims for loop parameters in the first for loop right behind the begin label and the second for loop right after the parse1 label.

Then it splits the remaining text using spaces at the parse2 label, and takes the right most portion using the shift command at the parse3 label.

Many thanks to Rob van der Woude for a lot of interesting batch file documentation. Read the rest of this entry »

Posted in Software Development, Power User, Windows 7, Windows XP, Scripting, Batch-Files, Windows | Leave a Comment »

Outlook signature locations

Posted by jpluimers on 2012/02/07

When Google searching, most results for the Outlook 2003 Signature Folder Location AppData give you the wrong folder.

They mix environment keys like UserName, UserProfile, but should use AppData as that has been the base since at least Windows XP.

This is the correct folder for any Outlook version (2003, 2010, etc): %appdata%\Microsoft\Signatures

Making sure you use the right environment variable is very important, especially in large Windows based environments that often use roaming profiles and a mix of Windows environments.

For instance, at a client they have a mixed environment of Windows XP and Windows 7, with separate AppData locations for the two on a LAN:

  • Windows XP:
    \\server\DFS\share\Application Data
  • Windows 7:
    \\server\DFS\share\Application Data.v2

There is a very nice Wikipedia article on the Windows Environment variable that explains this situation in the synopsis.

–jeroen

Posted in Software Development, Development, Power User, Windows 7, Windows Vista, Windows XP, Scripting, Batch-Files, Windows | Leave a Comment »

:: Strip HTML Tags :: Online Tools

Posted by jpluimers on 2012/02/02

Handy when copy-pasting stuff from the Web or Word Processor and your tools keep too much formatting:

HTML Tags Stripper is designed to strip HTML tags from the text. It will also strip embedded JavaScript code, style information (style sheets), as well as code inside php/asp tags ()

Edit:

John Kaster indicated that http://ckeditor.com/demo works nicely too, but I could not get their “paste from word” to emit nice clean un-styled HTML for me.

WordOff does work, and cleans away all the HTML tags (I with it didn’t clean structure tags and anchor tags, which you can keep with HTML Tags Stripper).

–jeroen

via :: Strip HTML Tags :: Online Tools.

Posted in Development, HTML, Power User, Software Development, Web Development | Leave a Comment »

Free: German HTML5 Cheat Sheet (via Google Translate)

Posted by jpluimers on 2012/02/01

While speaking at the German BASTA 2011 Fall conference, I noticed a German HTML 5 Cheat Sheet.

I recently found out that a PDF and XPS of that sheet is available.

Here is the English translation of the German download page (I did some editing on the Google Translate result):

Free: HTML5 Cheat Sheet

Know-how | 06/27/2011

MSDN Germany has put on line a cheat sheet with the most important new HTML5 tags and attributes. The handy two-page information informs web developers about how to use the audio, video and canvas element through JavaScript, what CSS3, and geolocation can provide you with and how websites with “Pinned Sites” can become even more useful. Simply download the free PDF (2.17 MB) or XPS file (601 KB), print it, and place it next to your keyboard!

Note that the PDF and XPS are German, but very handy even though your German is not perfect.

–jeroen

via: Google Translate.

Posted in Development, HTML, HTML5, Software Development, Web Development | Leave a Comment »

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, Personal, Software Development | Leave a Comment »

.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 | 2 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 (http://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 (http://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 | Leave a Comment »

Upgrading a Windows XP machine with Visual Studio 2005: KB2251481 Security Update for Microsoft Visual Studio 2005 Service – Microsoft Answers

Posted by jpluimers on 2012/01/24

Every once in a while you need to maintain really old stuff, and start update an old VM.

In case of Visual Studio 2005, the Windows Update and Microsoft Update will get you into a condition where it cannot install ”Security Update for Microsoft Visual Studio 2005 Service Pack 1 XML Editor (KB2251481)“. Not even the direct download will install.

The search for ”some updates were not installed” “Security Update for Microsoft Visual Studio 2005 Service Pack 1 XML Editor (KB2251481)” pointed me to the solution:

There are two versions of KB2251481 June and August. When the June version is installed, the August version refuses to install.

Uninstall the original KB2251481 from the Control Panel. Then reinstall the August version.

The KB2251481 article mentions this only for the “Microsoft Visual Studio 2005 Premier Partner Edition SP1″, but it happens with other Visual Studio 2005 editions as well.

–jeroen

via: KB2251481 Security Update for Microsoft Visual Studio 2005 Service – Microsoft Answers.

Posted in .NET, Development, Software Development, Visual Studio 2005, Visual Studio and tools | Leave a Comment »

Batch file examples – Wait using CHOICE (via: RobVanDerWoude.com)

Posted by jpluimers on 2012/01/19

Most batchfile wait examples require a functioning network connection.

Just in case you haven’t, Rob van der Woude has a nice example on his batch file Wait page using the Choice command.

The bummer is: choice is available on almost all Windows versions (actually since DOS 6.x), but not on Windows XP, and not on Windows 2000, but it is there in Windows Vista and up where you can use the timeout command :(

Alternatives can be found in the other examples on Rob’s wait page.

CHOICE – Wait.bat: Uses CHOICE to wait for a specified number of seconds.

By using REM | before the CHOICE command, the standard input to CHOICE is blocked, so the only “way out” for CHOICE is the time-out specified by the /T parameter.

The idea was borrowed from Laurence Soucy, I added the /C parameter to make it language independent.

@ECHO OFF
IF "%1"=="" GOTO Syntax
ECHO.
ECHO Waiting %1 seconds
ECHO.
REM | CHOICE /C:AB /T:A,%1 &gt; NUL
IF ERRORLEVEL 255 ECHO Invalid parameter
IF ERRORLEVEL 255 GOTO Syntax
GOTO End
:Syntax
ECHO.
ECHO WAIT for a specified number of seconds
ECHO.
ECHO Usage: WAIT n
ECHO.
ECHO Where: n = the number of seconds to wait (1 to 99)
ECHO.
:End

–jeroen

via: Batch file examples – Wait.

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Dear Mister Jones » How to insert a carriage return with batch

Posted by jpluimers on 2012/01/17

When appending multiple text files to a big one (for instance to post-processing on the total: dedupe, sort, gather statistics, etc) you often will find one or more of the source files missing a CRLF.

So you will have to insert those carriage return line feed combo’s manually.

Well, mr Jones points out that:

there’s actually an easy way to simply echo a carriage return and line feed instead, by just issuing an echo command followed immediately by a period (no space in between), like this:

echo. >> somefile.txt

Thanks Jared!

–jeroen

via: Dear Mister Jones » How to insert a carriage return with batch.

Posted in Batch-Files, Development, Scripting | Leave a Comment »

Should watch: Dave Herman: The Future of JavaScript #ECMAScript6

Posted by jpluimers on 2012/01/11

On:

Mozilla Labs engineer and TC39 representative Dave Herman joined us at YUIConf 2011 to give this keynote talk on the future of JavaScript, covering many of the new features currently under consideration for ES6, the next edition of the ECMAScript standard.

Many wonderful new features. Now it just need some great tooling.

–jeroen

via: http://www.youtube.com/watch?v=u4IdoBU1uKE

Posted in Development, JavaScript/ECMAScript, Scripting, Software Development | Leave a Comment »

great answer by Remy Lebeau on windows – CreateProcessAsUser doesn’t work when “change user” – on Stack Overflow part of @StackExchange

Posted by jpluimers on 2012/01/10

You might wonder why I quoted two great StackOverflow answers recently. Well, it is because I absolutely love the way that StackExchange.com and StackOverflow.com changed how to find quality answers (and questions!) on topics varying from programmers through Cooking to Chines Language Usage in a community based way.

This one is by Remy Lebeau, who is part of TeamB:

You don’t need to enumerate running explorer.exe processes, you can use WTSGetActiveConsoleSessionId() instead, and then pass that SessionId to WTSQueryUserToken(). Note that WTSQueryUserToken() returns an impersonation token but CreateProcessAsUser() needs a primary token, so use DuplicateTokenEx() for that conversion.

You should also use CreateEnvironmentBlock() so the spawned process has a proper environment that is suited to the user account that is being used.

Lastly, set the STARTUPINFO.lpDesktop field to ‘WinSta0\Default’ instead of nil so the spawned UI can be made visible correctly.

I have been using this approach for several years now and have not had any problems with it. For example:

… code sample is in the answer …

–jeroen

via: windows – CreateProcessAsUser doesn’t work when “change user” – Stack Overflow.

Posted in Delphi, Development, Software Development | 2 Comments »

Great answer by Cosmin Prund: How and when are variables referenced in Delphi’s anonymous methods captured? – Stack Overflow

Posted by jpluimers on 2012/01/05

Every once in a while, by accident you stumble on a really great answer on StackOverflow.

Here is a quote from Cosmin Prund describing on how Delphi implements anonymous methods using a TInterfacedObject descendant:

When you have a function like the one in the question, where you have an anonymous method accessing a local variable, Delphi appears to create one TInterfacedObject descendant that captures all the stack based variables as it’s own public variables. Using Barry’s trick to get to the implementing TObject and a bit of RTTI we can see this whole thing in action.

Read his full answer for the complete description including sample code.

I stumbled on this great answer trough the question Is it possible for a managed local variable to transparently “travel to” another local scope? which might sound like an odd question, but it is not: StackOverflow is about learning, and some people do that by asking questions on solving problems in a very uncommon way, just to learn there are far better ways of obtaining what they want.

–jeroen

via: How and when are variables referenced in Delphi’s anonymous methods captured? – Stack Overflow.

Posted in Delphi, Development, Software Development | Leave a Comment »

Introducing the for-if anti-pattern – via: The Old New Thing – Site Home – MSDN Blogs

Posted by jpluimers on 2012/01/03

I really like what Raymond Chen writes, not just the tech stuff in his Old New Thing blog, but  especially in his comments.

Here is a nice example:

You also see this anti-pattern used in real life: “What flavors do you have?” and then after the list of flavors is recited, “I was hoping you had raspberry.” -Raymond

And he is right, in real life, lots of people have stopped to actively think, expecing others (very often the government) to solve their problems.

It reminds me of one our kitchen magnets: “If it’s called common sense, then why is it so rare?”.

So: why do you think it is so rare?

–jeroen

via: Introducing the for-if anti-pattern – The Old New Thing – Site Home – MSDN Blogs.

Posted in About, Development, Opinions, Personal, Software Development | 2 Comments »

More vulnerabilities solved than just the ASP.NET hash collision DoS: Microsoft Security Bulletin MS11-100 – Critical : Vulnerabilities in .NET Framework Could Allow Elevation of Privilege (2638420)

Posted by jpluimers on 2011/12/29

In addition to the ASP.NET hash collision Denial of Service attack, Microsoft patches 3 more vulnerabilities resulting in an Aggregate Severity Rating that is Critical.

This is a summary of the vulnerabilities. Please read the full MS11-100 bulletin for more details and how to download and install the patches.

Vulnerability Severity Rating Maximum Security Impact Affected Software CVE ID
Important Denial of Service Collisions in HashTable May Cause DoS Vulnerability CVE-2011-3414
N/A or Moderate N/A or Spoofing Insecure Redirect in .NET Form Authentication Vulnerability CVE-2011-3415
Critical Elevation of Privilege ASP.Net Forms Authentication Bypass Vulnerability CVE-2011-3416
Important Elevation of Privilege ASP.NET Forms Authentication Ticket Caching Vulnerability CVE-2011-3417

The CVE-2011-3415 is N/A in .NET 1.1, and Moderate in all other .NET versions.

–jeroen

via Microsoft Security Bulletin MS11-100 – Critical : Vulnerabilities in .NET Framework Could Allow Elevation of Privilege (2638420).

Posted in .NET, ASP.NET, C#, Development, Software Development, VB.NET, Visual Studio and tools | Tagged: , , , , , | Leave a Comment »

Many more web platforms vulnerable to the hash collision attack (not only ASP.NET) #28C3 @hashDoS #hashDoS @ccc

Posted by jpluimers on 2011/12/29

When writing my Patch your ASP.NET servers ASAP early this morning, I didn’t have time to research the full extend of the vulnerabilities published at 28C3 (slides, mp4), though a small bell was ringing a message that I had seen something like it before earlier this century.

I was right, this posting on perlmonks direct me to a /. posting in 2003 pointing me to the research paper on low-bandwidth attacks based on hash collisions (pdf version) that I had seen before. Perl 5.8.1 fixed it September 2003 (search for “hash” in that link).

The attack can be used for DoS because a normal distributed hash table insert of n elements will be running O(n), but a carefully crafted insert of those elements will run O(n^2).

Carefully crafting a worst case scenario depends on how well you can predict collisions in the underlying hash table implementation, which - apparently - is not too difficult, and requires little bandwidth.

Many platforms and languages are vulnerable, including those based on Java, Tomcat, .NET, Ruby, PHP and more in greater or lesser extent. I have the impression that the list only includes big names, but presume platforms based on smaller names (ASP, Delphi, Objective C) are equally vulnerable.

Just read the articles on CERT 903934, oCERT 2011-003Arstechnica, Cryptanalysis.euHeise (German), Hackillusion and the research paper published at 28C3.

a few quotes:

“This attack is mostly independent of the underlying Web application and just relies on a common fact of how Web application servers typically work,” the team wrote, noting that such attacks would force Web application servers “to use 99% of CPU for several minutes to hours for a single HTTP request.”

“Prior to going public, Klink and Wälde contacted vendors and developer groups such as PHP, Oracle, Python, Ruby, Google, and Microsoft. The researchers noted that the Ruby security team and Tomcat have already released fixes, and that “Oracle has decided there is nothing that needs to be fixed within Java itself, but will release an updated version of Glassfish in a future CPU (critical patch update).”

“The algorithmic complexity of inserting n elements into the
table then goes to O(n**2), making it possible to exhaust hours of CPU time using a single HTTP request”

“We show that PHP 5, Java, ASP.NET as well as v8 are fully vulnerable to this issue and PHP 4,
Python and Ruby are partially vulnerable, depending on version or whether the server
running the code is a 32 bit or 64 bit machine.”

Microsoft seems to have been notified pretty late in the cycle, I presume because the researchers started with a some platforms and finally realized the breath of platforms involved.

The ultimate solution is to patch/fix the platforms using for instance a randomized hash function a.k.a. universal hashing.

Microsoft will provide a patch for ASP.NET later today, Ruby already patched and other vendors will soon or have already (please comment if you know of other platforms and patches).

The links this morning indicated there were no known attacks. That is (maybe was) true for ASP.NET, but for PHP a public proof of concept of such a DoS is has been published by Krzysztof Kotowicz (blog) with sources at github and a demo html page.

Temporary workarounds (based on the some of the links in this and the prior blog post, and the workarounds mentioned here and here):

  1. If you can: replace hash tables by more applicable data structures
    (I know this falls in the for-if anti-pattern category, but lots of people still use a hammer when a different tool works much better)
  2. Limit the request size
  3. Limit the maximum number of entries in the hash table
  4. Limit form requests only for sites/servers/etc that need it.
  5. Limit the CPU time that a request can use
  6. Filter out requests with large number of form entries

Some platforms already have applied temporary workarounds (I know of Tomcat (default max 10000 parameters), and PHP (default max_input_vars = 1000) did, and looks like the ASP.NET fix will do too).

Other platforms (like JRuby 1.6.5.1, CRuby 1.8.7 (comments) and Perl 5.8.1 in September 2003 ) fixed it the proper way.

Note: workarounds are temporary measures that will also deny legitimate requests. The only solution is to apply a fix or patch.

A major lesson learned today for a few people around me: when vendors start publishing “out of band” updates, do not trust a single 3rd party assessment with state “initial investigation”, but be diligent and do some further research.

–jeroen

PS: Just found out that most Azure users won’t need to manually apply a fix: just make sure your Hosted Service OS servicing policy is set to “Auto”.

Posted in .NET, ASP.NET, C#, Delphi, Development, Java, JavaScript, PHP, Scripting, Software Development, Web Development, Windows Azure | 5 Comments »

Patch your ASP.NET servers ASAP: ASP.NET Security Update Shipping Thursday, Dec 29th – ScottGu’s Blog

Posted by jpluimers on 2011/12/29

Quotes:

The security update we are releasing resolves a publicly disclosed Denial of Service issue present in all versions of ASP.NET.  We’re currently unaware of any attacks on ASP.NET customers using this exploit, but we strongly encourage customers to deploy the update as soon as possible.

Attacks such as these are not specific to any particular language or operating system. Presenters at the security conference discussed how to cause them using standard HTTP form posts against several different web frameworks (including ASP.NET). Because these attacks on web frameworks can create Denial of Service issues with relatively few HTTP requests, there is a high likelihood of attacks happening using this approach. We strongly encourage customers to deploy the update as soon as possible.

The security update we are releasing on Thursday, December 29th updates ASP.NET so that attackers can no longer perform these attacks. The security update does not require any code or application changes.

During the 28e Chaos Communication Congress in Germany, on December 28, 2011 a security vulnerability was showed that potentially can DOS many types of web servers (including ASP.NET) with a carefully crafted 100 kilobyte plain HTTP form post request.

Information on the ASP.NET vulnerability was published by Microsoft on December 27, 2011.

ASP.NET on all supported .NET versions (1.0 SP3, 1.1 SP1, 2.0 SP2, 3.5 SP1, 4.0) on all supported Windows versions (XP, Server 2003 and R2, Vista, 7, Server 2008 and R2) are affected.

Since the vulnerability as being very severe, Microsoft will publish an out of band fix today (December 29, 2011) at around 10 AM Pacific time (during winter, this 1800 UTC) on Windows Update, Windows Server Update and the Microsoft Download Center followed 3 hours later by a webcast at 01 PM Pacific time (2100 UTC).

More about about 28C3 in German.

–jeroen

via: ASP.NET Security Update Shipping Thursday, Dec 29th – ScottGu’s Blog.

Posted in .NET, ASP.NET, Development, Software Development | 1 Comment »

Get last command line argument in windows batch file – via: Stack Overflow

Posted by jpluimers on 2011/12/29

Sometimes you want to parse commandline arguments in batch files starting at the last one.

For parsing them left to right, the shift command comes in handy.

But there is no “shift-reverse” command, so you need some trick.

StackOverflow to the rescue: user Joey provides this really nice answer:

The easiest and perhaps most reliable way would be to just use cmds own parsing for arguments and shift then until no more are there.Since this destroys the use of %1, etc. you can do it in a subroutine

@echo off
call :lastarg %*
echo Last argument: %LAST_ARG%
goto :eof
:lastarg
set "LAST_ARG=%~1"
shift if not "%~1"=="" goto :lastarg
goto :eof
:eof

–jeroen

via: Get last command line argument in windows batch file – Stack Overflow.

Posted in Batch-Files, Development, Power User, Scripting, Software Development | Leave a Comment »

Added a few links to my “Tools” page, @WordPress bug spuriously inserting div tags still present.

Posted by jpluimers on 2011/12/28

While re-designing a Visual Studio 2010 plus Delphi XE2 install for a specific client, I updated some of my Tools page links:

And found out that the WordPress still wrongly inserts div tags when you step out a list by pressing Enter twice is still present. Annoying, as it has been there for at least 2 years, so I’m still interesting in people having a workaround for it.

–jeroen

Posted in .NET, C#, Delphi, Development, Software Development, TFS (Team Foundation System), Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

Applying XE2 Update 3: uninstall IDE Fix Pack first, then apply, then install updated IDE Fix Pack. Also update EurekaLog.

Posted by jpluimers on 2011/12/22

Before installing updates, it is always wise to read the release notes.

In this case, the below quote from the Release Notes for XE2 Update 3 was very important for me, as I use the IDE Fix Pack:

IDE Fix Pack Is Not Compatible with Update 3

The IDE Fix Pack for XE2 is incompatible with XE2 Update 3. If you have the IDE Fix Pack for XE2, you should uninstall the IDE Fix Pack for XE2 before installing Update 3. A revised version of the IDE Fix Pack for XE2 will be made available at http://andy.jgknet.de/fixpack/ .

The cool thing is, on the same day that Delphi XE2 Update 3 got releasedAndy also released the new FixPack 4.6 last week and also explained the cause of the incompatibility.

Note that because of the same reason, more products will need to be updated. EurekaLog also released an update, and I expect more vendors to release updates soon.

Update 3 breaks the monthly release cycle, but for a reason. This update contains way more fixes than the previous ones, in a much wider area and with short turnarounds between reporting and fixing (yes, it does pay to report bugs through QualityCentral). Just read the list of fixes. It is similar to the big updates we used to have for previous Delphi versions.

It also requires a lot more disk space, so make sure you have at least 5 gigabytes of free disk space.

Not related to Update 3, but still nice is that Thomas Müller made available for download the Expertimental GExperts version 1.35-2011-12-18 that is compatible with Delphi XE2. It includes a code formatter that has different bugs than the Delphi XE2 one, but for me usually works better.

–jeroen

via: Release Notes for XE2 Update 3 – RAD Studio XE2.

Posted in Delphi, Delphi x64, Delphi XE2, Development, Software Development | Leave a Comment »

svn – How do I move a file or folder from one folder to another in TortoiseSVN? – Stack Overflow

Posted by jpluimers on 2011/12/21

Duh – sometimes simple things are simple, you just have to know how simple: move it using the right mouse click as Mark Embling answers on StackOverflow.

–jeroen

via: svn – How do I move a file or folder from one folder to another in TortoiseSVN? – Stack Overflow.

Posted in Development, Software Development, Source Code Management, Subversion/SVN | Leave a Comment »

Delphi XE2 and iOS: things you should not do

Posted by jpluimers on 2011/12/20

When developing applications for iOS using Delphi XE2, it uses a smart but convoluted FPC detour.

That results in a few things you should take into account when developing iOS applications:

  • Do not use Unit scope identifiers (that’s why for instance the FireMonkey unit FMX.Dialogs is called FMX_Dialogs when building an iOS application)
    So don’t do a “uses System.SysUtils”, but “uses SysUtils” and don’t name your units using Unit scope identifiers for now.
    It would be so nice if Embarcadero shipped the tool that made all the FMX_* units out of the FMX.* units; that alone would make code sharing between non-iOS and iOS applications in Delphi a lot easier.
  • Do not use Generics (though FPC supports them, the FPC mode that Delphi XE2 uses for iOS compatibility does not)
  • Do not use new style RTTI or TValue (they are not supported by FPC)
  • Do not use any other dataset than the ones directly descending from TDataSet (so anything TClientDataSet or IBX like is out) mostly because those depend on external C obj files, Unit scope identifiers or new style RTTI
  • Do not spread your application sources over multiple directories
  • Do not use the TMyDynamicArray.Create shortcut of initializing dynamic arrays, but use a wrapper function that uses Open Array parameters as Rob Kennedy explains on StackOverflow.
  • Do not run dpr2xcode after you have changed any files it generated (believe me, you will change those). This basically makes you have to reinvent most of the dpr2xcode logic, which is a real pain, as I’m still in that process and not completed.
    These are the things you usually want to manually keep track of:
    - most of the manual changes are keeping the “YourProject.dpr” and dpr2xcode generated “YourProject.pas” in sync
    - altering the PNG files to show different splash graphics / application icons

I will extend this list over time.

Note that this detour should be gone in a future Delphi version, but for now you need to take the above into account.

It means that you might feel like programming with one hand behind your back. Well, the Objective C and Xcode way feels very similar, but from a different perspective :)

–jeroen

Posted in Delphi, Delphi XE2, Development, Software Development, xCode/Mac/iPad/iPhone/iOS/cocoa | 2 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 384 other followers