Skip to content

Instantly share code, notes, and snippets.

View lomholdt's full-sized avatar

Jonas Lomholdt lomholdt

View GitHub Profile
if (!(person is null)) {
throw new ArgumentNullException(nameof(person));
}
if (person is null == false) {
throw new ArgumentNullException(nameof(person));
}
@lomholdt
lomholdt / example.cs
Created September 11, 2018 18:35
Overriden == operator
if (person is null) {
throw new ArgumentNullException(nameof(person));
}
@lomholdt
lomholdt / example.cs
Created September 11, 2018 18:28
Overriden == operator
if (person == null) {
throw new ArgumentNullException(nameof(person));
}
@lomholdt
lomholdt / example.cs
Last active September 11, 2018 18:27
Overriden == operator
class Person
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
public Person(string firstName, string lastName) => (FirstName, LastName) = (firstName, lastName);
public static bool operator ==(Person a, Person b)
{
@lomholdt
lomholdt / example.cs
Created September 11, 2018 18:23
Overriden == operator
class Program
{
static void Main(string[] args)
{
var person1 = new Person("Jonas", "Lomholdt");
var personN = new Person("Jonas", "Lomholdt");
var person2 = new Person("Mike", "Tyson");
Person person3 = null;
// Show that comparing instances is working
@lomholdt
lomholdt / Directory.Build.targets
Created July 21, 2018 11:24 — forked from dasMulli/Directory.Build.targets
Allow `dotnet test` to be run from solution directory
<Project>
<Target Name="VSTestIfTestProject">
<CallTarget Targets="VSTest" Condition="'$(IsTestProject)' == 'true'" />
</Target>
</Project>
@lomholdt
lomholdt / .tmux.conf
Last active October 10, 2017 13:21
Tmux conf
# remap prefix from 'C-b' to 'C-a'
# unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
######################
### DESIGN CHANGES ###
######################
# panes
@lomholdt
lomholdt / tmux-git.sh
Created October 9, 2017 21:15
Add git branch to tmux status bar
#!/bin/bash
# Current path
current_path="$(tmux display-message -p -F "#{pane_current_path}")"
# get the current branch
function get_branch {
value=$(cd $current_path; git rev-parse --abbrev-ref HEAD)
echo $value
}
@lomholdt
lomholdt / .tmux.conf
Last active January 7, 2023 05:48
Add git branch to tmux status bar
set -g status-right '#(cd #{pane_current_path}; git rev-parse --abbrev-ref HEAD)'
@lomholdt
lomholdt / array_key_exists_recursive.php
Last active November 20, 2018 13:38
A recursive implementation of array_key_exists
<?php
function array_key_exists_recursive($key, $arr)
{
if (array_key_exists($key, $arr)) {
return true;
}
foreach ($arr as $currentKey => $value) {
if (is_array($value)) {
return array_key_exists_recursive($key, $value);