Skip to content

Instantly share code, notes, and snippets.

View andrewabest's full-sized avatar

Andrew Best andrewabest

View GitHub Profile
@michaelnoonan
michaelnoonan / gist:5566257
Last active December 6, 2019 01:55
Stop Loss Kata
Stop Loss Kata (original source: https://gist.github.com/gregoryyoung/1500720)
Developing solutions when time is involved is tricky, but testing when time is involved is yet another problem.
A trailing stop loss is a term used in financial trading. For a very in depth explanation you can read here (http://www.investopedia.com/articles/trading/03/080603.asp) and here (http://en.wikipedia.org/wiki/Order_(exchange)#Stop_orders), however we do not need a huge amount of background in order to do the kata as we are going to limit the problem a bit.
Say you buy into a stock at $10. You want it to automatically get sold if the stock goes below $9 to limit your exposure. This threshold is set by subtracting 10% from the original position. The term "trailing" means that if the price goes up to $11 then the sell point becomes $10, if it goes up to $15 then the sell point becomes $14, maintaining the original 10% margin of $1.
The kata is to create something that implements a trailing stop loss and to do it with TDD.
@markryd
markryd / memprofiling.md
Last active August 22, 2016 18:36
Memory profiling with windbg
  • Start up windbg and attach (F6).
  • Make sure you pick the right version (x86/x64) and run as admin if your app is running as admin.
  • Make sure you have the microsoft symbol servers turned on in Visual Studio -> tools -> options -> debugging -> symbols

Load

.loadby sos clr

Dump the heap

@davidfowl
davidfowl / dotnetlayout.md
Last active May 15, 2024 07:06
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
using System.Web.Optimization;
using LOR.PDCA.Web.Infrastructure;
namespace Foo.Bar.Baz
{
public class AppendApplicationVersion : IBundleTransform
{
private readonly IAppSettings _appSettings;
public AppendApplicationVersion(IAppSettings appSettings)
@jackawatts
jackawatts / XmlExpando
Last active August 29, 2015 14:23
Simple XmlExpando
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Xml.Linq;
namespace Expando
{
public static class XmlExpando
{
@droyad
droyad / gist:30097e1f8c02df781ac2
Created August 10, 2015 07:35
Test Autofac registrations by inspection
public abstract class ContainerTestsBase
{
private IContainer _container;
private HashSet<Type> _registeredServices;
readonly Autofac.Core.Activators.Reflection.DefaultConstructorFinder _ctorFinder = new Autofac.Core.Activators.Reflection.DefaultConstructorFinder();
private HashSet<Type> _genericServices;
private HashSet<Type> _registeredConcretions;
[TestFixtureSetUp]
@sheastrickland
sheastrickland / Landlord.cs
Created September 7, 2015 06:22
Landlord: The Com Destroyer. A simple utility class to wrap those nasty little devils.
using System;
using System.Runtime.InteropServices;
namespace Things
{
public static class LandLordExtensions
{
public static LandLord<TWrapped> AsDisposable<TWrapped>(this TWrapped tenant)
{
return new LandLord<TWrapped>(tenant);
@Sam-Martin
Sam-Martin / Invoke-KMSEncrypt-Example.ps1
Last active June 16, 2020 17:53
PowerShell Example for using Invoke-KMSEncrypt and Invoke-KMSDecrypt
# Stolen from http://ctrlf5.net/?p=263 and http://www.dailycoding.com/posts/convert_image_to_base64_string_and_base64_string_to_image.aspx
function ConvertFrom-StringToMemoryStream{
param(
[parameter(Mandatory)]
[string]$InputString
)
$stream = New-Object System.IO.MemoryStream;
$writer = New-Object System.IO.StreamWriter($stream);
$writer.Write($InputString);
@paulirish
paulirish / what-forces-layout.md
Last active May 19, 2024 03:45
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@teyc
teyc / WriteSeq.cs
Last active September 26, 2018 05:12
Pipes objects to Seq
// How to debug your powershell scripts by piping the intermediate results to Seq
// 1. Compile this into WriteSeq.dll
// 2. > Import-Module .\WriteSeq.dll
// 3. > Get-ChildItems C:\ | ? { $_.Name -ilike { "*Program*" } | Write-Seq | Format-Table
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;