[yoy - Why-O-Why]yoy - “Why-O-Why”

» frame | home browse filter search | refresh | log on

  printed donderdag 20 juni 2013 13:08:19 from www.yoy.be

Building query...

filter...

user: StijnSanders commented on: 20/06/2013 0:38:20 md5.pas

update! there appears to be an issue with UTF8String constants in Delphi XE

user: StijnSanders commented on: 17/04/2013 23:14:43 DirFind

verion 2.0.3.333
- Multi-line matches show first line when double-click matching file

"database locked" errors with SQLITE_CONFIG_SERIALIZED

I've been impressed by sqlite3 ever since I get to know about it. It's open source, and even more it's really put in the public domain completely avoiding the licensing headache. I haven't read the source in great detail, but as I understand it it's all in a single big file! Even how it works internally is impressive.

Since I didn't like the options available, I created my own very thin wrapper for sqlite3.dll without much trouble. Only in this one multi-threaded application, I've run into an occasional "database locked" error, so I had to search documentation and source for what I can do about it.

Working with other database solutions, I've had the common sense of using a database connection for each thread, so each could work with the database undisturbed by eachother. As it turns out this is not required with sqlite3! As stated with SQLITE_CONFIG_SERIALIZED, which is the default setting, you're better off using a single connection over all threads. Indeed in my case it solved the "database locked" errors.

location: Application Development > Data Storage > SQLite
created: 23/03/2013 22:36:26 « modified: 23/03/2013 22:36:26 weight: 0
tokens: delphi

How to create a shell extension context menu.

I've put it up here, but since it's a pretty good boiler plate code, I'll put it up here as well. Include a unit like this one into an ActiveX library. I especially had a though time to get the values right that are based on idCmdFirst and get sent back when a menu item is invoked. Something that gives pretty strange results if you don't get it right.

unit demoContextMenu;

interface

uses
  Windows, Classes, ActiveX, ComObj, ShlObj;

type
  PItemIDList=LPCITEMIDLIST;

  { TContextMenu }
  TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
  private
	Files:TStringList;
  protected
	{ IShellExtInit }
	function IShellExtInit.Initialize = SEIInitialize;
	function SEIInitialize(pidlFolder: PItemIDList; lpdobj: IDataObject;
	  hKeyProgID: HKEY): HResult; stdcall;
	{ IContextMenu }
	function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,
	  uFlags: UINT): HResult; stdcall;
	function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;
	function GetCommandString(idCmd: UINT_Ptr; uType: UINT; pwReserved: PUINT;
	  pszName: LPSTR; cchMax: UINT): HResult; stdcall;
  public
	procedure Initialize; override;
	destructor Destroy; override;
  end;

const
  Class_ContextMenu: TGUID = '{put a new GUID here by pressing Ctrl+Shift+G}';

implementation

uses ComServ, SysUtils, Registry;

procedure TContextMenu.Initialize;
begin
  inherited;
  Files:=TStringList.Create;
end;

destructor TContextMenu.Destroy;
begin
  Files.Free;
  inherited;
end;

function TContextMenu.SEIInitialize(pidlFolder: PItemIDList;
  lpdobj: IDataObject; hKeyProgID: HKEY): HResult; stdcall;
var
  StgMedium: TStgMedium;
  FormatEtc: TFormatEtc;
  i,c:integer;
  s:string;
begin
  if lpdobj=nil then Result:=E_INVALIDARG else
   begin
	FormatEtc.cfFormat:=CF_HDROP;
	FormatEtc.ptd:=nil;
	FormatEtc.dwAspect:=DVASPECT_CONTENT;
	FormatEtc.lindex:=-1;
	FormatEtc.tymed:=TYMED_HGLOBAL;

	Result:=lpdobj.GetData(FormatEtc,StgMedium);
	if not(Failed(Result)) then
	 begin
	  c:=DragQueryFile(StgMedium.hGlobal,$FFFFFFFF,nil,0);
	  for i:=0 to c-1 do
	   begin
		SetLength(s,1024);
		SetLength(s,DragQueryFile(StgMedium.hGlobal,i,PChar(s),1024));
		Files.Add(s);
	   end;
	  ReleaseStgMedium(StgMedium);
	  Result:=NOERROR;
	 end;
   end;
end;

function TContextMenu.QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst,
  idCmdLast, uFlags: UINT): HResult; stdcall;
var
  h:HMENU;
  i:integer;
begin
  i:=1;
  h:=CreatePopupMenu;
  AppendMenu(h,MF_STRING,idCmdFirst+i,'Menu item one');      inc(i);
  AppendMenu(h,MF_STRING,idCmdFirst+i,'Menu item two');      inc(i);
  AppendMenu(h,MF_STRING,idCmdFirst+i,'Menu item three');    inc(i);
  InsertMenu(Menu,indexMenu,
	MF_BYPOSITION or MF_POPUP or MF_STRING,h,'DemoContextMenu');
  Result:=i;
end;

function TContextMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult;
  stdcall;
begin
  Result := E_FAIL;
  //not called by application
  if HiWord(Integer(lpici.lpVerb))=0 then
	begin
	  Result := NOERROR;
	  case LoWord(Integer(lpici.lpVerb)) of
		1:;//perform action one (use data in Files:TStringList)
		2:;//perform action two
		3:;//perform action three
		else Result := E_INVALIDARG;
	  end;
	end;
end;

function TContextMenu.GetCommandString(idCmd: UINT_Ptr; uType: UINT;
  pwReserved: PUINT; pszName: LPSTR; cchMax: UINT): HResult; stdcall;
begin
  if idCmd=0 then
   begin
	if (uType=GCS_HELPTEXTW) then
	  StrCopy(pszName,'Perform one of several functions on files');
	Result:=NOERROR;
   end
  else
	Result:=E_INVALIDARG;
end;

type
  TContextMenuFactory = class(TComObjectFactory)
  public
	procedure UpdateRegistry(Register: Boolean); override;
  end;

procedure TContextMenuFactory.UpdateRegistry(Register: Boolean);
var
  ClassID:string;
  r:TRegistry;
begin
  if Register then
   begin
	inherited UpdateRegistry(Register);

	ClassID := GUIDToString(Class_ContextMenu);
	CreateRegKey('*\shellex', '', '');
	CreateRegKey('*\shellex\ContextMenuHandlers', '', '');
	CreateRegKey('*\shellex\ContextMenuHandlers\DemoContextMenu', '', ClassID);

	CreateRegKey('Folder\shellex', '', '');
	CreateRegKey('Folder\shellex\ContextMenuHandlers', '', '');
	CreateRegKey('Folder\shellex\ContextMenuHandlers\DemoContextMenu', '', ClassID);

	if Win32Platform=VER_PLATFORM_WIN32_NT then
	 begin
	  r:=TRegistry.Create;
	  try
		r.RootKey:=HKEY_LOCAL_MACHINE;
		r.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions',True);
		r.OpenKey('Approved',True);
		r.WriteString(ClassID,'DemoContextMenu Shell Extension');
	  finally
		r.Free;
	  end;
	 end;

   end
  else
   begin
	DeleteRegKey('Folder\shellex\ContextMenuHandlers\DemoContextMenu');
	DeleteRegKey('*\shellex\ContextMenuHandlers\DemoContextMenu');

	inherited UpdateRegistry(Register);
   end;
end;

initialization
  TContextMenuFactory.Create(ComServer, TContextMenu, Class_ContextMenu,
	'', 'DemoContextMenu Shell Extension', ciMultiInstance, tmApartment);
end.

location: Application Development > Programming Languages > Object Pascal > Delphi > ActiveX / COM objects
created: 12/11/2012 16:41:31 « modified: 12/11/2012 16:42:58 weight: 0
tokens: delphi

user: StijnSanders commented on: 18/10/2012 10:05:40 Create a shortcut from code.

See also here for more information on the IShellInfo interface:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb774950(v=vs.85).aspx

user: anonymous user commented on: 12/10/2012 15:06:08 ExecuteReader requires the command to have a transaction...

Helped me. Thanks.

Ajay

dotnetfor.com

E-mail over HTTP

It might be a stupid idea, but why has no-one ever thought of mapping SMTP/POP3/IMAP onto HTTP. (Or has someone?)
I know, there's a lot on the blogosphere about e-mail and it being broken in all kinds of ways, or not at all, but I don't want to touch upon that.

What I think it really is about is a clean straight-forward way of sending asynchronous messages to eachother. SMTP was created specifically for that. But it is getting old. Really old. Even so, it is based on a number of even older protocols (RFC822, anyone?). It's only normal that protocols cooperate or are based on eachother, but some are clearly established and are a really good fit for most if not all situations and environments, and some are established but happen to be the least worse solution that is available, just waiting to get replaced by something better, as soon as the folk could agree on the replacement.

HTTP was designed to transport hypertext. At first from a server to a client, but basically in any direction. And thanks to MIME, anything really. And face it, isn't almost all of our e-mail in hypertext nowadays? So HTTP and SMTP may have a lot in common, except HTTP has seen a lot more evolution as far as I know, both in design and in support by hardware and software.

How would it work? Just like an MX-record, something else (HTMX-record?) could point at a URL for the domain of an e-mail address. (And I mean full URL: http/https, (sub)domain, path, etc...) So the sender starts a request:

POST /incomingmail HTTP/1.1
Host: example.com
From: "John Doe" <john.doe@acme.us>
To: "James Day" <james.day@example.com>
Subject: Meeting invitation about some project
Date: Sat, 29 Sep 2012 15:38:11 +0000
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: deflate
Content-Length: 1234

At this point the server can respond with '100 Continue' or a suitable error code when spam detection or a blacklist does its job.

Same for POP3/IMAP: much like this REST thing that's getting so much attention, HTTP verbs GET and DELETE should be all you need to sift through the wad of timewasters people send you daily.

But, off course, it's just an idea. I've got lots of interesting stuff to work on before I'll put time in this probably, but if you think it's a good idea, let me know.

location: Opinions > Computer related > Internet
created: 30/09/2012 1:35:03 « modified: 30/09/2012 1:35:03 weight: 0
tokens: internet

"Even snel een login-procedure maken"...

Ik dacht 'ik bouw even snel een login-procedure op die website', niets van. Laat dat 'even snel' maar weg, en 'login-procedure' is volgens de regels van de kunst ook niet meer wat het was als je het vergelijkt met begin de jaren 90. Laat ik dan even snel even een exhaustieve lijst proberen op te stellen: (Als ik iets vergeet geef me een seintje!)

location: www.yoy.be > users > StijnSanders > IRL
created: 15/09/2012 16:32:15 « modified: 29/09/2012 11:29:56 weight: 0
tokens: internet coding

user: StijnSanders commented on: 2/09/2012 23:10:01 How to recreate 70's 'programming conditions'

 Came across this golden oldie: The UNIX-Haters' handbook

user: StijnSanders commented on: 10/05/2012 21:06:57 DirFind

v2.0.2.300
- issue expanding closest line above for lower indentation-levels over blank lines
- shell context menu on files/folders items
- command line parameters support:
    DirFind [<options>] <search path> [<filter filenames> [<exclude filenames> [<search pattern>]]]
    options:
      /i  ignore case
      /m  multi line
      /a  count all matches
      (/-... to disable, default settings are loaded from previous session)

Force Application.Run to skip the message loop (from within OnCreate event handler).

Warning: this is a very specific hack an may not apply to other situations.

For a number of projects that check for an update of the program executable on the central file server, from within the main form's OnCreate event handler, I was searching for a way to 'skip' Application.Run; when an update is found. I was using "raise EAbort.Create('Auto-update available.');" already to skip the remainder of the OnCreate event handler, but back in the project source (.dpr), Application.Run would start and perform the message loop. I used PostQuitMessage before, but that doesn't seem to always work, a better way would be to skip the message loop altogether.

I used "if SelfUpdateAvailable then Application.Run;" for some time, but in any new project that would use the auto-update mechanism, you would have to remember to put it in, or the support-calls after the first update for the program would remind you, or have you wondering first what's wrong with the auto-update this time. Anyway, it's better to leave the .dpr just the way Delphi hands it to you since it will modify it later when you add forms or data modules.

So I figured out I could disarm Application.Run by calling this from the 'start auto update' code:

  Application.ControlDestroyed(Application.MainForm);

This causes Application.MainForm to be unassigned, and Application.Run to skip starting the message loop, mission accomplished.

location: Application Development > Programming Languages > Object Pascal > Delphi
created: 10/05/2012 13:13:32 « modified: 10/05/2012 13:14:52 weight: 0
tokens: delphi

user: anonymous user commented on: 24/04/2012 1:15:26 ExecuteReader requires the command to have a transaction...

 great info....thank you so much

How to recreate 70's 'programming conditions'

When getting my batchelor CS, we were the last batch to get COBOL. (They replaced it with Java the next year. And Pascal with C++ as well, by the way.) It feels like I was the only one that understood the code width was limited to 72 characters and had to start at position 8, just to be sure it would fit on Hollerith cards. We had all the modern editors and compilers of the age, so I never worked with cards and tape.

I searched around a bit back then, and remember reading about how hard programming was back in the 70's (pre-dating my existance). COBOL was there just to make the process somewhat easier, and serve as a stepping-stone to a working result so you wouldn't have to do it all in raw processor-code. You still had to 'write' the program, prepare it as a stack of cards, get over the the card-reading office in time for when you're on the schedule (don't drop the cards!), wait for mainframe time to get around to having the compiler run on your code, and just hope and pray you finally would get something else back than a print-out of syntax errors. If the mail-boy didn't misfile it.

I remember even earlier on errors would arise because cards would get out of order (like I said, don't drop the stack, which regretfully unfortunately did happen), or even worse no compiler-errors arise and it only later gets apparent when the program behaved unexpectedly. (Did they even do debugging back then?) This was easily (...) solved by introducing code-line-numbers and have the (pre-)compiler order the lines from the input-file by number.

So I was wondering, in this day and age of virtual reality, advanced computing and online gamified educational experiences, would it be interesting to have something so us youngsters could appreciate how it was back then, by trying to recreate how it was to code. I'm not so much thinking about an emulated PDP-11 with a hall of tape stations. I'm more thinking of cubicles, internal mails, stacks of cards, print-outs, fighting for a few minutes of terminal access...

It's just an idea though. I'm afraid I don't have the time and skill to create a game like this.

location: www.yoy.be > users > StijnSanders > nice idea's but no time to spend on them
created: 16/04/2012 11:17:11 « modified: 16/04/2012 11:17:11 weight: 0
tokens: coding

user: StijnSanders commented on: 12/04/2012 18:09:43 DirFind

v2.0.1.290
- bug reading UTF16/UCS2 files
- issue updating display on abort

user: StijnSanders commented on: 5/04/2012 21:22:21 DirFind
token: delphi

v2.0.0.288
I've switched back to Delphi. The .Net version had trouble running more than three threads, and behaved strangly when exceptions occur. The option to use three regex'es in one run is gone, but there's an option now to use Execute instead of Test showing both the number of files that match, and the exact total number of matches in these files.
Also new is that when you double-click a matching line (double-click a file-node to get these), you not only get the five preceding and succeding lines, you also get the lowest preceding line of each lower level of indentation. It's hard to explain, but in most languages you should get the lines that starts the scope the line is in: namespace, function, method, loop or condition branch.

user: StijnSanders commented on: 30/03/2012 21:57:46 md5.pas
token: (friendly-url)

(md5)(md5/)(sha1)(sha1/)

user: StijnSanders commented on: 16/02/2012 20:28:59 md5.pas

 Code in a slightly modified form also used here: https://github.com/stijnsanders/TMongoWire/blob/master/mongoAuth.pas

user: StijnSanders commented on: 16/02/2012 20:27:10 md5.pas
token: (friendly-url)

(md5)(md5/)

md5.pas

This is odd, it looks like there isn't an open source md5.pas unit. And by open source I mean under a permissive license or without copyright or licensing. So I set out to write my own and share it here. I based it on the original RFC, and even more the description than the reference implementation, because it uses a few of those C tricks I don't like. I hope it's performant enough, in case you're demanding performance of it. I've done some testing myself, but if you detect any kind of issue, please let me know.

md5.pas with MD5Hash for strings, sometimes used with passwords

md5Stream.pas with MD5HashFromStream which takes any kind of stream (TFileStream, TMemoryStream...), and optionally a preset number of bytes to take from the stream (from the current position!).

Enjoy. 

Update: since MD5 and SHA1 are really similar, I've done the same for SHA1 and added sha1.pas and sha1Stream.pas.
Update 2: since I needed it for something else, I've added RIPEMD160 as well. And while I'l at it SHA256 as well

md5.zip (12KB)

location: freeware
created: 16/02/2012 20:26:41 « modified: 14/03/2013 21:24:12 weight: 0
tokens: delphi (friendly-url)

COM/ActiveX objects and Windows Vista and newer

Applications that provide one or more ActiveX/COM automation objects, created with older versions of Delphi, running without administrative privileges, throw an EOleSysError when strarting up (typically from within the Application.Initialize;). This is because the application will try to register its type library and class registrations when it starts. Add this unit to the project to silent this error at run-time:

unit comFixW6;

interface

implementation

uses Windows, SysUtils, ComObj;

var
  SaveInitProc:pointer=nil;

procedure FixComInitProc;
begin
  try
    if SaveInitProc<>nil then TProcedure(SaveInitProc);
  except
    on e:EOleSysError do if e.ErrorCode<>TYPE_E_REGISTRYACCESS then raise;
  end;
end;

initialization
  SaveInitProc:=InitProc;
  InitProc:=@FixComInitProc;

end.

location: Application Development > Programming Languages > Object Pascal > Delphi > ActiveX / COM objects
created: 2/02/2012 21:55:51 « modified: 2/02/2012 22:01:41 weight: 0
tokens: delphi

user: StijnSanders commented on: 2/02/2012 21:21:18 >=, <= operators

If I look at this page, the query you're looking for would look like this in JSON notation for example 'x>10':

{x:{$gt:10}}

in Delphi notation this could be written as:

BSON(['x',BSON(['$gt',10])])

or in the condensed form (where one BSON call does the embedded levels):

BSON([x,'[','$gt',10,']'])

>=, <= operators

Very nice, I'm trying it.

Is there a way to use >=. <= operators for quering objects? I know I should use &gt, but, how to use it with TMongoWireQuery?

location: freeware > TMongoWire
created: 2/02/2012 14:02:01 « modified: 2/02/2012 21:31:28 weight: -100
tokens: coding

user: anonymous user commented on: 31/01/2012 15:56:53 CreateProcessAsUser/CreateProcessWithLogon

Merci,

hope this works to run a third party application (without gui) from within a service :)

 

Printer.Canvas is not threadsafe!

What a strange discovery I made today. I was hunting down a weird exception we noticed in the logs of the live system.

It turns out that a 'global' callback procedure is being called when you use Printer.Canvas (Printer.Canvas.StretchDraw in my case) by the GDI subsystem. The default AbortProc in Printers.pas calls Application.ProcessMessages, which was causing trouble in my case.

There's a quick workaround:

function MyAbortProc(Prn: HDC; Error: Integer): Bool; stdcall;
begin
  Result := not FPrinter.Aborted;
end;

And then right after Printer.BeginDoc; call SetAbortProc(Printer.Canvas.Handle,MyAbortProc);

location: Application Development > Programming Languages > Object Pascal > Delphi
created: 26/01/2012 19:46:39 « modified: 26/01/2012 19:46:39 weight: -200
tokens: delphi

Power user trick: restart the Printer Spooler service.

Sometimes, there's still one or more jobs in the printer queue, none are deleting or cancelled or in an error state, the printer is powered on, connected, doesn't report any error also, but doesn't start printing. It's a strange situation, but just happens to happen from time to time. This power user trick comes in handy: (No guarantees: this may still not work if something else actually is causing the disruption)

This breathes new live into the print job sub-system and may sometimes cause the 'hanging' jobs to resume printing.

location: www.yoy.be > users > StijnSanders > IRL
created: 13/09/2011 0:04:51 « modified: 13/09/2011 0:04:51 weight: 0
tokens: computers

Safari Mobile: no focus from load or timed events

On one website, I'm using jQuery to load a form into a cell of a table to edit a value on that row, and set focus to the edit field, so the user can edit or overwrite the value rightaway.

On an iPad (not sure which version it was on), the keyboard doesn't show, and the field doesn't get the focus. It takes another click onto the field to give it focus and get the keyboard to show.

Sleuthing around, it appears that this is by design! Because showing the keyboard is slow and/or intrusive?! I disagree. I think this is a clever way of degrading the user experience of using an interactive website with Safari Mobile in such a way it would get interesting to create a specific iPhone/iPad app.

Though other sources tell me this is a bug and could get fixed in future versions...

location: Application Development > Platforms > iOS
created: 30/07/2011 2:01:14 « modified: 30/07/2011 2:01:14 weight: 0
tokens: coding

SQLite, a foreign key and its referential integrity...

Hmm, I guess this will take a lot more getting used to than I thought... Consider this code:

create table tbl1 (
id integer primary key autoincrement,
name varchar(50) not null
);
create table tbl2 (
id integer primary key autoincrement,
tbl1_id int not null,
name varchar(50) not null,
constraint FK_tbl1_tbl2 foreign key (tbl1_id) references tbl1 (id)
);
insert into tbl1 (id,name) values (1,'test1');
insert into tbl2 (id,tbl1_id,name) values (2,1,'test2');
insert into tbl2 (id,tbl1_id,name) values (3,2,'test3');
update tbl1 set id=id+100;
select * from tbl1;
select * from tbl2;

This works on SQLite3 without errors! Not on the inserts, setting an autoincrement field, not on updating the id field(s) that are in use by a foreign key, which actually breaks referential integrity between the two tables! Or have I stumbled upon a fault/bug/incorrectness in SQLite3?

location: Application Development > Data Storage > SQLite
created: 2/04/2011 0:03:07 « modified: 2/04/2011 0:04:27 weight: 0
tokens: coding

bitcoin: digital currency of the people (be your own bank)

I've been asked if I accept donations for the freeware I make available over this website, but I don't. I don't have a legal entity to my name to accept any funds for work done, and frankly I don't even care for checking if and how I could get this in the clear with the tax services.

Today I read about http://www.bitcoin.org/ and this looks like exactly what I need. It's not that hard to set up, and the fact that no institute like a bank is envolved is really interesting. Even the 'funds' itself actually measures in 'mathematical solids in the digital world', so if I were to amass e certain amount of it, it would get financially interesting to check out these aforementioned tax issues (perhaps by an accountant...)

So, if anyone wants to wire me anything (even 0.01BTC just to check if it works) here's a bitcoin address:

1Q5omBMcpRQkx7WqPpHceM37ZBqpCgyrDB

location: spotted on the net > legal issues > financial
created: 23/03/2011 16:45:07 « modified: 23/03/2011 16:45:07 weight: 0
tokens: internet actueel beurs coding politiek weblog

user: StijnSanders commented on: 14/12/2010 15:24:20 TSQLite
token: (friendly-url)

(TSQLite)

TSQLite

An alternative SQLite3.dll wrapper

location: freeware
created: 14/12/2010 15:23:58 « modified: 14/12/2010 15:23:58 weight: 0
tokens: delphi (friendly-url)

user: StijnSanders commented on: 14/12/2010 15:23:21 TMongoWire
token: (friendly-url)

(TMongoWire)

TMongoWire

Delphi MongoDB Driver

A Delphi driver to access a mongoDB server.
It maps variables onto Delphi variables of type OleVariant, which resembles the loose typing of JavaScript a lot.
There are two main units and three main object to enable access to a mongo DB server:

bsonDoc.pas
  TBSONDocument = class(TInterfacedObject, IBSONDocument, IPersistStream)

  function BSON:IBSONDocument; overload;
  function BSON(x:array of OleVariant):IBSONDocument; overload;

mongoWire.pas
  TMongoWire=class(TObject)

  TMongoWireQuery=class(TBSONDocumentsEnumerator)

Additional tools

bsonUtils.pas
  function BsonToJson(Doc:IBSONDocument):WideString;
    Converts a BSON document into a JSON string.
  function JsonToBson(jsonData:WideString):IBSONDocument;
    Converts a JSON string into a BSON document.
  procedure JsonIntoBson(jsonData:WideString;doc:IBSONDocument); overload;
    Parses a JSON string and adds any keys to an existing BSON document, overwriting the value if a key already exists.
  procedure JsonIntoBson(jsonData:WideString;doc:IBSONDocument;var EndIndex:integer); overload;
    Parses only the first JSON object from a string into an existing BSON document, and returns the index into the string where the JSON object ends.
    Use this method to iterate over a list of JSON strings. (See also IBSONDocument.Clear)

location: freeware
created: 2/12/2010 10:05:35 « modified: 24/06/2012 21:39:02 weight: 0
tokens: delphi (friendly-url) references:      

user: StijnSanders commented on: 8/11/2010 21:58:23 How to set the thread display name for the thread list deb...

 See also http://nldelphi.com/Forum/showthread.php?t=36655

How to set the thread display name for the thread list debug window

This little trick appears to work in the Delphi debugger also! Use this code to set the debug display name for the current thread:

interface


function IsDebuggerPresent: BOOL; stdcall;

implementation


uses
Windows;


function
IsDebuggerPresent; external 'kernel32.dll';

procedure
SetThreadName(ThreadDisplayName:AnsiString);
var
  ThreadInfo:record
    dwType:LongWord;
    szName:PAnsiChar;
    dwThreadID:LongWord;
    dwFlags:LongWord;
  end;
begin
if IsDebuggerPresent then
begin
  ThreadInfo.dwType:=$1000;
  ThreadInfo.szName:=PAnsiChar(ThreadDisplayName);
  ThreadInfo.dwThreadID:=LongWord(-1);//calling thread
  ThreadInfo.dwFlags:=0;
  try
    RaiseException($406D1388,0,SizeOf(ThreadInfo) div SizeOf(LongWord),@ThreadInfo);
  except
    //
  end;
end;
end;

location: Application Development > Programming Languages > Object Pascal > Delphi > Debugging
created: 5/11/2010 0:25:47 « modified: 5/11/2010 0:45:47 weight: 0
tokens: delphi

Creating a virtual image of that old laptop

The last few days I've been looking up a lot of information on a specific topic, but haven't found all that I need in a single place, so here it goes. This is the story of (yet another) someone that had the great idea of 'cloning' a virtual image out of the old physical machine, to run as a virtual machine on the brand new machine, with a multiple of the capacity of the old machine.

If you don't care about the story, scroll to the bottom to see the quick guide through the steps to take.

The old, aging, deteriorating laptop is ready for retirement, it's got its power connector re-soldered twice already, two out of three (...) USB ports no longer respond, etc. But, all your data is on it. It's full of tools and software you use and you'd like to use. You're not looking forward to the awkward time ahead using two laptops, re-installing software and tools, moving data around, and optionally finding out you've lost all of those precious personal perferences, settings, profile data...

Virtualization is a buzzword nowadays among the happy few that pull the reins on the server farms, but it's pretty available for home users as well. So why not try to pull a virtual image off of the physical machine and see if it would run on the new machine?

Step 1: Pulling the image.

A straight-forward method for modular desktop machines was to put the old harddisk into another machine as secondary drive and pull an image from it. I'm moving between laptops and I don't feel like dismantling this one (any more)... So I need to pull an image of the currently running system, from the main harddisk partition, and write it over network, since this 20GB is nearly full.

(On a side note, I'm was quite happy this last months to discover cleanmgr http://support.microsoft.com/kb/253597 and especially the 'remove system restore points' option on the second tab! Hundreds or thousands of dead unused kilobytes just sitting there you can get rid of with a mouseclick.)

I found this great tool that does the trick: http://www.chrysocome.net/dd

dd if=\\?\Device\HardDisk0\Partition0 of=\\192.168.0.3\temp\oldlaptop.img bs=128k --progress

'Partition0' apparently is the address of the entire disk, underneath any partitioning or locks the system has on the filesystem. Oddly enough it's available to read from, so take care with running other programs while you're pulling the image. Any files written to while the diskdump is writing may end up corrupt.

I've tried a number of block sizes, ranging from 4k to 2M, but 128k is about a good size to keep both the harddisk and the network interface (100Mbps) busy enough so they won't have to wait on eachother too much. Less would make more read operations, and less data packets going out, more would read more at once, but the disk may forget what to do while the data is flushing down the twisted pair.

Start 2: Running the image.

Let's see. I've selected qemu www.qemu.org to run the image, it's light-weight, runs well (and closes well), but I hear good things about VMWare player also. http://www.vmware.com/products/player/

And it boots! It shows a Windows logo for a second... and throws a 'blue screen of death' with an error that states, among other things "STOP 0000007B", and loops into a reboot which repeats.

Thing is, the old machine had an Intel something in it's center, the new one has it of AMD build, could this be causing problems? From what I read on the web it does. But I've also read all kinds of trickery and tool-slinging to alter registry and core files, but they all boil down to disabling the erring drivers, while still keeping the system running enough to get to boot in a new virtual enclosure.

Start 3: Fixing them drivers.

So back to the old machine. I've tried several things, but what I finally did to get it running is checking every little thing in the device manager (with display of hidden devices swicthed on), which showed the brand's name in the description, and 'update' the drivers to the generic make of drivers, which seem to do the trick also. It may take a reboot or two, and some things may re-appear getting plugged to play again, but you just play them down again putting the generic label on it. (Update driver > no, not now > I wont to choose > don't search > select the plain vanilla one)

Then I took a new diskdump, and just to let this old bird fly again, I restarted in safe mode, and selected to restore a restore point from before I started this endeavor.

Start 4: Does it run now?

Does it run now? Looks like it does, the image is holding a system that wasn't shutdown properly (deuh), so it starts a scandisk before it boots, but that's only normal. Any file that was open at the time of the diskdump may get 'corrected', but I warned you. Then the system boots, telling you you need to activate. Just like you would when you replace your motherboard. (Which I kind of did.)

So, in short, this is what you need to do to convert a physical Windows installation into a virtual image:

location: www.yoy.be > users > StijnSanders > IRL
created: 28/10/2010 23:23:16 « modified: 28/10/2010 23:23:16 weight: 0
tokens: weblog computers

Waar heeft wuauctl.exe nu weer mijn ram voor nodig?

Ik vraag me meer en meer af wat wuauctl.exe nu weer zit te doen:


Houdt die er ergens een log bij want ik ga die eens moeten onderzoeken denk ik.
Dat de CPU niet omhoog gaat is omdat die zoveel werk heeft met het swappen!
GoogleUpdate.exe heeft ten minste de manieren om zo weinig mogelijk resources te gebruiken.

location: www.yoy.be > users > StijnSanders > IRL
created: 14/10/2010 18:55:49 « modified: 14/10/2010 18:55:49 weight: 0
tokens: computers

Programmeren met het middellangetermijngeheugen.

Ik heb net een raar idee. Zou het kunnen zijn dat ik programmeer met mijn middellangetermijngeheugen? (Wat een lang woord.) Dingen die je in je op neemt verwerk je in je kortetermijngeheugen, en als ze daar even blijven gaan ze over naar het middellangetermijngeheugen. Wat daar een tijdje zit maakt het langetermijn zo'n beetje zijn keuze in wat die gaat bijhouden. (Daarom lijkt het achteraf altijd alsof de tijd voorbij is gevlogen, maar da's een ander verhaal.)

Wat er veel gebeurt bij programma's schrijven is lezen! Lezen, lezen en lezen, en onderwijl onthouden wat er precies allemaal gebeurt in veel, zoniet alle mogelijke gevallen. Dat wordt soms wel eens een hele hoop, maar al die dingen lezen (en herlezen, en herlezen...) bouwt op in het kortetermijngeheugen, tot de hele structuur zo'n beetje kant en klaar in je hoofd in het middellangetermijngeheugen zit, en dan pas kan je verder met te veranderen aan die complexe structuur van logica. En je aanpassingen testen en zo.

Als je dat dan een paar dagen niet meer gebruikt, dan verdwijnt het. Bij mij toch. Als ik er dan een paar weken of maandan later nog eens op moet terug komen, dan komen de grote lijnen wel terug (ik vermoed uit het langetermijngeheugen), maar lang niet alles. Dus wordt het weer lezen en lezen...

t'Is natuurlijk maar een idee.

location: www.yoy.be > users > StijnSanders > IRL
created: 8/10/2010 16:12:15 « modified: 8/10/2010 16:12:15 weight: 0
tokens: coding weblog

user: StijnSanders commented on: 23/04/2010 23:54:33 DirFind

version 1.0.1.260
I finally got round to changing two things that were disturbing me about DirFind:

When searching a large structure of folders and sub-folders, I usually wanted to see the matching files in a certain sub-folder, but had to wait for the search running in the background to get to the directory I wanted to see. Now, when you expand the folder view, the background process is asked to move the folder you selected to the front of the queue. This feature will save me tuns of time. If larger files are being searched, this behaviour might not be apparent rightaway.

There was an issue using the replace feature on non-unicode text files. When re-writing the files, they got converted to UTF8. Now, if no unicode byte order marks are present, the file is re-written in the 'default' encoding, depending on your current regional settings. You may still get unexpected results on non-unicode files using another encoding than this default encoding.

Flash is dood, ander en beter

http://www.theregister.co.uk/2010/04/10/adobe_man_on_apple/

Kom, kom, kom. Ik kan ze heel goed begrijpen. Het is tijd voor een nieuw tijdperk, en dat merk je aan alle groten der aarde, niet alleen Apple en Google, maar zowat alle nieuwelingen: Facebook, Twitter, Youtube. Java en plugins in browsers allerhande zijn nodig geweest om vanop een soort gefragmenteerd platform weg te kunnen bij het grote publiek die met allerhande metaal en verbindingen van bemerkelijke kwaliteit zaten. We hebben er eigenlijk maar van kunnen uitgaan dat het bij de meeste een beetje werkte.

Maar de nieuwe wind die waait, blaast in twee richtingen. Misschien een beetje vreemd om te volgen voor de buitenstaander, maar in de onderste lagen gaat het naar de windrichting van de pure techniek. Schrijf code, maar heel weinig, en direct voor een processor. Er blijven er maar een paar soort meer over, en dan is het te doen om ze elk specifiek te bedienen (x86, ARM...). Er is dus geen nood meer aan tussenstapjes, logica die onderweg ergens rondslingert, zoals SQL of Java. Of Flash. Alleen het zuivere spul.

Vanboven stuurt de wind je naar een virtuele wereld. Of toch zo lijkt het, want er draaien gewoon nog altijd instructies op een rekeneenheid. Alleen is er net voorbij de grens van het uitdeinende universum van threads, processen en het OS, een laagje bij die geruisloos wappert tussen je huidige illusie van werkelijkheid en het hoopje metaal dat de kleur van de lichtpuntjes voor je ogen aanstuurt.

Het wordt dus aanpassen geblazen aan veel rekenkracht, veel geheugen, en veel mogelijkheden waar het allemaal kan zitten. In je broekzak, in een kantoorgebouw ergens, of allemaal tesamen.

Klinkt allemaal wel mooi. Maar toch is er iets dat niet goed onder het dak van mijn luchtkasteel lijkt te passen: JavaScript. (Die trouwens nog weinig met Java te maken heeft, zeg en schrijf maar JavaScript, mocht er een leek meeluisteren, maar lees ECMAScript.) Even leek het of het ook in de mist van de geschiedenis zou verdwijnen, maar dankzij XMLHttpRequest staat het nu vooraan om de hemel mee te kleuren. Het is naar verluid een drukkende kracht die het web naar nieuwe hoogten brengt. En blijkbaar niet alleen het web, als ik het zo bij Palm en Apple zie. En Mozilla.

Ik denk dat de grote verdienste is dat je in Javascript zo alles lekker vaag kan laten. Is het een object? Een functie? Doe maar iets. Je ziet wel of je er iets uit krijgt. Je browser is slim genoeg om zelf uit te zoeken wat in machine-instructies kan. Is het een string? Een stuk van de pagina? Misschien wel. Als niet iets anders het heeft vervangen met dezelfde naam en interface. Mash-ups allerhande schijnen al aan de horizon. We kunnen er virtueel nu al virtueel al ons virtueel werk mee doen. (Ik wist niet goed waar het woord 'virtueel' in te planten, dus laat ik ze alledrie staan, kies zelf maar.)

location: Opinions > Computer related > Development
created: 12/04/2010 21:38:46 « modified: 12/04/2010 21:42:29 weight: 0
tokens: actueel coding

Programming the Commodore 64

http://developers.slashdot.org/story/10/03/13/2316217/Programming-the-Commodore-64-the-Definitive-Guide

Jaja, toen kon je nog een OS zelf beginnen. Tegenwoordig word ik uitgelachen.

(Hoewel deze wel de moeite is: http://wiki.osdev.org/ )

location: spotted on the net > IT-related > development related
created: 14/03/2010 13:03:11 « modified: 14/03/2010 13:03:11 weight: 0
tokens: computers coding

Ad blocking hurts websites

http://arstechnica.com/business/news/2010/03/why-ad-blocking-is-devastating-to-the-sites-you-love.ars

Ik heb tot nu toe nog geen ad-blocker gebruikt. Ik vind het wel storend dat de ads de pagina eerst even overnemen voor je kan lezen wat je wou, maar ik slaag er blijkbaar wel in die websites te vermijden (hint).
Maar moest ik zelf een ad-blocker ooit maken dan zou het wel eens interessant kunnen zijn om ze alleen maar te proberen 'overplakken' met een wit venster of zo, dan komen de ads wel door, maar storen ze zo niet.

location: spotted on the net > IT-related > internet related
created: 6/03/2010 21:30:47 « modified: 6/03/2010 21:30:47 weight: 0
tokens: internet actueel

How to turn on automatic logon in Windows XP

Als ik deze nodig heb kan ik die natuurlijk nooit onthouden! Tijd om die hier toe te voegen dus:
Start+R (run) en dan: "control userpasswords2"

location: Application Development > Platforms > Microsoft Windows
created: 18/02/2010 8:28:18 « modified: 18/02/2010 8:28:18 weight: 0
tokens: computers werk

user: StijnSanders commented on: 9/02/2010 0:52:04 BarcodeStuff

v1.0.2.255
I've finally figured out the deal about Code-A/B/C in encoding Code128 barcodes. I've added code that auto-switches between digits-interleaving as soon as four or more digits follow eachother, and the checksum character.

Encryption Export Regulation

Ja miljaar wat een boterham:

This project DOES incorporate, access, call upon or otherwise use encryption. Posting of open source encryption is controlled under U.S. Export Control Classification Number "ECCN" 5D002 and must be simultaneously reported by email to the U.S. government. You are responsible for submitting this email report to the U.S. government in accordance with procedures described in:http://www.bis.doc.gov/encryption/PubAvailEncSourceCodeNotify.htmland Section 740.13(e) of the Export Administration Regulations ("EAR") 15 C.F.R. Parts 730-772.

Eeuh? Ik denk het niet zeker? (via http://yro.slashdot.org/story/10/02/08/1620238/SourceForge-Removes-Blanket-Blocking)

location: Application Development > Application Lifetime Management > SourceForge
created: 8/02/2010 23:51:43 « modified: 8/02/2010 23:51:43 weight: 0
tokens: coding actueel

doehetzelf erjee vijvenveertig

Grr. Ik krijg soms kriebels van die kleine dingen. Zelfgeperste kabels, maar met het buitenplastiek zo net te ver afgesneden. Deze ziet er nog niet zo erg uit, maar als ze wat beginnen te plooien gaat er zo een van de geleidertjes breken.
Iemand met een overdreven zin voor detail (kuch), knipt die bekrompen kort, zodat er lekker veel van de buitenschil tussen dat door-duw-dingetje zit. Dan zit de kop veel harder vast op de kabel en kan dan tenminste tegen een stootje.
De tang duwt trouwens ook dat driehoekbalkje door het gaatje, ik denk dat de meerderheid daar nog niet eens bij stilgestaan heeft. Knap gezien allemaal.

http://arstechnica.com/business/news/2010/02/designing-a-highly-reliable-small-medium-business-network.ars/

location: spotted on the net > IT-related > internet related
created: 8/02/2010 23:36:00 « modified: 8/02/2010 23:36:34 weight: 0
tokens: internet

Isometric perspective

Mijn eerste stapjes in doe-het-zelf isometrisch perspectief, schoon he?

Voor wie het zich afvraagt, de onderste helft bevat XYZ coordinaten in de RGB planes, de schakeringen in het zwart zie je met het blote oog niet, maar de negatieve coordinaten zie je wel mooi in het groen, rood en met zowel X en Y in het negatief geel.

location: www.yoy.be > users > StijnSanders > IRL > Nostalgia
created: 21/01/2010 23:05:42 « modified: 21/01/2010 23:07:29 weight: 0
tokens: coding

user: trevor commented on: 15/01/2010 13:27:42 Chromium: HTML Ruby/RT element not rendered

Showoff!

Chromium: HTML Ruby/RT element not rendered

Woohoo! Een van mijn tickets is Fixed:

Updates:
       Status: Fixed

Comment #9 on issue 4016 by scarybeasts: HTML Ruby/RT element not rendered


http://code.google.com/p/chromium/issues/detail?id=4016

Implemented in latest Chrome Betas.

location: Information > Technology > Companies > Google > Google Chrome
created: 14/01/2010 7:55:58 « modified: 14/01/2010 7:55:58 weight: 0
tokens: internet

user: anonymous user commented on: 15/12/2009 14:41:43 Harddisk recovery

I like this! Our Systems people formatted my HDD by mistake (drive with data instead of the one with program files) when they installed windows on my PC. Luckily I bought a portable HDD the previous day and copied everything, otherwise I might as well not have come into the office…

Harddisk recovery

Deze mens is met serieuze dingen bezig zo te zien:
http://blog.atola.com/disksense-gigabit-ethernet/
Maar is wel te zo goed om ntfsundelete gratis ter beschikking te stellen (en het lijkt nog te werken ook)

location: spotted on the net > IT-related > hardware related
created: 12/12/2009 15:07:15 « modified: 12/12/2009 15:07:15 weight: 0
tokens: computers