Skip to content

Instantly share code, notes, and snippets.

@ccy
ccy / DHCP-Self-Assign-Lease.md
Last active December 12, 2020 06:43
Self assign DHCP lease from own DHCP server

Introduction

A DHCP server listen on a network interface (e.g: eth0)

$ cat /etc/default/isc-dhcp-server
INTERFACESv4="eth0"
INTERFACESv6=""
version: '2.4'
services:
dns:
image: estreamsoftware/coredns-forward
restart: always
networks:
default:
ipv4_address: 10.10.50.255
@ccy
ccy / delphi.async.md
Last active December 21, 2023 01:57

DEPRECATED: Refer to delphi-ppl

UI design strategy for long running task

A long running task may cause the application runtime become unresponsive and lead perception of application halt or hang during the operation.

For example:

  1. A database backup operation spend 10 minutes to finish.
  2. Perform length report calculation
@ccy
ccy / FastReport - AlignHorzCenter.pas
Last active August 26, 2021 14:11
FastReport: Align linear controls to center horizontally
procedure AlignHorzCenter(aControls: array of TfrxView);
var i: Integer;
iTotalWidth, iLeft: Extended;
CalcWidths: array of Extended;
Gaps: array of Extended;
begin
if not Engine.FinalPass then Exit;
if Length(aControls) = 0 then Exit;
// Calculate actual width of controls
@ccy
ccy / fmx.detectDeviceOrientationChange.pas
Created July 20, 2017 04:38
FireMonkey: Detect device orientation change
uses System.Messaging, FMX.Platform;
var FId: Integer;
// Subscribe to TOrientationChangedMessage
FId := TMessageManager.DefaultManager.SubscribeToMessage(TOrientationChangedMessage, DoOrientationChanged);
// Write orientation change handler:
procedure TMyForm.DoOrientationChanged(const Sender: TObject; const M: TMessage);
var s: IFMXScreenService;
uses Patterns.Singleton.Generic;
var o1, o2: TSingleton<TStringList>;
s1, s2, s3: string;
begin
o1.Get.AddStrings(['a1', 'a2']);
s1 := o1.Get.Text; // return "a1<cr,lf>a2"
s2 := o2.Get.Text; // return "a1<cr,lf>a2"
s3 := TSingleton<TStringList>.Get.Text; // // return "a1<cr,lf>a2"
@ccy
ccy / EnumerateNetworkInterfaces.pas
Last active January 15, 2017 11:50
Enumerate Network Interfaces in Windows
uses
System.SysUtils,
Winapi.Windows,
Winapi.IpTypes,
Winapi.IpHlpApi;
var
Adapter, Current: PIP_ADAPTER_ADDRESSES;
Buffer: NativeInt;
Error: DWord;
@ccy
ccy / 0_reuse_code.js
Created April 10, 2016 04:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ccy
ccy / UpdateResource.pas
Last active January 15, 2017 11:28
Update embedded resource in Windows binary file
procedure UpdateExeResource(Const Source,Dest:string);
var
Stream : TFileStream;
hDestRes : THANDLE;
lpData : Pointer;
cbData : DWORD;
begin
Stream := TFileStream.Create(Source,fmOpenRead or fmShareDenyNone);
try
Stream.Seek(0, soFromBeginning);
@ccy
ccy / GetIconByFileExt.pas
Last active January 15, 2017 12:17
Get icon for known file type
uses Winapi.ShellAPI;
function GetIconByFileExt(aFileExt: string): TBytes;
var C: TIcon;
N: SHFILEINFO;
S: TBytesStream;
begin
C := TIcon.Create;
try
Win32Check(Succeeded(