Skip to content

Instantly share code, notes, and snippets.

View John-Paul-R's full-sized avatar

John Paul John-Paul-R

View GitHub Profile
@John-Paul-R
John-Paul-R / intro_numeric_promotion.md
Last active November 19, 2023 00:14
C#: math, types, and numeric promotion
View intro_numeric_promotion.md

doing an operation on two numbers will give you a different output type depending on what the types of the operands are.

  • an "operation" is something like "addition" (+) or division (/).
  • an "operand" is one of the things you're doing the operation on.

for example, in 3 - 2, 3 is the first operand, 2 is the second operand, and subtraction (-) is the operation.

For our case, we're working with 2 types:

@John-Paul-R
John-Paul-R / delegates-and-events.md
Created November 18, 2023 17:34
C#: Comparing combined Delegates and Events
View delegates-and-events.md

I think what might clarify is how events work. (Note, this is a long answer, tailored to your example. For something shorter, but less specific, see https://stackoverflow.com/a/33964976/8105643)

The event keyword is really just a nice syntax for setting up an EventHandler Delegate.

Now we understand that events are just special syntax delegates, we can explain how subscribing to an event actually works, and show how the two examples you gave are actually quite similar:

In your first example, you have essentially this situation:

public class DelegateCombineExample {
@John-Paul-R
John-Paul-R / keybase.md
Created August 10, 2023 19:39
keybase.md
View keybase.md

Keybase proof

I hereby claim:

  • I am John-Paul-R on github.
  • I am john_paul_r (https://keybase.io/john_paul_r) on keybase.
  • I have a public key whose fingerprint is 522F F5DE A709 6C4A AD1A 3BEC 7B98 1822 047F E953

To claim this, I am signing this object:

@John-Paul-R
John-Paul-R / FlexVerBenchmarkHarness.csproj
Created May 3, 2023 05:00
FlexVerBenchmarkHarness.csproj
View FlexVerBenchmarkHarness.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
@John-Paul-R
John-Paul-R / FabricModList.md
Last active December 2, 2023 00:37
private modlist gist
View FabricModList.md

Fabric Mod List

This page contains a list of the current Minecraft Fabric mods. (As of 2022-11-27 00:31:01 Timezone: UTC+0000 (GMT))

To search for mods by name, category, or download count, visit the website, fibermc.com!

Note: You can view a mod's source files by following the "Source" link on its CurseForge or Modrinth page, assuming that the mod's creator has made such files public.

There are currently 9508 mods in this list.

@John-Paul-R
John-Paul-R / filter_props_by_type.ts
Last active May 7, 2022 02:43
Utility types for constructing a type from an existing type, including only properties that are of a specified type. Can be applied recursively to child objects.
View filter_props_by_type.ts
type FilteredKeys<T, U> = { [P in keyof T]: T[P] extends U ? P : never }[keyof T];
enum Color {
Red, Green, Blue,
}
type PropsOfType<T, U> = {
[K in FilteredKeys<T, U>]: T[K]
};
@John-Paul-R
John-Paul-R / Program.cs
Last active February 3, 2022 19:10
Updated Dictionary Benchmarks
View Program.cs
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
@John-Paul-R
John-Paul-R / Program.cs
Last active January 31, 2022 18:13
Comparison of `Dictionary`, `ConcurrentDictionary`, and `ImmutableDictionary` read performance at differing collection sizes.
View Program.cs
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
namespace Bench_Dictionaries
{
@John-Paul-R
John-Paul-R / TopCommand.java
Created January 9, 2022 19:18
Get the "top" block at a given position using world.raycast.
View TopCommand.java
public class TopCommand implements Command<ServerCommandSource> {
@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();
ServerPlayerEntity player = source.getPlayer();
World world = source.getWorld();
Vec3d playerPos = player.getPos();
int new_y;
double new_x = playerPos.x;
@John-Paul-R
John-Paul-R / InGameHudAccess.java
Last active January 9, 2022 02:04
Client Chat Listener Mixin
View InGameHudAccess.java
package com.packagename.access;
import net.minecraft.client.gui.ClientChatListener;
import net.minecraft.network.MessageType;
public interface InGameHudAccess {
void registerChatListener(MessageType messageType, ClientChatListener listener);
}