Skip to content

Instantly share code, notes, and snippets.

View twofingerrightclick's full-sized avatar

Austen Frostad twofingerrightclick

View GitHub Profile
@twofingerrightclick
twofingerrightclick / OnInitializedAsyncExample.razor
Last active December 8, 2023 18:53
An example of how to handle null when using OnInitializedAsync to fetch data to display in a Blazor component
<h2>@Config?.WelcomeMessage</h2>
@code {
protected ConfigObject? Config { get; set; }
protected int RenderCount { get; set; }
protected override async Task OnInitializedAsync()
{
@twofingerrightclick
twofingerrightclick / variablePrimer.ps1
Last active February 4, 2023 00:13
Learn a bit about variables in PowerShell by running this script
function Name {
#what is the output here?
write-host $name # $name is "foo" because it is the global variable $name
$name = "bar" #the global $name cannot be modified here and so this is actually creating
# a local variable, same as $local:name = "bar".
# in other words it will create a local variable if you try to modify a variable in a child scope
# what is the output here?
write-host $name # so now $name is implied to be the $local one (because a $local:name exists) and not the $script one is "bar"
# powershell will get the local variable if it exists, otherwise it will get the script variable otherwise the global variable...
#what is the output here?
@twofingerrightclick
twofingerrightclick / brokenInto2parts.cs
Last active October 28, 2022 20:58
Whats the differnce between these 2 EntityFramework v6 queries?
namespace Foo {
public class Blah {
public IEnumerable<CustomerServiceReportItem> LoadCustomerServicesReportData(int year, int month)
{
DateTimeOffset startDate = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero);
DateTimeOffset cutoffDate = new DateTimeOffset(1900, 1, 1, 0, 0, 0, TimeSpan.Zero);
var isPudUser = (_CurrentUser == null || _CurrentUser.IsPudUser);
@twofingerrightclick
twofingerrightclick / Listing 12.5.cs
Created September 8, 2021 23:27
Listing 12.5: Declaring a Nullable Type That Contains a Value Property of Type object
struct Nullable
{
/// <summary>
/// Provides the value when HasValue returns true
/// </summary>
public object Value{ get; private set; }
/// <summary>
/// Indicates whether there is a value or whether
/// the value is "null"
@twofingerrightclick
twofingerrightclick / Listing 12.4.cs
Created September 8, 2021 23:24
Listing 12.4: Declaring Versions of Various Value Types That Store null
struct NullableInt
{
/// <summary>
/// Provides the value when HasValue returns true
/// </summary>
public int Value{ get; private set; }
/// <summary>
/// Indicates whether there is a value or whether
/// the value is "null"
@twofingerrightclick
twofingerrightclick / Listing 12.3.cs
Created September 8, 2021 23:14
Listing 12.3: Defining a Specialized Stack Class
public class CellStack
{
public virtual Cell Pop();
public virtual void Push(Cell cell);
// ...
}
@twofingerrightclick
twofingerrightclick / Listing12.2.cs
Created September 8, 2021 22:46
Listing 12.2: Supporting Undo in a Program Similar to an Etch A Sketch Toy
using System.Collections;
class Program
{
// ...
public void Sketch()
{
Stack path = new Stack();
Cell currentPosition;
ConsoleKeyInfo key; // Added in C# 2.0
@twofingerrightclick
twofingerrightclick / Listing12.1.cs
Created September 8, 2021 22:40
Listing 12.1: The System.Collections.Stack Method Signatures
public class Stack
{
public virtual object Pop() { ... }
public virtual void Push(object obj) { ... }
// ...
}
@twofingerrightclick
twofingerrightclick / Help.js
Created September 8, 2021 20:56
Testing Gist
var x= 1;