Skip to content

Instantly share code, notes, and snippets.

View iansan5653's full-sized avatar

Ian Sanders iansan5653

View GitHub Profile
@iansan5653
iansan5653 / Apple.scala
Created October 29, 2020 01:21
Create a Case Class
case class Apple(color: String) extends Fruit {
val isSour: Boolean = color == "green"
}
type JSONValue =
| string
| number
| boolean
| null
| JSONValue[]
| {[key: string]: JSONValue};
type ParsedJSON = {[key: string]: JSONValue};
function assertMatchesSchema<Schema extends yup.ObjectSchema>(
/**
* Stricter version of `Omit`:
* Construct a type with the properties of T except for those in type K.
*/
export type OmitStrict<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
@iansan5653
iansan5653 / JSONTypes.ts
Created February 11, 2020 21:10
Typescript types for parsed JSON data
/** Any allowed JSON member value. */
export type JSONValue =
| string
| number
| boolean
| null
| JSONValue[]
| {[key: string]: JSONValue};
/** The generic result of parsing any valid JSON data. */
export type ParsedJSON = Record<string, JSONValue>;
function getSumOfSquaresOfDigits(n) {
let _n = n;
let result = 0;
while (_n > 0) {
result += (_n % 10) ** 2;
_n = Math.floor(_n / 10);
}
return result;
}
@iansan5653
iansan5653 / shortcut_target.txt
Created August 23, 2019 16:06
Windows Snipping Tool Fast Shortcut
C:\Windows\System32\SnippingTool.exe /clip
interface ExampleQuery {
name?: string;
age?: number;
child?: {
id?: number;
name?: string;
};
}
const GET = Symbol();
@iansan5653
iansan5653 / media.ahk
Created August 16, 2019 18:08
AutoHotKey to map Windows media keys: scroll lock -> skip, pause/break -> pause/play.
sc046::Media_Next
Pause::Media_Play_Pause
@iansan5653
iansan5653 / gulpfile.js
Created August 14, 2019 15:33
Configuration for packing electron app into a single exe file
/* eslint @typescript-eslint/no-var-requires: 0 */
const gulp = require("gulp");
const ts = require("gulp-typescript");
const clean = require("gulp-clean");
const replace = require("gulp-replace");
const tsProject = ts.createProject("tsconfig.json");
const paths = {
web: ["src/*.html", "src/*.css"]
@iansan5653
iansan5653 / promise-parse.ts
Created July 17, 2019 13:33
Promisified csv-parse method
/**
* Promisified `parse()` from `csv-parse`.
* @param input The raw CSV data.
* @param options The options object to pass through to the `parse()` function.
* @returns Promise that resolves upon completion with an object containing the
* results and information about those results.
* @see {@link https://csv.js.org/parse/} For info about the options and info
* objects.
*/
export function promiseParse(