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 / chmod-tutorial.md
Created November 22, 2019 16:29 — forked from cjaoude/chmod-tutorial.md
chmod tutorial / cheat sheet / cheatsheet / for dummies

chmod
Forget the chmod octals (the numbers). Set permission the easy way using the keywords

// know the ownerships:
u = User (you)
g = Group
o = Other (aka. 'World')
a = All of the above

@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 / keybase.md
Created May 30, 2019 13:58
keybase.md

Keybase proof

I hereby claim:

  • I am emptyother on github.
  • I am emptyother (https://keybase.io/emptyother) on keybase.
  • I have a public key ASBFH6HUS7k4xRDppPM5W-Lg1RiZSmQstSbqXqm_mpVF9Ao

To claim this, I am signing this object:

@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.
}