Skip to content

Instantly share code, notes, and snippets.

@thomaslevesque
thomaslevesque / GitHubMarkdownShortcuts.user.js
Last active April 14, 2021 00:33
Keyboard shortcuts for GitHub markdown editor
// ==UserScript==
// @name GitHub Markdown shortcuts
// @namespace ThomasLevesque
// @include https://github.com/*
// @include https://gist.github.com/*
// @version 1
// @grant none
// ==/UserScript==
@thomaslevesque
thomaslevesque / gist:e1ccd9cef0a47e609a46
Created January 15, 2016 13:34
aglio dependencies... OMG!
└─┬ aglio@2.2.0
├─┬ aglio-theme-olio@1.6.2
│ ├── coffee-script@1.10.0
│ ├── highlight.js@8.9.1
│ ├─┬ jade@1.11.0
│ │ ├── character-parser@1.2.1
│ │ ├─┬ clean-css@3.4.9
│ │ │ └─┬ commander@2.8.1
│ │ │ └── graceful-readlink@1.0.1
│ │ ├── commander@2.6.0
@thomaslevesque
thomaslevesque / gitconfig
Last active March 28, 2022 12:54
Useful git aliases
[repo]
defaultRemoteName = origin
mainBranchName = master
[alias]
diffc = diff --cached
logg1 = log --graph --oneline
current-branch = rev-parse --abbrev-ref HEAD
publish = !git push -u $(git config repo.defaultRemoteName) $(git current-branch)
finish-branch = !branchName=$(git current-branch) && git fetch $(git config repo.defaultRemoteName) $(git config repo.mainBranchName):$(git config repo.mainBranchName) && git checkout $(git config repo.mainBranchName) && git branch -d $branchName && git fetch -p $(git config repo.defaultRemoteName)
// Solution for James Michael Hare's anagram challenge (http://geekswithblogs.net/BlackRabbitCoder/archive/2015/07/28/little-puzzlersndashlist-all-anagrams-for-a-word.aspx)
// Run in LinqPad, adding a reference to Microsoft.Experimental.Collections
void Main()
{
string path = @"D:\tmp\words.txt";
var dict = new MultiValueDictionary<string, string>();
foreach (var word in File.ReadLines(path))
{
dict.Add(new string(word.OrderBy(c => c).ToArray()), word);
}
@thomaslevesque
thomaslevesque / memset.cs
Last active July 6, 2021 01:48
Benchmark of memset implementations in C# using a loop or the initblk CLR instruction (run in LinqPad)
void Main()
{
var array = new byte[10000000];
var initBlk = new InitblkMemoryHelper();
var loop = new LoopMemoryHelper();
// First run for JIT warmup and type initialization
initBlk.Memset(array, 0, array.Length, 42);
loop.Memset(array, 0, array.Length, 42);
@thomaslevesque
thomaslevesque / CallerInfo.cs
Last active August 29, 2015 14:09
Caller info attributes
using System;
namespace System.Runtime.CompilerServices
{
[AttributeUsageAttribute(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerMemberNameAttribute : Attribute
{
}
[AttributeUsageAttribute(AttributeTargets.Parameter, Inherited = false)]
public sealed class CallerFilePathAttribute : Attribute
@thomaslevesque
thomaslevesque / FullOuterJoinTests
Last active July 20, 2017 20:24
AssertThrowsWhenArgumentNull: helper to test correct validation of null arguments
using System;
using NUnit.Framework;
namespace MyLibrary.Tests.XEnumerableTests
{
[TestFixture]
class FullOuterJoinTests
{
[Test]
public void FullOuterJoin_Throws_If_Argument_Null()
@thomaslevesque
thomaslevesque / Sleeper.cs
Created May 14, 2014 08:23
A cancellable synchronous Sleep implementation
using System;
using System.Threading;
namespace Utils.Threading
{
/// <summary>
/// A cancellable replacement for Thread.Sleep
/// </summary>
public static class Sleeper
{
@thomaslevesque
thomaslevesque / BasicAuthenticationModule.cs
Last active August 29, 2015 14:01
A Basic authentication module that uses UTF-8 to encode username and password (rather than ANSI for the built-in implementation)
using System;
using System.Linq;
using System.Net;
using System.Text;
using Sharebox.Utils.Collections;
namespace Sharebox.Communication
{
class BasicAuthenticationModule : IAuthenticationModule
{
@thomaslevesque
thomaslevesque / CustomDragCursor.cs
Created May 2, 2014 22:55
Drag and drop with custom cursor
void Main()
{
var pb = new PictureBox { Image = Image.FromFile(@"D:\tmp\dotnet.png") };
bool down = false;
Cursor dragCursor = null;
pb.MouseDown += (sender, e) => down = true;
pb.MouseUp += (sender, e) => { down = false; dragCursor = null; };
pb.MouseMove += (sender, e) =>
{
if (down)