Skip to content

Instantly share code, notes, and snippets.

View emptyother's full-sized avatar

Tom A. Vibeto emptyother

View GitHub Profile
@emptyother
emptyother / out-notepad.ps1
Last active July 22, 2017 12:00
Pipe powershell data to notepad
Param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
$InputObject
)
begin {
$tempfile = [System.IO.Path]::GetTempFileName();
$collection = @();
}
process {
@emptyother
emptyother / Process-Paths.psm1
Last active November 5, 2017 17:25
Powershell template for functions that takes a list of paths or files
#requires -version 5
<#
.Synopsis
Processes a path
.Description
This is a template for creating Powershell functions that processes paths
.Parameter Path
The path(s) to process
.Inputs
System.IO.DirectoryInfo
@emptyother
emptyother / Guid.ts
Last active July 4, 2023 21:00
GUID class for Typescript
class Guid {
public static newGuid(): Guid {
return new Guid(crypto.randomUUID());
// Old IE supported way:
/*return new Guid('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = Math.random() * 16 | 0;
const v = (c == 'x') ? r : (r & 0x3 | 0x8);
return v.toString(16);
}));*/
@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
|
@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 / 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 / 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 / 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 / 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 / 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]>
};