Skip to content

Instantly share code, notes, and snippets.

View bgrainger's full-sized avatar

Bradley Grainger bgrainger

View GitHub Profile
@bgrainger
bgrainger / Benchmark.cs
Created July 22, 2014 20:43
WriteInt64 micro-benchmark
using System;
using System.Diagnostics;
namespace WriteInt64Test
{
class Program
{
static void Main()
{
byte[] buf = new byte[8];
FileNotFoundException: Retrieving the COM class factory for component with CLSID {56FDF344-FD6D-11D0-958A-006097C9A090} failed due to the following error: 8007007e The specified module could not be found. (Exception from HRESULT: 0x8007007E). in System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck):-1
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark):26
System.Activator.CreateInstance(Type type, Boolean nonPublic):54
System.Activator.CreateInstance(Type type):0
System.Windows.Window.ApplyTaskbarItemInfo():97
System.Windows.Window.WindowFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolea
@bgrainger
bgrainger / XamlParseException.txt
Created November 23, 2015 18:05
XamlParseException call stack
Message: XamlParseException: Document belongs to another FlowDocumentScrollViewer already. in System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter) ArgumentException: Document belongs to another FlowDocumentScrollViewer already. in System.Windows.Controls.FlowDocumentScrollViewer.DocumentChanged(FlowDocument oldDocument, FlowDocument newDocument)
System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter):540
System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter):41
System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField):271
System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren):42
System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 da
@bgrainger
bgrainger / MonadicTasks.cs
Last active December 15, 2015 15:09
Tasks as monads.
class Program
{
public static void Main()
{
string urls = @"http://www.google.com/
http://www.microsoft.com/
http://www.github.com/
http://news.ycombinator.com/
http://stackoverflow.com/
http://www.logos.com/";
@bgrainger
bgrainger / Squirrel.md
Last active December 27, 2015 07:19
What I had to do to get Squirrel working

Squirrel is the latest name for GitHub's "It's like ClickOnce but Works™" installer. I've been working on a Windows GUI for git blame, and setting up automatic updates with Squirrel seemed like a must-have feature before an initial public release.

However, I had a few problems when trying to add Squirrel to my project, so I thought I'd document what I had to do to get it actually working.

1. Read the Documentation

Keybase proof

I hereby claim:

  • I am bgrainger on github.
  • I am bgrainger (https://keybase.io/bgrainger) on keybase.
  • I have a public key ASC7V4yXHiiwteOw05YmgR1XRHmYGCzhVFPn4hz4lAm5KQo

To claim this, I am signing this object:

@bgrainger
bgrainger / DeleteWithReverseUnorderedSelects.md
Last active April 9, 2016 05:59
SQLite: DELETE can fail with reverse_unordered_selects = true

DELETE can fail with reverse_unordered_selects = true

Under very specific circumstances DELETE FROM x WHERE col = val may fail to delete all rows if PRAGMA reverse_unordered_selects = true; has been executed.

Steps to repro:

Open the test DB (40KB) with SQLite 3.12.1

Run:

using System;
using MySql.Data.MySqlClient;
namespace MySqlCompressBlob
{
class Program
{
static void Main(string[] args)
{
var csb = new MySqlConnectionStringBuilder
using System;
using MySql.Data.MySqlClient;
namespace MySqlCompressBlob
{
class Program
{
static void Main(string[] args)
{
var csb = new MySqlConnectionStringBuilder
public class CpuTimer
{
public void Start()
{
m_sw = Stopwatch.StartNew();
using (var process = Process.GetCurrentProcess())
{
m_total = process.TotalProcessorTime;
m_user = process.UserProcessorTime;
m_kernel = process.PrivilegedProcessorTime;