Skip to content

Instantly share code, notes, and snippets.

@TheWass
TheWass / abortablepromise.ts
Last active February 7, 2023 19:26
Helpful TS Extensions
/**
* This pairs an ES6 promise and the AbortController together.
* Useful where you need to stop the promise from continuing externally.
* Note: Async/await will not work with this class. Use the toAwaitable function to convert it back to a standard promise.
*/
export class AbortablePromise<T> implements PromiseLike<T> {
private abortController: AbortController;
private promiseWrapper: Promise<T>;
private cancelEvent!: (reason?: unknown) => void;
@TheWass
TheWass / console.hex.ts
Created June 11, 2020 20:44 — forked from NielsLeenheer/console.hex.js
console.hex
/* eslint-disable */
// @ts-nocheck
interface Console {
hex(data: any): void;
}
console.hex = (d) => console.log((Object(d).buffer instanceof ArrayBuffer ? new Uint8Array(d.buffer) :
typeof d === 'string' ? (new TextEncoder('utf-8')).encode(d) :
new Uint8ClampedArray(d)).reduce((p, c, i, a) => p + (i % 16 === 0 ? i.toString(16).padStart(6, 0) + ' ' : ' ') +
c.toString(16).padStart(2, 0) + (i === a.length - 1 || i % 16 === 15 ?
@TheWass
TheWass / MacSetup.md
Last active March 30, 2018 16:58
What to do when setting up a Mac:

Mac Setup and Configuration Instructions

Install App Store Apps

Install Xcode, Remote Desktop, and Slack from the App Store
Wait until Xcode is complete
Run the following:

touch ~/.bash_profile
xcode-select --install

defaults write com.apple.finder AppleShowAllFiles YES

#!/usr/bin/env node
/**
* This cordova hook checks to see if the developer is building a release version,
* but not in a production environment.
*
* Add this to config.xml
* <hook src="envcheck.js" type="before_prepare" />
* <hook src="envcheck.js" type="after_build" />
*/
function coerceIntWithDefault(test) {
test = (test !== 0) ? (test || 42) : 0;
return test;
};
var test;
coerceIntWithDefault(test);
// test === 42;
test = 78;
coerceIntWithDefault(test);
@TheWass
TheWass / twFilters.js
Last active September 30, 2016 14:28
Custom AngularJS modules
angular.module('twFilters', [])
.filter('unique', function () {
return function (arr, field) {
var o = {}, i, l = (arr) ? arr.length : 0, r = [];
for (i = 0; i < l; i += 1) {
o[arr[i][field]] = arr[i];
}
for (i in o) {
r.push(o[i]);
}
@TheWass
TheWass / snippets.cs
Last active October 27, 2016 21:40
Useful Code snippets
//Make a dictionary of distinct records
Dictionary<int, Record> records = findRecords(keys)
.GroupBy(r => r.keyid)
.ToDictionary(g => g.Key, g => g.First());
records.TryGetValue(key, out record);
//Make groups from lines
Lines.GroupBy(l => l.ReleaseDate, (k, g) => new { Key = k, Lines = g.ToList() } ).OrderBy(g => g.Key).ToList();
// Find and remove duplicates
git init
git config --add user.email lord.d35ruct0@gmail.com
git config --add user.name thewass
echo "# readme" >> readme.md
git add .
git commit -m "Initial Commit"
@TheWass
TheWass / gitshortcuts.md
Last active August 6, 2018 15:32
This is a list of useful git shortcuts to put into your global config.
  1. Run git config -e --global
  2. Paste this into the file:
[alias]
        superlog = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blu$        supertimelog = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset$        co = checkout
        br = branch
        ci = commit
        st = status
        psuh = push
 spuh = push
@TheWass
TheWass / commentcode.c
Last active August 29, 2015 14:18
I came across a nifty way of quickly toggling C-style code: Simply, add a slash to comment/uncomment a block.
/*
Code block
//*/
//* <--Added a slash here!
Code block
//*/
/*