Skip to content

Instantly share code, notes, and snippets.

View taylorhutchison's full-sized avatar
💭
Working on the Geode library

Taylor Hutchison taylorhutchison

💭
Working on the Geode library
View GitHub Profile
@taylorhutchison
taylorhutchison / profile.ps1
Last active November 23, 2019 17:34
A powershell prompt function for showing current git branch.
function Prompt {
Write-Host "PS $($executionContext.SessionState.Path.CurrentLocation)" -NoNewline
$head = git symbolic-ref HEAD
if($null -ne $head) {
Write-Host " " -NoNewline
Write-Host "[$($head.substring($head.LastIndexOf("/") +1))]" -ForegroundColor Yellow -BackgroundColor Red -NoNewline
}
"$('>' * ($nestedPromptLevel + 1)) "
}
C# 2 hrs 13 mins ████████░░░░░░░░░░░░░ 38.6%
HTML 1 hr 24 mins █████▏░░░░░░░░░░░░░░░ 24.4%
TypeScript 1 hr 8 mins ████▏░░░░░░░░░░░░░░░░ 19.8%
SQL 40 mins ██▍░░░░░░░░░░░░░░░░░░ 11.7%
Other 8 mins ▌░░░░░░░░░░░░░░░░░░░░ 2.6%
@taylorhutchison
taylorhutchison / webpack.config.js
Created November 8, 2020 15:02
Basic Webpack Setup for TypeScript
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
// npm install typescript webpack webpack-cli html-webpack-plugin clean-webpack-plugin copy-webpack-plugin ts-loader file-loader webpack-dev-server
module.exports = {
mode: 'development',
entry: {
@taylorhutchison
taylorhutchison / SnackbarInterceptor.ts
Last active December 2, 2022 13:17
An Angular interceptor to show a Material Snackbar on success or error of an HTTP POST/PUT.
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor,
HttpResponse
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError, tap, } from 'rxjs/operators';
@taylorhutchison
taylorhutchison / ADAL_with_vanilla_JS.md
Created April 29, 2021 21:13 — forked from psignoret/ADAL_with_vanilla_JS.md
Minimal sample app using ADAL.JS and vanilla JavaScript

Using ADAL.JS with vanilla JavaScript

A minimal sample app using ADAL.JS and plain old vanilla JavaScript to obtain an access token from Azure Active Directory and use that access token to make an API request. In this case, the API we're requesting a token for is the Microsoft Graph API, which is used to retrieve the signed-in user's basic profile.

You can see (and test) this live at: https://bl.ocks.org/psignoret/raw/50e88652ae5cb6cc157c09857e3ba87f/

@taylorhutchison
taylorhutchison / CTE.sql
Created June 27, 2021 19:31
Using Common Table Expressions to recursively grab employee reporting structures
-- Traces up from leaf to root
WITH org(id, name, title, department, manager) AS (
SELECT
id, name, title, department, manager
FROM
employee
WHERE id = '9E033E7A-9D49-445F-BB8E-C6B777DFC19E'
UNION ALL
SELECT
e.id, e.name, e.title, e.department, e.manager
@taylorhutchison
taylorhutchison / TaskLock.cs
Created December 14, 2021 03:16
C# example of using a lock to prevent multiple threads from starting a long running task when it only needs to be run once.
// C# top-level statements
// The goal of this code is to create a method that simulates a long-running task that
// only needs to be computed once, but that multiple threads might request before the computation is finished.
// It uses a lock object to check if the computation has been requested. If not it starts the work.
var t1 = Task.Run(async () =>
{
var result = await TaskRunner.LongRunningTask();
Console.WriteLine(result);
@taylorhutchison
taylorhutchison / Program.cs
Created December 27, 2021 05:22
Output the distribution of English words by their first letter (ignoring case).
// Steps to reproduce assuming you have dotnet installed (using version 6).
// mkdir english-word-distribution && cd english-word-distribution
// dotnet new console
// curl https://raw.githubusercontent.com/dwyl/english-words/master/words.txt --output words.txt
// dotnet run
var letterCount = new Dictionary<char, int>();
foreach (var word in File.ReadLines("words.txt"))
{
var letter = word.ToLower()[0];
if (!letterCount.ContainsKey(letter))
@taylorhutchison
taylorhutchison / Program.cs
Last active April 27, 2022 13:51
Writing to the log stream in a Window Azure App Service.
// This is a ASP.NET 6 sample showing how to write to the log stream in a Window Azure App Service.
// It seems standard out (stdout) is disabled in a Window Azure App Service.
// The key for me was adding the Microsoft.Extensions.Logging.AzureAppServices package
// To see logs in the Log Stream
// 1. go to "App Service logs" panel under monitoring
// 2. turn on Application logging (Filesystem)
// 3. set the level to Verbose or whatever is appropriate for the level of logging you want to see.
// Note: This will automatically turn back off after 12 hours by design.
// 4. Now you can see the logs in the Log Stream panel of your App Service.
@taylorhutchison
taylorhutchison / local.settings.json
Created January 3, 2023 03:18
Allow CORS when running Azure Functions locally
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"Host": {
"CORS": "*"
}
}