Skip to content

Instantly share code, notes, and snippets.

@davidalpert
davidalpert / Program.cs
Created August 2, 2015 05:59
Per-Instance logging with NLog & TopShelf
using System;
using System.Timers;
using FubuCore;
using NLog;
using NLog.Layouts;
using NLog.Targets;
using Topshelf;
using Topshelf.Runtime;
namespace Dragon.WindowsService
@davidalpert
davidalpert / HideEpisodeDescriptions.js
Last active September 20, 2015 15:14
Tampermonkey - Remove Episode Descriptions
// ==UserScript==
// @name Hide Episode Descriptions
// @namespace https://gist.github.com/davidalpert/a103c10889b74f9e5ef0
// @version 0.1
// @description hides (and then optionally toggles) the descriptions of episode listings on Wikipedia
// @author David Alpert
// @match https://en.wikipedia.org/wiki/*episodes*
// @match http://en.wikipedia.org/wiki/*episodes*
// @match https://en.wikipedia.org/wiki/*(TV_series)
// @match http://en.wikipedia.org/wiki/*(TV_series)
@davidalpert
davidalpert / TestHelpers.fs
Created April 5, 2015 17:23
An F# version of the RedirectedConsole
module TestHelpers
open System
open System.IO
type RedirectedConsole() =
let outBefore = Console.Out
let errorBefore = Console.Error
let console = new StringWriter()
public class RedirectedConsole : IDisposable
{
readonly TextWriter outBefore;
readonly TextWriter errBefore;
readonly StringWriter console;
public RedirectedConsole()
{
console = new StringWriter();
outBefore = Console.Out;
lg = log --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %-n%Cgreen(%ci)%Creset%-n' --date=relative
lg2 = "!git lg -2"
drop = "!sh -c 'git merge drop$1 && git ci --allow-empty --amend && git lg2' -"
patch = "!sh -c 'git merge patch$1 && git ci --allow-empty --amend && git lg2' -"
cd = "!git diff-index --cached --quiet HEAD --ignore-submodules -- && GIT_COMMITTER_DATE=\"$1\" git commit --allow-empty --amend -C HEAD --date \"$1\"" || echo >&2 "error: date change failed: index not clean!"
let private getFromResource resourceName =
let assem = System.Reflection.Assembly.GetExecutingAssembly()
try
use stream = assem.GetManifestResourceStream(resourceName)
use reader = new System.IO.StreamReader(stream)
reader.ReadToEnd();
with
| ex ->
let errorMessageBase = sprintf "%s not found; available resources include:" resourceName
let errorMessage =
@davidalpert
davidalpert / cinst.ps1
Created May 16, 2014 22:10
Chocolatey install succeeds with custom source
PS C:\Users\dalpert> cinst virtualbox -source "https://chocolatey.org/api/v2/"
@davidalpert
davidalpert / cinst.ps1
Last active August 29, 2015 14:01
Chocolatey install fails with a 404
PS C:\Users\dalpert> cinst virtualbox
Chocolatey (v0.9.8.23) is installing ‘virtualbox’ and dependencies. By installing you accept the license for ‘virtualbox’ and each dependency you are installing. Unable to connect to the remote server
Command ‘install’ failed (sometimes this indicates a partial failure). Additional info/packages: virtualbox Reading environment variables from registry. Please wait… Done.
PS C:\Users\dalpert> cinst virtualbox
@davidalpert
davidalpert / DigitalStorageUnits.fs
Created April 15, 2014 17:02
Digital storage units of measure for F#
// Digital Storage units ---------------------------
[<Measure>] type GB =
static member perMB = 0.000976562<GB>
static member perKB = 9.5367e-7<GB>
static member perByte = 9.3132e-10<GB>
[<Measure>] type MB =
static member perGB = 1024.0<MB>
static member perKB = 0.000976563<MB>
@davidalpert
davidalpert / ManifestResourceHelper.cs
Created April 8, 2014 21:52
Helper code to extract resources from a C# assembly.
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace %%YOUR_NAMESPACE%%
{
public static class ManifestResourceHelper
{
public static string[] GetManifestResourceNames(Assembly asm = null)
{