Skip to content

Instantly share code, notes, and snippets.

View ffMathy's full-sized avatar
🦄

Mathias Lykkegaard Lorenzen ffMathy

🦄
View GitHub Profile
string?[] nullableStringArray = new []
{
"hello",
null,
"world"
};
var valuesThatAreNotNullTrimmed = nullableStringArray
.Where(x => x != null)
.Select(x => x!.Trim()); //notice the exclamation mark here
string?[] nullableStringArray = new []
{
"hello",
null,
"world"
};
var valuesThatAreNotNullTrimmed = nullableStringArray
.Where(x => x != null)
.Select(x => x.Trim());
bool DoesUserHaveAnAdorableShippingDetailsName(User? user) {
var name = user
.ShippingDetails
.Name;
var namesSplit = name.Split(' ');
var firstName = namesSplit[0];
var lastName = namesSplit[1];
if(lastName.EndsWith("son"))
return false;
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- put these two properties next to the others in your property group -->
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@ffMathy
ffMathy / billion_dollar_mistake.csv
Last active January 23, 2020 19:53
Billion_Dollar_Mistake_Table
Shipping details Name Adorable name NullPointerException
X
X X
X X
X X X
bool DoesUserHaveAnAdorableShippingDetailsName(User user) {
var name = user.ShippingDetails.Name;
var namesSplit = name.Split(' ');
var firstName = namesSplit[0];
var lastName = namesSplit[1];
if(lastName.EndsWith("son"))
return false;
return firstName.StartsWith("Mc") && lastName.StartsWith("Fluffy");
}
@ffMathy
ffMathy / MongoDB_Median.js
Created August 27, 2019 13:06
Median in MongoDB
db.Transactions.aggregate([
{
"$group": {
"_id": null,
"count": {
"$sum": 1
},
"values": {
"$push": "$INSERT_VALUE_TO_GET_MEDIAN_OF_HERE"
}
import { Container, Inject, Injectable } from '@fluffy-spoon/inverse';
import { VueInverse, VueInjectable } from '@fluffy-spoon/inverse-vue';
import Component from 'vue-class-component';
import Vue from 'vue';
//we first create our IOC container.
var container = new Container();
//we provide that to the VueInverse plugin.
const mockedCalculator = TypeMoq.Mock.ofType(RealCalculator);
const calculator = mockedCalculator.object;
mockedCalculator.setup(x => x.isEnabled).throws(new Error());
console.log(calculator.isEnabled); //throws
const mockedCalculator = mock(RealCalculator);
const calculator = instance(mockedCalculator);
when(mockedCalculator.isEnabled).thenThrow(new Error());
console.log(calculator.isEnabled); //throws