Skip to content

Instantly share code, notes, and snippets.

@an01f01
an01f01 / tzipfile_example.pas
Created January 17, 2023 21:50
Creates and extract sample procedures for Zip files with Delphi
uses
System.Zip;
procedure CreateZipFile():
var
ZipFile: TZipFile;
begin
// Creates a new instance of TZipFile
ZipFile := TZipFile.Create;
var
SelectedFile: string;
begin
if OpenDialog1.Execute then begin
for SelectedFile in OpenDialog1.Files do
ListBox1.Items.Add(SelectedFile);
end;
end;
{ Since the process is now dynamic, the method that compresses the files should be changed }
procedure TForm1.OnProgressEvent(Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64);
var
CurrentFileProgress: real;
OverallProgress: real;
begin
Application.ProcessMessages;
// Calculates the percentages
CurrentFileProgress := Position / Header.UncompressedSize * 100;
OverallProgress := (BytesProcessed + Position) / BytesToProcess * 100;
// Updates the labels with each progress
private
procedure OnProgressEvent(Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64);
{ … }
procedure TForm1.OnProgressEvent(Sender: TObject; FileName: string; Header: TZipHeader; Position: Int64);
begin
Application.ProcessMessages;
// Displays the compression percentage
private
function GetFileSize(const FileName: string): integer;
{ … }
function TForm1.GetFileSize(const FileName: string): integer;
var
StreamArchive: TFileStream;
begin
import os
import sys
import json
import ast
import datetime
import django
orm_dir_path = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'server/my_orm')
server_dir_path = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'server')
@an01f01
an01f01 / tornado_app_v6_3.py
Last active May 25, 2023 20:34
Base tornado 6.3 app
import os
import signal
import asyncio
from typing import Optional, Awaitable
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import os
import signal
import asyncio
from typing import Optional, Awaitable
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
procedure TFrmMain.FormCreate(Sender: TObject);
begin
inherited;
{ TODO: Initialized objects }
end;
procedure TFrmMain.BtnSaveClick(Sender: TObject);
begin
inherited;
{ TODO: Encrypt and save json file }
procedure TFrmMain.BtnSaveClick(Sender: TObject);
begin
inherited;
Memo1.Lines.Add('Saving...');
Memo1.Lines.Add(TTodoProgSettings.GetSettingsFolder);
Memo1.Lines.Add(TTodoProgSettings.GetDefaultSettingsFilename);
Todos.Name := 'test me';
TTodoProgSettings.SaveTodos(Todos);
end;