Utility for converting curl commands to code
For my link archive: [WayBack] Convert cURL command syntax to Python requests, Node.js code
–jeroen
Posted by jpluimers on 2019/07/26
Utility for converting curl commands to code
For my link archive: [WayBack] Convert cURL command syntax to Python requests, Node.js code
–jeroen
Posted in *nix, *nix-tools, cURL, Development, JavaScript/ECMAScript, Node.js, Power User, Python, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/26
–jeroen
via: [WayBack] Interesting: Anypaste – Share And Upload Files To Compatible Hosting Sites Automatically… – DoorToDoorGeek “Stephen McLaughlin” – Google+
Posted in *nix, *nix-tools, bash, cURL, Power User | Leave a Comment »
Posted by jpluimers on 2019/07/25
Need to check on this compiler error that you can solve by moving the generic class TExceptionThread<T> from the implementation section of a unit to the interface section.
[dcc32 Error] Test.ExceptionLogging.pas(246): E2506 Method of parameterized type declared in interface section must not use local symbol 'TExceptionThread`1'
My gut feeling is that that this either has to do with RTTI generation, or is a limitation of the compiler.
I need to trim that one done since it does not match any of these:
program which does not even distinguish interface and implementation.–jeroen
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/25
A great video on Intellectual Property for Engineers presented during [WayBack] PyGotham 2017.
Via [WayBack] Very interesting topic, but rushed through too quickly. Hope this guy gets a 60 minute slot next time… – ThisIsWhyICode – Google+
–jeroen
Posted in Development, Licensing, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/25
I love the solution with piped Join-Path constructs answered by David Keaveny in [WayBack] powershell – How do I use join-path to combine more than two strings into a file path? – Stack Overflow:
Since Join-Path can be piped its path value, you can pipe multiple Join-Path statements together:
Join-Path "C:" -ChildPath "Windows" | Join-Path -ChildPath "system32" | Join-Path -ChildPath "drivers"
Of course you could replace the built-in [WayBack] Join-Path by using using the .NET Framework [WayBack] Path.Combine Method (System.IO), but then you loose code completion.
If you do like that, here is how:
[System.IO.Path]::Combine("C:", "Windows", "system32", "drivers")
–jeroen
Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/24
A while ago, I got a question on code metrics, so here some links for my reading list:
Delphi related:
--jeroen
Posted in Development, Profiling-Performance-Measurement, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/24
Blast from the past: [WayBack] delphi – Why variables are declared as TStrings and created as TStringList? – Stack Overflow
Q
Why variables are declared as
TStringsand created asTStringList?A
Because that way you could put another
TStringsdescendant in theSLvariable (I’d probably call thatStrings, notSL).In your case, that is moot, since the logic around
SLcontains the creation of aTStringListand no external assignment or parameter parsing.But if you ever split the logic away from the assignment, then you could benefit from using any
TStringsdescendant.For instance, a
TMemoy.Lines,TListBox.Items,TComboBox.Items, etc.
From the outside it looks like they areTStrings, but internally they do not use aTStringListbut their own descendant.A few examples of classes that descend from
TStrings:source\DUnit\Contrib\DUnitWizard\Source\DelphiExperts\Common\XP_OTAEditorUtils.pas: TXPEditorStrings = class(TStrings) source\fmx\FMX.ListBox.pas: TListBoxStrings = class(TStrings) source\fmx\FMX.Memo.pas: TMemoLines = class(TStrings) source\rtl\common\System.Classes.pas: TStringList = class(TStrings) source\vcl\Vcl.ComCtrls.pas: TTabStrings = class(TStrings) TTreeStrings = class(TStrings) TRichEditStrings = class(TStrings) source\vcl\Vcl.ExtCtrls.pas: TPageAccess = class(TStrings) THeaderStrings = class(TStrings) source\vcl\Vcl.Grids.pas: TStringGridStrings = class(TStrings) TStringSparseList = class(TStrings) source\vcl\Vcl.Outline.pas: TOutlineStrings = class(TStrings) source\vcl\Vcl.StdCtrls.pas: TCustomComboBoxStrings = class(TStrings) TMemoStrings = class(TStrings) TListBoxStrings = class(TStrings) source\vcl\Vcl.TabNotBk.pas: TTabPageAccess = class(TStrings)
–jeroen
Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | 1 Comment »
Posted by jpluimers on 2019/07/24
This is my default PowerShell script header from now on:
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$PSDefaultParameterValues['*:ErrorAction']='Stop'
This might sound like overkill, but it solves these problems:
Set-StrictMode -Version Latest will warn on uninitialised variables and other code risks; see for instance [WayBack] Enforce Better Script Practices by Using Set-StrictMode – Hey, Scripting Guy! Blog and [WayBack] Set-StrictMode$ErrorActionPreference = 'Stop' will raise exceptions when errors occur under almost all circumstances to you do not have to add -ErrorAction Stop in CmdLets; see for instance [WayBack] powershell – Why does the exception not get me in the catch block? – Stack Overflow$PSDefaultParameterValues['*:ErrorAction']='Stop'works around CmdLets that ignore $ErrorActionPreference = 'Stop'; see for instance [WayBack] windows – How to stop a PowerShell script on the first error? – Stack Overflow and [WayBack] error handling – PowerShell – Setting $ErrorActionPreference for the entire script – Stack OverflowThe above helped me tremendously with for instance [WayBack] powershell – Why does the exception not get me in the catch block? – Stack Overflow:
I’m trying to interrogate some service information. Sometimes the installer of the application fails to correctly install, so the registry does not contain a service entry. I want to find out which installer steps did get executed correctly, even on systems that do not have proper logging in the installer.
If
MyServicedoes not exist, the script below does not go to thecatchblock even though the exception handling documentation suggests a barecatchshould be enough:try { $path = 'hklm:\SYSTEM\CurrentControlSet\services\MyService' $key = Get-Item $path $namevalues = $key | Select-Object -ExpandProperty Property | ForEach-Object { [PSCustomObject] @{ Name = $_; Value = $key.GetValue($_) } } $namevalues | Format-Table } catch { $ProgramFilesX86 = [System.Environment]::GetFolderPath("ProgramFilesX86"); $ProgramFiles = [System.Environment]::GetFolderPath("ProgramFiles"); Write-Host $ProgramFilesX86 Write-Host $ProgramFiles }Why is that and how should I force it to end up in the
catch?This is what PowerShell outputs:
Get-Item : Cannot find path 'HKLM:\SYSTEM\CurrentControlSet\services\MyService' because it does not exist. At C:\Users\Developer\...\GetMyServiceInfo.ps1:17 char:12 + $key = Get-Item $path + ~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (HKLM:\SYSTEM\Cu...vices\MyService:String) [Get-Item], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
For which I edited the answer to become this:
Force the error to be terminating:
$key = Get-Item $path -ErrorAction StopThat way it will throw and catch will get it.
Explanation and links to the official Microsoft documentation:
-ErrorActionis a Common Parameter that can be applied to any PowerShell command- The default value for
-ErrorActionisContinuewhich prevented the exception to be thrown in the first place.- You can configure a global
-ErrorActionsetting using the Preference Variable named$ErrorActionPreferenceto override this default value.
What is missing there is the link to the $PSDefaultParameterValues documentation at [WayBack] about_Parameters_Default_Values | Microsoft Docs
–jeroen
Posted in CommandLine, Development, PowerShell, PowerShell, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/23
A while back, I posted the “profiling” CommitStrip on[WayBack] Profiling – Jeroen Wiert Pluimers – Google+. Boy how did I not know that within a week, I bumped into a “laptop fan profiling” artefact.
A coworker noticed, that when starting a thread based equivalent of [WayBack] TTimer Class (which cannot be used in services as it depends on the VCL), then sometimes the laptop fans would spin up.
What basically happened was that for certain combinations of Enabled and Interval the Execute would loop burning 100% of one CPU core.
With 3 or more – sometimes 2 – of these threads active on a 4+4 core (4 are hyper-threaded), the processor fan would start to spin like madness.
Finding the solution was somewhat easy too:


Focussing on one thread, allowed a close inspection of the loop, quickly finding the actual cause and repairing it.
A similar and better class is at [WayBack] multithreading – TTimerThread – Threaded timer class – Code Review Stack Exchange, based on [WayBack] timer – Using VCL TTimer in Delphi console application – Stack Overflow.
Posted in Conference Topics, Conferences, Debugging, Delphi, Development, Event, Fun, Multi-Threading / Concurrency, Profiling-Performance-Measurement, Software Development | Leave a Comment »
Posted by jpluimers on 2019/07/23
Blast from the past, but still relevant: [WayBack] Namespaces in Delphi – Stack Overflow:
Q
Are there any practical benefits in using long unit file names like MyLib.MyUtils.pas or it is just a kind of unit name prefix?
A
Namespaces, like all identifiers, are meant to organize.
So using them, only benefits if your project gets organized in a better way. This is highly subjective matter (there have been ‘wars’ on even the most simple naming conventions!), so impossible to really answer.
[WayBack] Here is some documentation on how namespaces work in Delphi.
Note that ‘true’ namespaces (where more than one generic DLL can contribute to the same namespace; this is how namespaces function in the .NET world) are not possible in Delphi: you could go the BPL way, but that is not the same as a ‘generic DLL’. This is not a limitation of Delphi itself, but the way that native DLLs in Windows ‘work’.
–jeroen
Posted in Delphi, Development, Software Development | Leave a Comment »