Skip to content

Instantly share code, notes, and snippets.

View happyincent's full-sized avatar

Vincent Chen happyincent

View GitHub Profile
@happyincent
happyincent / chromeurl.reg
Last active October 30, 2021 16:53
URL Scheme to open Chrome
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\chromeurl]
@="URL:Google Chrome Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\chromeurl\Shell]
[HKEY_CLASSES_ROOT\chromeurl\Shell\Open]
[HKEY_CLASSES_ROOT\chromeurl\Shell\Open\Command]
@="cmd /V /C \"set \"URL=%1\" && set URL=!URL:^&=^^^&! && set URL=!URL:chromeurl://=! && cmd /c \"start chrome !URL!\" \""
; chromeurl://https://www.google.com/search?q=google&oq=google
@happyincent
happyincent / lockThenRun.ts
Created January 13, 2023 18:21
Lock then run the Promise only in one window/tab with Web Locks API (native/polyfill).
if (!window.isSecureContext) import("navigator.locks");
async function lockThenRun<T>(name: string, callback: (lock: Lock | null) => Promise<T>) {
return await window.navigator.locks
.request(name, { ifAvailable: true }, async (lock) => {
if (lock === null) throw new DOMException("The lock was not granted.");
await new Promise((resolve) => setTimeout(resolve, Math.random() * 100));
return lock;
})
.then(callback)
@happyincent
happyincent / yupHelper.ts
Created February 16, 2023 07:33
A workaround to get autocomplete work in yup.object with Partial keys of an existing type.
type Shape<T, K extends keyof T> = { [key in K]?: yup.ISchema<T[key]> | ReturnType<typeof yup.ref<T[key]>> };
export type YupObjectType<T> = Pick<T, keyof T>;
export type YupObjectShape<T> = Shape<T, keyof T>;
// Usage: yup.object<YupObjectType<T>, YupObjectShape<T>>({ ... })
@happyincent
happyincent / ToDbString.cs
Created April 1, 2023 15:03
Convert string to Dapper's DbString with StringLengthAttribute and UnicodeAttribute.
public static DbString ToDbString<T>(this string value, string key, bool? IsFixedLength, int? MaxLength, bool? IsAnsi)
{
var property = typeof(T).GetProperty(key);
var attrLength = property?.GetCustomAttributes<StringLengthAttribute>().SingleOrDefault();
var maxLength = MaxLength ?? attrLength?.MaximumLength ?? DbString.DefaultLength;
var attrAnsi = property?.GetCustomAttributes<UnicodeAttribute>().SingleOrDefault();
var isAnsi = IsAnsi ?? attrAnsi?.IsUnicode switch
{
[ -f /tmp/mnt/DDL/D/tomato/syncthing-linux-arm/syncthing ] && /tmp/mnt/DDL/D/tomato/syncthing-linux-arm/syncthing --gui-address=192.168.2.1:8384 --home=/tmp/mnt/DDL/D/tomato/syncthing-linux-arm/home
#>/tmp/mnt/DDL/D/tomato/syncthing-linux-arm/log.txt 2>&1
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Target Name="PublishHash" AfterTargets="AfterPublish">
<ItemGroup>
<FilesToHash Include="$(PublishDir)**" Exclude="$(PublishDir)*.sha256;" />
</ItemGroup>
<GetFileHash Files="@(FilesToHash)" Algorithm="SHA256">
<Output TaskParameter="Items" ItemName="Hashes" />
</GetFileHash>