Skip to content

Instantly share code, notes, and snippets.

@stevegreatrex
stevegreatrex / useAsyncEffect.tsx
Created July 11, 2019 06:10
Async Effect Hook
interface LoadStarted { type: 'STARTED'; }
interface LoadComplete<TResult> { type: 'COMPLETE'; result: TResult; }
interface LoadFailed { type: 'FAILED'; error: any; }
type LoadAction<TResult> = LoadStarted | LoadComplete<TResult> | LoadFailed;
type AsyncFunction<TResult> = () => Promise<TResult>;
interface State<TResult> {
isLoading: boolean;
result?: TResult;
error?: any;
@stevegreatrex
stevegreatrex / clean-up-merged-branches.ps
Last active May 10, 2017 13:39
Clean up merged git branches in powershell
git branch -vv | %{$_.trim()} | ?{$_ -match 'origin/([a-zA-Z\-]+): gone'} | %{git branch -D $Matches[1]}
@stevegreatrex
stevegreatrex / 1.something
Last active March 9, 2017 06:40
Embed test
// One
@stevegreatrex
stevegreatrex / MyD3Component.ts
Created January 5, 2017 17:05
Cleaning up resources with MutationObserver: With MutationObserver
class MyD3Component {
constructor(targetElement: HTMLElement) {
//create some resources that need to be cleaned up
const observer = new MutationObserver(mutations => {
//get a flattened list of all removed elements
const removedElements = mutations.map(m => m.removedNodes)
.reduce((a, b) => a.concat(Array.prototype.slice.apply(b)), []);
//dispose if my target element was removed
@stevegreatrex
stevegreatrex / MyD3Component.ts
Created January 5, 2017 17:04
Cleaning up resources with MutationObserver: Initial Version
class MyD3Component {
constructor(targetElement: HTMLElement) {
//create some resources that need to be cleaned up
}
dispose() {
//clean up my resources
}
}
@stevegreatrex
stevegreatrex / MyD3Component.ts
Last active January 5, 2017 17:08
Cleaning up resources with MutationObserver: Final Version
class MyD3Component {
private observer: MutationObserver;
constructor(targetElement: HTMLElement) {
//create some resources that need to be cleaned up
this.observer = new MutationObserver(mutations => {
//get a flattened list of all removed elements
const removedElements = mutations.map(m => m.removedNodes)
.reduce((a, b) => a.concat(Array.prototype.slice.apply(b)), []);
@stevegreatrex
stevegreatrex / ExampleFixture.cs
Created January 4, 2017 06:45
nCrunch Bug Repro
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace nCrunchBugRepro
{
@stevegreatrex
stevegreatrex / Attachment
Last active August 29, 2015 14:19
Streaming Uploads to Azure
public class Attachment
{
/// <summary>
/// Gets the unique identifier for this attachment.
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// Gets the file name for this attachment.
/// </summary>
@stevegreatrex
stevegreatrex / WhenConverter.cs
Created October 4, 2012 19:22
Reusable Conditional WPF Converter
/// <summary>
/// A converter class used to return conditional values based on the binding value.
/// </summary>
public class When : MarkupExtension, IValueConverter
{
#region Public Properties
/// <summary>
/// Gets or sets the value to which the resolved value will be compared.
/// </summary>
/// <value>