Skip to content

Instantly share code, notes, and snippets.

View jpluimers's full-sized avatar

Jeroen Wiert Pluimers jpluimers

  • wiert.me
  • Amsterdam, The Netherlands
View GitHub Profile
@jpluimers
jpluimers / AppendWithRetry.pas
Created March 10, 2014 15:14
Circumvent I/O error 32 in Delphi at least for a while (in case for instance two threads want to log to the same log file at almost the same time)
//1 do not use 0=aSleepMillisecondsBetweenRetries as Sleep doesn't work predictably then: http://blogs.msdn.com/b/oldnewthing/archive/2005/10/04/476847.aspx
function AppendWithRetry(const aTextFile: TextFile; const aRetryCount: Integer = 10; const aSleepMillisecondsBetweenRetries: Integer = 1): Boolean;
var
lCount: Integer;
lIOResult: Integer;
begin
Result := False;
{$IFOPT I+}
{$DEFINE AppendWithRetry_IPlus}
{$I-}
@jpluimers
jpluimers / fnStripCharacters.sql
Created March 11, 2014 10:44
SQL Server function fnStripCharacters
CREATE FUNCTION fnStripCharacters
(
@String NVARCHAR(MAX),
@MatchExpression VARCHAR(255)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
SET @MatchExpression = '%['+@MatchExpression+']%'
@jpluimers
jpluimers / fnBarePhoneNumber.sql
Created March 11, 2014 10:45
SQL Server fnBarePhoneNumber function
create function fnBarePhoneNumber(@Value varchar(1000))
returns varChar(1000)
as
begin
select @Value = dbo.fnStripCharacters(@Value, '^\+0-9')
return @Value
end
-- http://en.wikipedia.org/wiki/E.164
-- http://en.wikipedia.org/wiki/E.123
;
@jpluimers
jpluimers / MainFormUnit.pas
Created March 21, 2014 10:15
When handling `Application.OnException` add the `ExceptAddr` to in Delphi the menu `Search` -> `Go to address` has a chance of working, and the `ClassName` so you know what happened.
procedure TMainForm.Application_OnException(Sender: TObject; E: Exception);
var
lMessage: String;
begin
lMessage := E.Message;
{$IFDEF DEBUG}
lMessage := Format('%s at $%p: %s', [E.ClassName, ExceptAddr, lMessage]);
{$ENDIF DEBUG}
BringToFront();
MessageDlg(lMessage, mtError, [mbOK], 0);
@jpluimers
jpluimers / WinSCP-error.txt
Created March 22, 2014 21:34
WinSCP installer throwing error: The NTVDM CPU has encountered an illegal instruction. CS:0551 IP:0387 OP:63 64 6e 37 37 Choose 'Close' to terminate the application.
---------------------------
16 bit MS-DOS Subsystem
---------------------------
C:\WINDOWS\system32\cmd.exe - winscp.net\download\winscp552setup.exe
The NTVDM CPU has encountered an illegal instruction.
CS:0551 IP:0387 OP:63 64 6e 37 37 Choose 'Close' to terminate the application.
---------------------------
Close Ignore
---------------------------
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.71.1 192.168.71.28 10
0.0.0.0 0.0.0.0 192.168.171.1 192.168.171.140 10
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.171.1 192.168.171.140 5
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.71.1 192.168.71.28 10
0.0.0.0 0.0.0.0 192.168.171.1 192.168.171.140 5
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.71.1 192.168.71.28 10
0.0.0.0 0.0.0.0 192.168.171.1 192.168.171.140 5
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 192.168.171.1 5
0.0.0.0 0.0.0.0 192.168.71.1 10
C:\temp>curl -O http://winscp.net/download/winscp552setup.exe
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0