Skip to content

Instantly share code, notes, and snippets.

View daneb's full-sized avatar
🏠
Working from home

Dane Balia daneb

🏠
Working from home
View GitHub Profile
@daneb
daneb / LocaleHere.php
Last active December 22, 2021 19:25
process_identity_server_token $response
# I see the locale visible in the token but then it disappears
# error_log("[777] Before Prepared Decoded Token: " . print_r($decoded, true));
# $valid_token_data = $this->prepare_token($decoded, $user->ID);
(
[data] => stdClass Object
(
[user] => stdClass Object
(
[id] => 224175
public static ChannelReader<T> CreateScheduleMessenger<T>(ChannelReader<T> channelReader,
Command command)
{
var output = Channel.CreateUnbounded<T>();
Task.Run(async () =>
{
if (command is Command.Get)
{
@daneb
daneb / sample.rs
Created December 31, 2019 09:35
Ownership in Rust with Pluralize
fn main() {
let s = String::from("book");
// Add code here that calls the pluralize function
let many = pluralize(s.clone());
println!(
"I have one {}, you have two {}",
s,
many,
@daneb
daneb / typeconstraint.cs
Created August 2, 2019 13:57
Type Constraint
public sealed class MyTuple<T1, T2> : IEquatable<MyTuple<T1, T2>>
{
// Create Instance for Comparing Against Self.
// If we used type against Interface we can compare two values
private static readonly IEqualityComparer<T1> FirstComparer = EqualityComparer<T1>.Default;
private static readonly IEqualityComparer<T2> SecondComparer = EqualityComparer<T2>.Default;
private readonly T1 _first;
private readonly T2 _second;
@daneb
daneb / genericSwap.cs
Created July 19, 2019 09:41
Generic Swap
// Generic
public void Swap<T>(ref T lhs, ref T rhs)
{
T temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
@daneb
daneb / callIt.cs
Last active July 19, 2019 10:27
Calling Swap
int a = 1;
int b = 2;
string aa = "Hello";
string bb = "World";
Swap<int>(ref a, ref b);
Swap(ref a, ref b); // we can even ignore being explicit about the type.
Swap(ref aa, ref bb);
@daneb
daneb / swap.cs
Last active July 19, 2019 09:40
Generics
public void SwapInt(ref int lhs,ref int rhs)
{
int temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
public void SwapString(ref string lhs, ref string rhs)
{
@daneb
daneb / Safe.cs
Created June 21, 2019 12:49
Type System Safe for C#
[Fact]
public void ThisIsSafe()
{
int a = 5;
int b = a + 2; //OK
bool test = true;
// Error. Operator '+' cannot be applied to operands of type 'int' and 'bool'.
int c = a + test;
@daneb
daneb / ExplicitTyping.cs
Created June 21, 2019 12:38
Explicit Typing Linked to Blog Post
public class ExplicitTyping
{
// This would have failed in C# 1 and 2, prior to the introduction of var in 3.0
// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var
[Fact]
public void ImplicitTypingWillFail()
{
var s = "Hello";
var x = s.Length;
var twiceX = x * 2;
@daneb
daneb / StaticallyTypedCSharp.cs
Last active June 21, 2019 12:25
Statically Typed C#
public class StaticallyTypedCSharp
{
[Fact]
public void StaticTypeWontCompile()
{
Object o = "Hello";
Assert.True(o.Length == 5);
}