Skip to content

Instantly share code, notes, and snippets.

@dlumpp
dlumpp / rolling-stone-greatest-sci-fi-scrape.js
Created January 2, 2024 00:34
A script to scrape the Rolling Stone Greatest Science Fiction Movies of All Time article
/* A script to scrape the Rolling Stone Greatest Science Fiction Movies of All Time article
at https://www.rollingstone.com/tv-movies/tv-movie-lists/best-sci-fi-movies-1234893930/
Paste into browser and hit enter to avoid all the scrolling they want you to do.
You'll have to click 'Load More' a couple times the bottom to get all of them.
Results are below the code. */
const films = [];
const stripFancyQuotes = (str) => {
// values look like: '‘Westworld’ (1973)'
return str.replace(/‘|’/g, '');
@dlumpp
dlumpp / dotnet-family-tree.md
Created March 9, 2023 16:32
.NET Family Tree

.NET Family Tree

stateDiagram-v2
    %% https://en.wikipedia.org/wiki/.NET_Framework_version_history
    %% https://en.wikipedia.org/wiki/.NET#History
    %% TFMs https://learn.microsoft.com/en-us/dotnet/standard/frameworks
    net40: 4.0
    net45: 4.5
 net48: 4.8
@dlumpp
dlumpp / ListHelper.cs
Created May 18, 2022 14:11
Simpler syntax for creating single-item lists
using System.Linq;
namespace System.Collections.Generic;
public static class List
{
public static List<T> From<T>(T value) => new(1) { value };
public static List<T> From<T>(params T[] values) => values.ToList();
}
@dlumpp
dlumpp / CalculatorTestTheoryData.cs
Created February 12, 2021 18:11
[xUnit TheoryData] Strongly typed theory test data #testing #xunit
// https://andrewlock.net/creating-strongly-typed-xunit-theory-test-data-with-theorydata/
public class CalculatorTestData : TheoryData<int, int, int>
{
public CalculatorTestData()
{
Add(1, 2, 3);
Add(-4, -6, -10);
Add(-2, 2, 0);
Add(int.MinValue, -1, int.MaxValue);
Add(1.5, 2.3m, "The value"); // will not compile!
@dlumpp
dlumpp / EmbeddedResources.cs
Created February 1, 2021 14:32
[Read Embedded Resources] Read string resources embedded in assembly #testing
using System;
using System.IO;
using System.Reflection;
public static class EmbeddedResources
{
public static string Read(string resourceName)
{
var assembly = Assembly.GetExecutingAssembly();
var defaultNamespace = assembly.GetName().Name;
@dlumpp
dlumpp / SurroundWithParentheses.snippet
Created October 25, 2019 15:36
Surround With Parentheses - Visual Studio Surrounds With Snippet
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>parens</Title>
<Shortcut>parens</Shortcut>
<Description>Code snippet to surround a block of code with parentheses</Description>
<Author>Dan Lumpp</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@dlumpp
dlumpp / IIndexAccessible.cs
Created August 24, 2018 16:10
[IIndexAccessible] Indexed property interface that I wish was part of .NET so that Dictionary could implement it
public interface IIndexAccessible<TKey, TValue>
{
TValue this[TKey index] { get; }
}
@dlumpp
dlumpp / Move-Many-Patterns.ps1
Created July 10, 2018 18:44
[Move Files by Multiple Patterns] Move all files matching any of an array of wildcard patterns #filesystem
# Moves only files matching any wildcard in the array
# PowerShell has a bug that throws errors for each non-matching file
# but it still works and moves the matches
# https://github.com/PowerShell/PowerShell/issues/2385
$filters = @("*.pdf", "*.jpg")
# alternatively read in filters from a text file, separated by newlines
# $filterFile = "C:\filters.txt"
# $filters = Get-Content -Path $filterFile
@dlumpp
dlumpp / Count-Child-Items.ps1
Last active July 9, 2018 16:53
[Count Files] Count all files and folders in a folder #filesystems
Write-Host ( Get-ChildItem C:\somefolder | Measure-Object ).Count
@dlumpp
dlumpp / ExecutionTimer.cs
Last active July 9, 2018 16:45
[ExecutionTimer] A code timer using an IDisposable wrapper around a Stopwatch that allows you to add a using statement above the statement you want to time.
using System;
using System.Diagnostics;
namespace Diagnostics
{
public class ExecutionTimer : IDisposable
{
private Stopwatch stopwatch;
private string name;
private Action<string> outputAction;