Time to Go Back to the School

Time to be back to the school. No, not as a student, but as a mentor. I have a debt to pay back to.

학교로 돌아갈 시간

학교로 돌아갈 시간이다. 아니, 학생으로서가 아니라 멘토로써. 난 되갚아야 할 빚이 있거든.

XMLlucination: 의사(pseudo) XML 해석기

XMLlucination은 XML 문서에 대한 의사(pseudo) 해석기입니다. XMLlucination은 노드를 찾고, 속성이나 노드 안의 raw text를 읽을 수 있습니다. 예. raw text입니다 - 텍스트 엘리먼트같은 것만 선택적으로 뽑아내는게 아니라, 노드 안에 있는 텍스트 전체를 뽑아내는 무식한 녀석입니다(……).

이 코드의 라이선스는 Lazarus의 라이선스 조건을 따릅니다. 기본적으로는 LGPL이나, 추가적으로 static link를 허용합니다.

간단한 사용법은 다음과 같습니다:

  1. 파일을 PChar 배열이나 String에 읽어들입니다.
  2. LocateNodePair()를 사용하여 TNodePair를 받습니다.
  3. GetAttributeValue()에 TNodePair.Open를 적용하여 속성값을 얻어냅니다.
  4. GetNodeValue()에 TNodePair 객체를 적용하면 node 안의 text를 얻을 수 있습니다.

아무쪼록 도움이 되셨으면 좋겠습니다. 즐거운 코딩 되세요!

2014년 4월 21일 추가:2013년 10월 31일에 등록된 원본 포스팅에서는 본 포스팅에 모든 소스코드를 공개하였으나,지금은 소스코드를 Google Drive의 파일 링크로 대체합니다. Uploading 당시 Tumblr의 오류로 추정되는 이상행위로 인해 소스코드가 여러모로 사용 불가능하게 등록되어 있더군요(따옴표의 유니코드 대체, ‘보다 작다’ 부등호 사인의 삭제 등).
이 문장을 클릭하시면 파일을 다운로드하실 수 있습니다.

XMLlucination: XML pseudo-parser

XMLlucination is a pseudo-parser for XML documents, in which you can locate nodes and read attributes or raw text between nodes. Yes. It is raw text - anything between nodes, not intelligently extract text elements only. :P

This code applies the same license terms of Lazarus, LGPL with additionally accepting static link.

Quick start guide:

  1. Load a file to array of PChar or String
  2. Use LocateNodePair() to get a TNodePair
  3. Use GetAttributeValue() with TNodePair.Open to search for a attribute value
  4. Use GetNodeValue() with TNodePair object
Hope you like it. Happy coding!

Edit at April 21th. 2014:In the original posting at Oct. 31. 2013, I opened the full source code here but now I replace the code with download link to Google Drive. I found out the source code is broken, which is expected to unexpected Tumblr behavior(replacing the quotation mark to unicode characters, deleting ‘less than’ sign accidentally, etc).

Click here to download the file.

Freepascal과 Lazarus를 위한 자작 Boyer-Moore-Horspool 문자열 검색 알고리 즘

아래의 코드는 Boyer-Moore-Horspool 문자열 검색 알고리즘을 직접 Freepascal / Lazarus로 구현한 코드입니다. Freepascal / Lazarus에서만 테스트되었습니다만, 델파이에서도 충분히 사용 가능하리라고 생각됩니다.

이 코드의 라이선스는 Lazarus가 채용한, 수정된 LGPL(LGPL+static link 허용)을 따릅니다. 사용하시는데 큰 문제는 없을겁니다.

간단한 사용법은 다음과 같습니다.

  1. TPosBMH 객체를 생성합니다
  2. TPosBMH.PosBMH()를 호출하면 첫번째 위치를 찾습니다
  3. TPosBMH.PosBMHNext()를 호출하면 다음 위치를 찾습니다
  4. 만일 찾는 대상이 더이상 없다면, TPosBMH는 Nil을 반환합니다
실제 코드는 다음과 같습니다. 도움이 되셨으면 좋겠습니다.

{
Unit PosBMH: Implementation of Boyer-Moor-Horpspool string search algorithm, optimized for consecutive searches

Create a TPosBMH object, use PosBMH() for initializing search, and PosBMHNext() for consecutive search. The return value is always PChar.

Can be used freely under the same license of LCL(Lazarus Component Library), which adopts modified LGPL.
(LGPL + allowing exception for static linking)

©Copyright 2012~2013 Robert Teminian(Hyunse Oh)
}
unit PosBMH;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils;

type
TPosBMH = class(TObject)
private
FBMHLast: PChar;
FSubString: String;
FSubStringLength: SizeInt;
FBMHSkipTable: Array[0..255] of SizeInt;
procedure FBuildSkipTable();
procedure FPosBMH();
protected
BMHCursor: PChar;
public
function PosBMH(Needle: String; StartAt: PChar; EndAt: PChar): PChar;
function PosBMH(Needle: String; var Haystack: String): PChar;
function PosBMHNext: PChar;
end;

implementation

procedure TPosBMH.FBuildSkipTable();
var
i: Integer;
begin
for i:=0 to 255 do FBMHSkipTable[i]:=FSubStringLength;
for i:=1 to FSubStringLength do FBMHSkipTable[Byte(FSubString[i])]:=FSubStringLength-i;
end;

procedure TPosBMH.FPosBMH();
begin
while BMHCursor if FBMHSkipTable[Byte(BMHCursor^)]=0 then begin
Dec(BMHCursor, FSubStringLength-1);
if CompareByte(BMHCursor^, FSubString[1], FSubStringLength)=0 then Exit
else Inc(BMHCursor, FSubStringLength);
end else Inc(BMHCursor, FBMHSkipTable[Byte(BMHCursor^)]);
end;
BMHCursor:=nil;
end;

function TPosBMH.PosBMH(Needle: String; StartAt: PChar; EndAt: PChar): PChar;
begin
FSubString:=Needle;
FSubStringLength:=Length(FSubString);
BMHCursor:=StartAt;
FBMHLast:=EndAt;
FBuildSkipTable();
FPosBMH();
Result:=BMHCursor;
end;

function TPosBMH.PosBMH(Needle: String; var Haystack: String): PChar;
begin
Result:=PosBMH(Needle, @Haystack[1], @Haystack[Length(Haystack)]);
end;

function TPosBMH.PosBMHNext: PChar;
begin
if(BMHCursorNil) then begin
Inc(BMHCursor, FSubStringLength);
FPosBMH();
end;
Result:=BMHCursor;
end;

end.

Implementation of Boyer-Moore-Horspool string search algorithm forFreepascal / Lazarus

This is my own implementation of Boyer-Moore-Horspool string search algorithm for object pascal. Though tested only in Freepascal / Lazarus, I think the code can also apply to Delphi.

The license of this code is modified LGPL Lazarus adopted(LGPL+permitting static link), so enjoy using it,

Quick instructions:

  1. Make a TPosBMH object
  2. Use TPosBMH.PosBMH() to find out the first occurrence
  3. Use TPosBMH.PosBMHNext() to locate the next occurrence
  4. If there’s no more, TPosBMH returns Nil
Now, here comes the code. Enjoy!

{
Unit PosBMH: Implementation of Boyer-Moor-Horpspool string search algorithm, optimized for consecutive searches

Create a TPosBMH object, use PosBMH() for initializing search, and PosBMHNext() for consecutive search. The return value is always PChar.

Can be used freely under the same license of LCL(Lazarus Component Library), which adopts modified LGPL.
(LGPL + allowing exception for static linking)

©Copyright 2012~2013 Robert Teminian(Hyunse Oh)
}
unit PosBMH;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils;

type
TPosBMH = class(TObject)
private
FBMHLast: PChar;
FSubString: String;
FSubStringLength: SizeInt;
FBMHSkipTable: Array[0..255] of SizeInt;
procedure FBuildSkipTable();
procedure FPosBMH();
protected
BMHCursor: PChar;
public
function PosBMH(Needle: String; StartAt: PChar; EndAt: PChar): PChar;
function PosBMH(Needle: String; var Haystack: String): PChar;
function PosBMHNext: PChar;
end;

implementation

procedure TPosBMH.FBuildSkipTable();
var
i: Integer;
begin
for i:=0 to 255 do FBMHSkipTable[i]:=FSubStringLength;
for i:=1 to FSubStringLength do FBMHSkipTable[Byte(FSubString[i])]:=FSubStringLength-i;
end;

procedure TPosBMH.FPosBMH();
begin
while BMHCursor if FBMHSkipTable[Byte(BMHCursor^)]=0 then begin
Dec(BMHCursor, FSubStringLength-1);
if CompareByte(BMHCursor^, FSubString[1], FSubStringLength)=0 then Exit
else Inc(BMHCursor, FSubStringLength);
end else Inc(BMHCursor, FBMHSkipTable[Byte(BMHCursor^)]);
end;
BMHCursor:=nil;
end;

function TPosBMH.PosBMH(Needle: String; StartAt: PChar; EndAt: PChar): PChar;
begin
FSubString:=Needle;
FSubStringLength:=Length(FSubString);
BMHCursor:=StartAt;
FBMHLast:=EndAt;
FBuildSkipTable();
FPosBMH();
Result:=BMHCursor;
end;

function TPosBMH.PosBMH(Needle: String; var Haystack: String): PChar;
begin
Result:=PosBMH(Needle, @Haystack[1], @Haystack[Length(Haystack)]);
end;

function TPosBMH.PosBMHNext: PChar;
begin
if(BMHCursorNil) then begin
Inc(BMHCursor, FSubStringLength);
FPosBMH();
end;
Result:=BMHCursor;
end;

end.

Activate QtWebKit module for Qt Quick after manually building Qt inWindows

After building Qt from source code, you’ll find out that Qt Creator will complain that “module QtWebKit is not installed” for your Qt WebKit 3.0 applications.

In this case, follow the order here as a remedy:

  1. Copy jsc.exe and QtWebBrowser.exe in qtwebkit/bin to qtbase/bin
  2. Copy QtWebKit directory from qtwebkit/import to qtbase/qml
  3. in qtbase/qml/QtWebKit, make a new file named qmldir, and write down following:
    module QtWebKit
    plugin qmlwebkitplugin
  4. Try your code
  5. PROFIT! :)

Windows에서 Qt를 build한 후 QtWebKit을 활성화하는 방법

Qt를 소스코드에서 빌드한 후 Qt Quick에서 QtWebKit 3.0을 import한 후 실행해보면, Qt Creator가 “module QtWebKit is not installed”라는 메시지를 내며 Qt WebKit을 제대로 가져오지 못하는 경우가 있습니다. 이 경우 다음을 따라해보세요:

  1. qtwebkit/bin에 있는 jsc.exe와 QtWebBrowser.exe를 qtbase/bin으로 복사합니다
  2. qtwebkit/import에 있는 QtWebKit 디렉토리를 qtbase/qml에 복사합니다
  3. qtbase/qml/QtWebKit 디렉토리에 qmldir이라는 이름의 파일을 새로 생성하고 다음의 내용을 입력합니다:
    module QtWebKit
    plugin qmlwebkitplugin
  4. 코드를 테스트합니다
  5. PROFIT! :)

Hidden dependency of pacbuilder in Arch Linux

pacbuilder is a useful tool in Arch Linux when you try to rebuild all the packages from the source, regardless of the repository(ABS or AUR).

But seldom someone notices the idea that the tool has the hidden package dependency of pacbuilder - sudo. I didn’t know that and in the pacbuilder-svn AUR there was no indication of the dependency. I had to read the script itself and modify some of the codes to see the blackholed message myself.

If you try pacbuilder(like pacbuilder -v —world) but you encountered error such as “makepkg failed”, just run pacman -S sudo and everything would work fine. I think I’ll report a new PKGBUILD for the package in AUR.

아치 리눅스 - pacbuilder의 숨겨진 의존성

Arch Linux의 3rd party tool 중 하나인 pacbuilder는 리포지토리에 상관없이(ABS든 AUR이든) 시스템에 설치된 모든 패키지를 쉽게 다시 컴파일할 수 있도록 도와줍니다. 하지만 많은 사람들이 이 도구에 숨겨진 패키지 의존성이 있다는 것을 모르는 것 같습니다: pacbuilder는 sudo가 없으면 동작을 제대로 안 하더군요. AUR에 있는 pacbuilder-svn에는 이러한 의존성이 표시되어 있지 않아서 스크립트를 보면서 찾아다녀야 했습니다.

혹시 pacbuilder를 쓰려고 하는데 makepkg error 등의 문제가 일어나거든 pacman -S sudo를 실행해주시면 될겁니다. AUR 관리자에게 PKGBUILD를 수정해서 보내던가 해야 할 것 같네요.

PostgreSQL vs. SQLite: read & write in multithreaded environment

The start was humble. I needed to cache some data, and I thought just push them to database table and give index, and the rest will be datab...

Popular in Code{nested}