Skip to content

Instantly share code, notes, and snippets.

@toddlucas
toddlucas / DoubleDispatch.cs
Last active December 20, 2021 18:58
Double dispatch example from Wikipedia in C#
// https://en.wikipedia.org/wiki/Double_dispatch
using static System.Console;
WriteLine("Example 1. Method overloading");
Asteroid theAsteroid = new();
SpaceShip theSpaceShip = new();
ApolloSpacecraft theApolloSpacecraft = new();
// Asteroid hit a SpaceShip
@toddlucas
toddlucas / gulpfile-starter.js
Last active December 21, 2020 00:58
Minimal gulpfile to copy Bootstrap
/// <binding ProjectOpened='build' />
"use strict";
const gulp = require('gulp'),
merge = require('merge-stream');
const roots = {
node_modules: "./node_modules/",
wwwroot: "./wwwroot/",
wwwlib: "./wwwroot/lib/"
@toddlucas
toddlucas / github-backup.sh
Created February 1, 2020 21:49
Back up GitHub repos
#!/bin/bash
USERNAME='xyz'
# https://news.ycombinator.com/item?id=22210681
for i in `seq 1 20`;
do
curl --fail -s https://api.github.com/users/$USERNAME/repos?page=$i | jq '.[] | .clone_url' | xargs -t -n1 git clone
sleep 1
done
@toddlucas
toddlucas / gulpfile-fragment.js
Last active December 23, 2019 17:09
Build multiple app bundles with Gulp and Browserify (vendor bundle not included here)
const paths = {
entries: {
ts: [
"Scripts/app.ts"
]
},
...
};
@toddlucas
toddlucas / app.tsx
Created December 17, 2019 08:18
Minimalist TypeScript React Redux additions
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { Router } from "react-router-dom";
import { RouteMap } from "./routes";
import store from "./store";
import history from "./history";
ReactDOM.render((
@toddlucas
toddlucas / gulpfile.js
Last active December 17, 2019 07:29
Add TypeScript to gulpfile
/// <binding ProjectOpened='default' />
'use strict';
...
const tslint = require("gulp-tslint");
const tsify = require("tsify");
const source = require("vinyl-source-stream");
const merge = require('merge-stream');
const browserify = require("browserify");
@toddlucas
toddlucas / .gitignore
Created December 17, 2019 02:34
Gulp 4 with bootstrap 4
*.user
.DS_Store
**/node_modules/*
**/obj/*
**/bin/*
**/.vs/*
**/fontawesome/*
@toddlucas
toddlucas / maybe.ts
Last active October 7, 2019 21:03
TypeScript Option/Maybe type
export class Some<T> {
public some: true = true;
constructor(public value: T) { }
}
export class None {
public some: false = false;
}
export type Maybe<T> = Some<T> | None;
@toddlucas
toddlucas / routes-to-csv.py
Created April 1, 2019 19:03
Takes a file generated by AspNetCore.RouteAnalyzer and converts to a CSV.
# Takes a file generated by AspNetCore.RouteAnalyzer and converts to a CSV.
# Note: you'll need to remove the RouteInformation prefix and quote the object
# keys to transform the output into legitimate JSON before using.
import sys
import json
import re
# MyController.Index(My.Namespace.Controllers.MyController.Index (My.AssemblyName))
invocationRegex = re.compile(r"(\w+)\.(\w+) \(([\w\.]+) \(([\w\.]+)\)\)")
@toddlucas
toddlucas / jour.py
Last active December 24, 2023 23:47
A simple script to edit a dated file for journalling or note taking
import sys
import time
import os
import argparse
import configparser
journal_dirname = ""
journal_cwd = ""
journal_date = ""
journal_filename = ""