Skip to content

Instantly share code, notes, and snippets.

View edwinyzh's full-sized avatar

Edwin Yip edwinyzh

View GitHub Profile
@edwinyzh
edwinyzh / progress.html
Created June 7, 2018 04:05 — forked from WeiChiaChang/progress.html
Simple Pure CSS Progress Bar
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta chatset="UTF-8" />
<title>CSS Progress Bar</title>
<style>
.wrapper {
width: 500px;
}
@edwinyzh
edwinyzh / OAuth2Authentication.pas
Created April 18, 2018 09:55
mORMot OAuth2 Implementation
unit OAuth2Authentication;
// OAuth2 implemetation
// - http://tools.ietf.org/html/rfc6749
interface
uses
{$ifdef USE_FASTMM4}
FastMM4,
@edwinyzh
edwinyzh / MyAuthentication.pas
Created April 18, 2018 09:55
TOAuth2ResourceOwnerPasswordGrant example
unit MyAuthentication;
interface
uses
OAuth2Authentication,
SysUtils,
SynCommons,
mORMot;
@edwinyzh
edwinyzh / Oauth2.md
Created March 31, 2018 14:47 — forked from mziwisky/Oauth2.md
Oauth2 Explanation

OAUTH2

The Problem

I’m a web app that wants to allow other web apps access to my users’ information, but I want to ensure that the user says it’s ok.

The Solution

I can’t trust the other web apps, so I must interact with my users directly. I’ll let them know that the other app is trying to get their info, and ask whether they want to grant that permission. Oauth defines a way to initiate that permission verification from the other app’s site so that the user experience is smooth. If the user grants permission, I issue an AuthToken to the other app which it can use to make requests for that user's info.

Note on encryption

Oauth2 has nothing to do with encryption -- it relies upon SSL to keep things (like the client app’s shared_secret) secure.

@edwinyzh
edwinyzh / GlobalDataModule.pas
Last active April 2, 2020 16:35
Compilable, untested demo of opening TAdoDataset in the background thread with OmniThreadLibrary
unit GlobalDataModule;
interface
uses
System.SysUtils, System.Classes, Data.Win.ADODB, OtlTask, OtlTaskControl, OtlComm, OtlCommon;
type
TdmGlobal = class(TDataModule)
procedure DataModuleCreate(Sender: TObject);
@edwinyzh
edwinyzh / pagination_example.sql
Created March 10, 2018 17:47 — forked from ssokolow/pagination_example.sql
Reasonably efficient pagination without OFFSET (SQLite version)
-- Reasonably efficient pagination without OFFSET
-- SQLite version (Adapted from MS SQL syntax)
-- Source: http://www.phpbuilder.com/board/showpost.php?p=10376515&postcount=6
SELECT foo, bar, baz, quux FROM table
WHERE oid NOT IN ( SELECT oid FROM table
ORDER BY title ASC LIMIT 50 )
ORDER BY title ASC LIMIT 10
unit NonBlockingDlgHelperU;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
const
WM_ShowDlgA = WM_APP + 1;
unit UDebouncedEvent;
interface
uses
System.Classes, System.SysUtils, System.DateUtils, FMX.Types;
type
TDebouncedEvent = class (TComponent)
private
@edwinyzh
edwinyzh / OtlTaskTeriminationTestUnit.pas
Last active May 27, 2017 14:21
Demonstrate the blocking issue of OTL task termination
(*
1 - the thread proc.
*)
procedure MyThreadProc(task: IOmniTask);
begin
while not task.Terminated do begin
SubProcedureThatWillTakeAtLeast3Second;
if task.Terminated then Exit;
SubProcedureThatWillTakeAtLeas2Second;
@edwinyzh
edwinyzh / Unit1.dfm
Created May 24, 2017 06:50
Prove that the each OTL task has a built-in cancellation token and I use it a lot!
object frmMain: TfrmMain
Left = 0
Top = 0
Caption = 'frmMain'
ClientHeight = 571
ClientWidth = 798
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14