Skip to content

Instantly share code, notes, and snippets.

View dkstar88's full-sized avatar

William Yang dkstar88

  • iHerb
  • Shanghai, China
View GitHub Profile
@dkstar88
dkstar88 / json2php
Last active May 17, 2016 06:57
json2php is script convert Json object to PHP array. Combine it with "pbpaste | php ~/scripts/json2php.php | pbcopy", from terminal, makes quick tool for convert json to php.
<?php
function var_export54($var, $indent="") {
switch (gettype($var)) {
case "string":
return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"';
case "array":
$indexed = array_keys($var) === range(0, count($var) - 1);
$r = [];
foreach ($var as $key => $value) {
@dkstar88
dkstar88 / udiskcache.pas
Created August 1, 2013 09:07
Stores data in a specified storage folder, all stored files are stored in a flat dir structure, no sub folders, filenames are hashed using md5. In the root folder, a hidden file "cache.ini" will be created to store cache time, and other data
unit uDiskCache;
interface
uses System.SysUtils, System.Classes, System.IOUtils, System.DateUtils,
FMX.Types, IniFiles, System.Generics.Collections;
type
{
Stores data in a specified storage folder, all stored files are
@dkstar88
dkstar88 / hashutil.pas
Created August 1, 2013 08:56
Short hash function name wrapper for TIdHashMessageDigest5
unit hashutil;
interface
uses SysUtils, Classes, IdGlobal, IdHash, IdHashMessageDigest, IdHashSHA, IdHashCRC;
function MD5(S: String): String; overload;
function MD5(S: TStream): String; overload;
function MD5_Bytes(S: String): TIdBytes;
function MD5_File(AFilename: String): String;
@dkstar88
dkstar88 / hashutil.pas
Created August 1, 2013 08:56
Short hash function name wrapper for TIdHashMessageDigest5
unit hashutil;
interface
uses SysUtils, Classes, IdGlobal, IdHash, IdHashMessageDigest, IdHashSHA, IdHashCRC;
function MD5(S: String): String; overload;
function MD5(S: TStream): String; overload;
function MD5_Bytes(S: String): TIdBytes;
function MD5_File(AFilename: String): String;
@dkstar88
dkstar88 / version.pas
Created August 1, 2013 08:51
A generic Version structure utilizing operator override feature in Delphi versions. Currently it supports comparison, and not so useful addition and substraction. Now you can do TVersion('1.0.2.3') > TVersion('1.0.2.2') I also put AppVersion, which returns the version of your running application for both Windows and MacOS. So checking where if t…
unit Version;
interface
uses Types;
type
TVersion = record
Major, Minor, Release, Build: Word;
@dkstar88
dkstar88 / uImageLoader.pas
Created July 23, 2013 06:43
A ImageLoader for FireMonkey TImage component. I written this when I found I need to load a few images from the Internet. Obviously delphi isn's browser, if I just call download using Indy it will just block my app's UI. ImageLoader is very simple class with a loading queue, and a timer to trigger the work on the queue. You just need to call the…
unit uImageLoader;
interface
uses SysUtils, Classes, System.Generics.Collections,
FMX.Types, FMX.Objects, FMX.Controls, AsyncTask, AsyncTask.HTTP;
type
TLoadQueueItem = record
ImageURL: String;
@dkstar88
dkstar88 / WebLabel.pas
Created July 23, 2013 03:38
A clickable label opens URL in system's Internet browser with full Mouse Hover, Mouse Down effect.
{
Author: William Yang
Website: http://www.pockhero.com
Last Update: 2013/07/23
A clickable label opens URL in system's Internet browser.
}
/// <summary>
/// A clickable label opens URL in system's Internet browser.
/// </summary>
@dkstar88
dkstar88 / FilenameHelper.pas
Created July 12, 2013 06:43
FilenameHelper is a helper for TFilename, its purpose is to be able to use TFilename like an object, codes readable and less writing.
{
FilenameHelper is a helper for TFilename, its purpose is to be able
to use TFilename like an object, codes readable and less writing.
Author: William Yang
Email: flyingdragontooth@gmail.com
Features:
@dkstar88
dkstar88 / buildrc.cmd
Created July 8, 2013 07:31
Reads files inside resources sub folder and turn them into resource script. With certain replacement of special chars, Slash (\), Space ( ), Dash (-) all converted to underscore.
@echo on>resources.rc
@echo off
setlocal enabledelayedexpansion
set "parentfolder=%__CD__%resources\"
for /r %parentfolder% %%g in (*.*) do (
set "var=%%g"
set var=!var:%parentfolder%=!
set file=!var:\=\\!
set var=!var: =_!
set var=!var:-=_!
@dkstar88
dkstar88 / httputil.pas
Created July 6, 2013 17:45
I wrote these two functions for idhttp for easy usage.
unit httpUtil;
interface
uses Classes, SysUtils, IdHTTP;
type
THTTP_STATUS = Cardinal;
function DownloadToStream(AURL: String; AStream: TStream): THTTP_STATUS;