Skip to content

Instantly share code, notes, and snippets.

View emptyother's full-sized avatar

Tom A. Vibeto emptyother

View GitHub Profile
@emptyother
emptyother / uuid_to_bin.sql
Created August 21, 2020 09:23 — forked from tzal/uuid_to_bin.sql
MySQL: convert GUID (UUID) to BINARY(16)
# MySQL: convert GUID (Microsoft-style UUID) to BINARY(16)
# '11223344-5566-7788-9900-AABBCCDDEEFF' → 0x44332211665588779900AABBCCDDEEFF
# usage: CREATE TABLE example(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, guid BINARY(16) NOT NULL UNIQUE);
# INSERT INTO example(guid) VALUES (uuid_to_bin(UUID()));
CREATE FUNCTION uuid_to_bin(s CHAR(36))
RETURNS binary(16)
DETERMINISTIC
RETURN UNHEX(CONCAT(
SUBSTRING(s,7,2),SUBSTRING(s,5,2),SUBSTRING(s,3,2),SUBSTRING(s,1,2),
@emptyother
emptyother / uuid_from_bin.sql
Created August 21, 2020 09:21 — forked from tzal/uuid_from_bin.sql
MySQL: convert BINARY(16) to GUID (UUID)
# MySQL: convert BINARY(16) to GUID (Microsoft-style UUID)
# 0x11223344556677889900AABBCCDDEEFF → '44332211-6655-8877-9900-AABBCCDDEEFF'
# usage: CREATE TABLE example(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, guid BINARY(16) NOT NULL UNIQUE);
# SELECT id, uuid_from_bin(guid) FROM example;
CREATE FUNCTION uuid_from_bin(b BINARY(16))
RETURNS char(36) CHARSET utf8
DETERMINISTIC
BEGIN
DECLARE h CHAR(32);
@emptyother
emptyother / .mocharc.json
Last active January 6, 2020 10:16
JSON Schemas
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://onlyhuman.dk/json-schema/.mocharc.json",
"type": "object",
"title": "The Root Schema",
"properties": {
"diff": {
"$id": "#/properties/diff",
"type": "boolean",
@emptyother
emptyother / Generic Interfaces.ts
Last active October 28, 2019 14:18
Useful typescript interfaces
/**
* Removes ReadOnly from all properties on an interface.
*/
type Mutable<T> = {
-readonly [P in keyof T]: T[P] extends ReadonlyArray<infer U> ? Mutable<U>[] : Mutable<T[P]>
};
@emptyother
emptyother / runtime_reflection.js
Last active October 22, 2019 04:45
runtime_reflection.js
/**
* Reads a object at runtime and serializes it into metadata.
* Need serious improvements, but does some of the work.
* @returns metadata.
* @returns typescript definition text.
*/
function (targetvar){
// TODO: Find a way to recognize a class from a function.
// TODO: Find out how to detect arrays (should be easy).
// TODO: Create separate interfaces instead of a nested interface.
@emptyother
emptyother / Read-BeepFile.ps1
Created July 12, 2019 22:09
[Read-BeepFile] Powershell script to read a text file and beep based on the content #powershell
<#
.Synopsis
Reads a file, and beeps on 0 or 1.
.Description
Reads a textfile, beeps once for every 0 and twice for 1 it finds in the text.
.Parameter Path
The file to read
.Inputs
System.IO.FileInfo
.Example
@emptyother
emptyother / disposable.ts
Created May 6, 2018 21:34
Implementing C#'s "IDisposable" pattern in Typescript
interface Disposable {
dispose(): void;
}
function using<T extends Disposable>(instance: T, fn: (instance: T) => any) {
try {
fn(instance);
} finally {
instance.dispose();
}
}
@emptyother
emptyother / MyExtensions.linq
Last active November 10, 2021 16:18
Linqpad extensions
<Query Kind="Program">
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>System.Globalization</Namespace>
</Query>
void Main()
{
// Write code to test your extensions here. Press F5 to compile and run.
}
@emptyother
emptyother / firefox settings.md
Last active January 12, 2020 23:34
My firefox settings

These files goes into your user profile folder, which can be found at about:profiles.

The user.js file goes into the root of the profile directory, and userChrome.css and userContent.css goes into a subfolder called chrome.

@emptyother
emptyother / uuid_to_bin.sql
Created December 13, 2017 11:13
Mysql convert Guid to binary
DELIMITER |
CREATE FUNCTION uuid_from_bin(b BINARY(16))
RETURNS CHAR(36) DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
SET hex = HEX(b);
RETURN CONCAT(LEFT(hex, 8), '-', MID(hex, 9,4), '-', MID(hex, 13,4), '-', MID(hex, 17,4), '-', RIGHT(hex, 12));
END
|