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 2,524 other followers

Archive for the ‘Software Development’ Category

Jan Schaumann: “The secret language of coders, part N of many. Today: “risk acceptance”… “

Posted by jpluimers on 2021/12/08

From a while back, but more relevant than ever:

[Archive.is] Jan Schaumann on Twitter: “The secret language of coders, part N of many. Today: “risk acceptance”… “

Obligatory video below the fold.

–jeroen

Read the rest of this entry »

Posted in Development, DevOps, Infrastructure, LifeHacker, Power User, Security, Software Development | Leave a Comment »

In case I ever need rails performance troubleshooting: I feel like I should be able to ask @datadoghq “What’s the CPU load across all our Rails controllers”, but have no idea where to start with that.

Posted by jpluimers on 2021/12/08

Just in case I need to do performance troubleshooting in Rails some day: [Archive.is] hey on Twitter: “@shelbyspees @honeycombio From a browser. Thinking is we had trouble even narrowing it down to a section of the site. Thinking if we could see that most of the load was in some_controller we could maybe dig in there. I don’t want to take up too much of your time, but how would a double request show up?” / Twitter

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

Chrome Print dialogue not offering fit to page, landscape, other printing options ( I’m looking at you @OHRA )

Posted by jpluimers on 2021/12/08

Some sites manage to disable various printing options (including layout, so you cannot choose between landscape and portrait any more, or force landscape when portrait works better or vice versa).

Googling this got me into a web of things that didn’t help me (see links below), but those led me to this query [Wayback] chrome save as pdf layout missing portrait landscape – Google Search.

That returned a helpful result at [Archive.is/Wayback] Chrome Print dialogue not offering fit to page, landscape, other printing options – Google Chrome Community:

I found a solution.

1.  Install the Stylus Extension.
2.  Go into the Stylus extension and click on “Write new style”.
3.  Put the following code in:
@page {
  size: auto;
}

4.  Give it a name (I called mine “Fix Orientation”) and save it.

5.  Reload the page you’re trying to print and the print dialogue should now have the “Layout” option and you should always get it for any page you print from now on.

It’s about the extension [Archive.is] Stylus – Chrome Web Store

Redesign the web with Stylus, a user styles manager. Stylus allows you to easily install themes and skins for many popular sites.

I reconfigured the OHRA Mijn Zorg site to force re-enabling of layout by adding @page { size: auto !important; } for https://mijn.ohrazv.nl/ (click the Save button to save this change permanently):

Read the rest of this entry »

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

How to build a CD ISO image file from the windows command line? – Stack Overflow

Posted by jpluimers on 2021/12/07

As I might need this in the future, some highlights from [Wayback] How to build a CD ISO image file from the windows command line? – Stack Overflow:

–jeroen

 

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

On TStrings (and TStringList) sorting: what the default Sort behaviour is and how to change sorting order

Posted by jpluimers on 2021/12/07

Because I need this eventually, here the full quote of my answer in [Wayback] sorting – How can I get TStringList to sort differently in Delphi – Stack Overflow (The default Sort behaviour is to accommodate i18n sorting in natural order):

i18n sorting totally depends on your locale.
So I totally agree with PA that this is not a bug: the default Sort behaviour works as designed to allow i18n to work properly.

Like Gerry mentions, TStringList.Sort uses AnsiCompareStr and AnsiCompareText (I’ll explain in a few lines how it does that).

But: TStringList is flexible, it contains SortCustomSort and CompareStrings, which all are virtual (so you can override them in a descendant class)
Furthermore, when you call CustomSort, you can plug in your own Compare function.

At the of this answer is a Compare function that does what you want:

  • Case Sensitive
  • Not using any locale
  • Just compare the ordinal value of the characters of the strings

CustomSort is defined as this:

procedure TStringList.CustomSort(Compare: TStringListSortCompare);
begin
  if not Sorted and (FCount > 1) then
  begin
    Changing;
    QuickSort(0, FCount - 1, Compare);
    Changed;
  end;
end;

By default, the Sort method has a very simple implementation, passing a default Compare function called StringListCompareStrings:

procedure TStringList.Sort;
begin
  CustomSort(StringListCompareStrings);
end;

So, if you define your own TStringListSortCompare compatible Compare method, then you can define your own sorting.
TStringListSortCompare is defined as a global function taking the TStringList and two indexes referring the items you want to compare:

type
  TStringListSortCompare = function(List: TStringList; Index1, Index2: Integer): Integer;

You can use the StringListCompareStrings as a guideline for implementing your own:

function StringListCompareStrings(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result := List.CompareStrings(List.FList^[Index1].FString,
                                List.FList^[Index2].FString);
end;

So, by default TStringList.Sort defers to TList.CompareStrings:

function TStringList.CompareStrings(const S1, S2: string): Integer;
begin
  if CaseSensitive then
    Result := AnsiCompareStr(S1, S2)
  else
    Result := AnsiCompareText(S1, S2);
end;

Which then use the under lying Windows API function CompareString with the default user locale LOCALE_USER_DEFAULT:

function AnsiCompareStr(const S1, S2: string): Integer;
begin
  Result := CompareString(LOCALE_USER_DEFAULT, 0, PChar(S1), Length(S1),
    PChar(S2), Length(S2)) - 2;
end;

function AnsiCompareText(const S1, S2: string): Integer;
begin
  Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, PChar(S1),
    Length(S1), PChar(S2), Length(S2)) - 2;
end;

Finally the Compare function you need. Again the limitations:

  • Case Sensitive
  • Not using any locale
  • Just compare the ordinal value of the characters of the strings

This is the code:

function StringListCompareStringsByOrdinalCharacterValue(List: TStringList; Index1, Index2: Integer): Integer;
var
  First: string;
  Second: string;
begin
  First := List[Index1];
  Second := List[Index2];
  if List.CaseSensitive then
    Result := CompareStr(First, Second)
  else
    Result := CompareText(First, Second);
end;

Delphi ain’t closed, quite the opposite: often it is a really flexible architecture.
It is often just a bit of digging to see where you can hook into the that flexibility.

–jeroen

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

 
%d bloggers like this: