Skip to content

Instantly share code, notes, and snippets.

@Fitzse
Fitzse / git.config
Created January 2, 2020 17:22
Git Aliases
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
unstage = reset HEAD --
amend = commit --amend -C HEAD
co = checkout
ci = commit
st = status
br = branch
g = grep --break --heading --line-number
hist = log --graph --pretty=format:'%h %ad | %s%d [%an]' --date=short
last = log -1 HEAD
@Fitzse
Fitzse / gist:5969917
Created July 10, 2013 20:18
Extension method to copy all instance parameters with same names/types from once class to another. First one is implementation second is usage.
public static class MyExtensions {
public static U CopyTo<U>(this Object obj){
var objType = obj.GetType();
var newType = typeof(U);
var newInstance = Activator.CreateInstance<U>();
var objProperties = objType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
var newProperties = newType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach(var prop in objProperties){
@Fitzse
Fitzse / gist:5716111
Created June 5, 2013 18:37
ExceptionSafe Monad Example
void Main()
{
Func<int,ExceptionSafe<int>> first = x => (1000 - x).ToSafe();
Func<int,ExceptionSafe<int>> second = x => (100/x).ToSafe();
Func<int,ExceptionSafe<double>> third = x => (0.68 * x).ToSafe();
Func<int,ExceptionSafe<double>> composed = first.Compose(second).Compose(third);
900.ToSafe().ApplyFunction(composed).Dump();
}
@Fitzse
Fitzse / gist:5659026
Last active December 17, 2015 19:18
LINQPad snippet to read a FreeMind mind map file (.mm) and get the nested Node hierarchy. Also writes formatted lines to file (tab indented hierarchy).
void Main()
{
var outputPath = "Something.txt";
var inputPath = "Something.mm";
var nodes = LoadFromFile(inputPath);
var lines = nodes.SelectMany(x => GetPrefixedString(x,""));
lines.Dump();
File.WriteAllLines(outputPath,lines);
}
@Fitzse
Fitzse / gist:3068458
Created July 7, 2012 22:53
Beginning of Conway's Game of Life in Clojure
(ns GameOfLife.core)
(defn next-state [neighbours state]
(cond
(= :dying state) :dead
(and (= :alive state)
(or (= 2 neighbours)
(= 3 neighbours))) :alive
:else :dying))