Skip to content

Instantly share code, notes, and snippets.

@hallojoe
hallojoe / CharacterClassifications.ts
Created February 24, 2021 15:00
Bitwise flags for classifying characters.
enum CharacterClassifications {
None = 0,
Digit = 1,
Upper = 2,
Lower = 4,
Space = 8,
Control = 16,
SymbolOrPunctuation = Upper | Lower,
AlphaOrDigit = Digit | Upper | Lower | Space
}
@hallojoe
hallojoe / UnicodeMap.ts
Created February 14, 2021 12:21
Unicode character code ranges mapped to category name.
const UnicodeMap = new Map<string, [number, number]>([
["Basic Latin", [32, 127]],
["Latin-1 Supplement", [160, 255]],
["Latin Extended-A", [256, 383]],
["Latin Extended-B", [384, 591]],
["IPA Extensions", [592, 687]],
["Spacing Modifier Letters", [688, 767]],
["Combining Diacritical Marks", [768, 879]],
["Greek and Coptic", [880, 1023]],
["Cyrillic", [1024, 1279]],
@hallojoe
hallojoe / inheritTimeFrom.js
Last active January 20, 2021 11:14
Inherit time from source date time
function inheritTimeFrom(source, target) {
var sourceDateTime = new Date(source)
var targetDateTime = new Date(target)
targetDateTime.setHours(sourceDateTime.getHours())
targetDateTime.setMinutes(sourceDateTime.getMinutes())
targetDateTime.setSeconds(sourceDateTime.getSeconds())
targetDateTime.setSeconds(sourceDateTime.getMilliseconds())
return targetDateTime
}
@hallojoe
hallojoe / File.ts
Created January 14, 2021 09:16
Read files with FileReader
export interface IFile {
name: string
size?: number
type?: string
lastModified?: number
data?: string|ArrayBuffer
}
export enum ReadFileReturnTypes {
Text = "text",
const slug = s => s
.toString() // ensure string
.normalize("NFD") // convert to unicode normalization form using (N)normalization (F)form canonical (D)decomposition
// aka. remove accent and leave base
.replace(/[\u0300-\u036f]/g, "") // remove range combining grave accent to combining lating small letter x
.toLowerCase() // lower chars
.trim() // trim whitespace
.replace(/\s+/g, '-') // replace space(s) with dash
.replace(/[^\w-]+/g, "") // remove things not a-z A-Z 0-9 or -
.replace(/--+/g, '-') // replace double dash with single dash
@hallojoe
hallojoe / checkered-background.css
Last active September 9, 2021 18:13
Color-scheme aware CSS checkered background.
:root {
font-size:24px;
--backgroundColor: rgba(255, 255, 255);
--squareColor: rgba(100, 100, 100, .5);
--squareSize: 2em;
}
@media (prefers-color-scheme: dark) {
:root {
--backgroundColor: rgb(0, 0, 0);
@hallojoe
hallojoe / ManagedForEachAsync.cs
Last active December 14, 2019 17:00
Executes a collection of functions, in parallel managed by a semaphore.
/// <summary>
/// Executes a list of functions, in parallel managed by a semaphore.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="values">The values to act on.</param>
/// <param name="maxDegreeOfParallelism">Maximum degree of parallelism when executing functions.</param>
/// <param name="fn">Function to call using value.</param>
/// <returns></returns>
public static async Task ManagedForEachAsync<T>(this IEnumerable<T> values, int maxDegreeOfParallelism, Func<T, Task> fn)
{
@hallojoe
hallojoe / nuget.ps1
Last active October 7, 2019 14:32
Powershell script that will pack and push .nupkg
# Nuget packaging thing
#
# Use this guy to pack and push .nupkg from your .csproj
#
# Note: nuget.exe pack will assume a .nuspec file already exist
# if not then create one yourself: nuget.exe spec.
# This is not done automatically, as you probably wan't to
# customize this your self, before running this.
#
# This will check if the assembly version on given project
@hallojoe
hallojoe / isTrue.js
Created February 24, 2019 10:07
A thing JavaScript that convert a boolean'ish strings and a number to boolean
var isTrue = function (value) {
if ('string' === typeof (value)) value = value.toLowerCase().trim();
return ['true', '1', 'on', 'yes', 1].indexOf(value) > -1;
};
@hallojoe
hallojoe / range.scss
Last active November 7, 2018 05:45
Input range styled css sass
// Input range sass thing. Result of reading this:
// http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html
// 07112018: removed focus outline i firefox
$range-track-width: 100%;
$range-track-height: 12px;
$range-track-background: #ccc;
$range-track-background-focus: #ccc;
$range-track-border: none;
$range-track-border-radius: 3px;