This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class PromiseLike | |
{ | |
public static Task Create(Action<TaskCompletionSource> action) | |
{ | |
ThrowIfNull(action); | |
var tcs = new TaskCompletionSource(); | |
action.Invoke(tcs); | |
return tcs.Task; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.DependencyInjection.Extensions; | |
public interface ISingletonService<out TService> | |
{ | |
TService Serivce { get; } | |
} | |
public static class SingletonServiceHelper | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# copied from https://stackoverflow.com/questions/17782142/ | |
def patch_requests_timeout(default_timeout: float) -> None: | |
import requests | |
old_send = requests.Session.send | |
def new_send(*args, **kwargs): | |
if kwargs.get("timeout", None) is None: | |
kwargs["timeout"] = default_timeout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class BitArrayExtensions | |
{ | |
public static byte[] ToByteArray(this BitArray bits) | |
{ | |
// copied from https://stackoverflow.com/questions/560123/convert-from-bitarray-to-byte | |
byte[] ret = new byte[(bits.Length + 7) >> 3]; | |
bits.CopyTo(ret, 0); | |
return ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $ProjectKey, | |
[Parameter(Mandatory = $true)] | |
[string] $BaseName | |
) | |
$BaseUrl = "https://database.deta.sh/v1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bulk clone repos from config list. | |
# | |
# to run the script, try: | |
# ^nu 'bulk-git-clone.nu' .\git_repos.yaml | |
def get-qualname [repo_url: string] { | |
let $name_parts = if $repo_url =~ '^https?://' { | |
let $match = ($repo_url | parse -r '^https?://(?P<host>.+)/(?P<user>.+)/(?P<repo>.+)$') | |
if ($match | length) > 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright (c) 2022~2999 - Cologler <[email protected]> | |
# ---------- | |
# | |
# ---------- | |
from time import monotonic as _time | |
def iwait(wait, timeout=None, *, interval=0.1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load all partial scripts to caller context. | |
# - for caller, add `. "$(Split-Path $PSCommandPath)\Load-PartialScripts.ps1"`; | |
# - the partial scripts must named `{caller}.{partial}.ps1`; | |
foreach ( | |
$item in $( | |
Get-ChildItem ` | |
-Path $(Split-Path $MyInvocation.PSCommandPath -Parent -Resolve) ` | |
-Filter "$(Split-Path $MyInvocation.PSCommandPath -LeafBase).*$(Split-Path $MyInvocation.PSCommandPath -Extension)" ` | |
| Sort-Object { Split-Path $_ -LeafBase } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright (c) 2021~2999 - Cologler <[email protected]> | |
# ---------- | |
# | |
# ---------- | |
import json | |
import re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright (c) 2021~2999 - Cologler <[email protected]> | |
# ---------- | |
# check if there has some invisible chars in your file path. | |
# ---------- | |
from typing import * | |
import os | |
import sys |
NewerOlder