Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View danielmoore's full-sized avatar

Daniel Moore danielmoore

View GitHub Profile

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@danielmoore
danielmoore / source-git-completion.bash
Created May 31, 2016 21:27
Bulletproof git completion?
gitRootDir=$(dirname $(git --info-path))/..
source $(find $gitRootDir -name git-completion.bash)
source $(find $gitRootDir -name git-prompt.sh)
@danielmoore
danielmoore / gist:8356567
Created January 10, 2014 15:40
Weird user path rewrite behavior in npm

Why does this work...

$ curl http://$auth@registry.npmjs.org/-/user/org.couchdb.user:isaacs

{"_id":"org.couchdb.user:isaacs","_rev":"93-157a5d9f44f3ef8fe6b21380632becf1","name":"isaacs","email":"i@izs.me","type":"user","roles":[],"date":"2013-12-25T20:42:32.599Z","fullname":"Isaac Z. Schlueter","fields":[{"name":"fullname","value":"Isaac Z. Schlueter","title":"Full Name","show":"Isaac Z. Schlueter"},{"name":"email","value":"isaacs@izs.me","title":"Email","show":"isaacs@izs.me"},{"name":"github","value":"isaacs","title":"Github","show":"isaacs"},{"name":"twitter","value":"izs","title":"Twitter","show":"@izs"},{"name":"appdotnet","value":"isaacs","title":"App.net","show":"isaacs"},{"name":"homepage","value":"http://blog.izs.me","title":"Homepage","show":"http://blog.

var array = [-3 , -6, -2, -56, -32, -5, -89, -32];
function max1(array) {
var largest = array[0]; // start with the first item
for (i = 1; i < array.length; i++) // changed i to start at 1, to avoid extra work
if (array[i] > largest) {
largest = array[i];
}
return largest;
function Get-Hash {
[CmdletBinding(DefaultParameterSetName='file:sha1')]
param(
[Parameter(ParameterSetName='file:md5')]
[Parameter(ParameterSetName='string:md5')]
[Switch]
$MD5,
[Parameter(ParameterSetName='file:sha1')]
[Parameter(ParameterSetName='string:sha1')]
[Switch]
function Find-File {
[CmdletBinding(DefaultParameterSetName = 'Count')]
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$Name,
[Parameter(Position = 1)]
[string]$Directory = '.',
[Parameter(ParameterSetName = 'Count')]
[int]$MaxResults = 1,
[Parameter(ParameterSetName = 'All')]
@danielmoore
danielmoore / clipboard.psm1
Created April 6, 2012 20:16
Clipboard Utilities for Powershell
Add-Type -Namespace PowershellPlatformInterop -Name Clipboard -MemberDefinition @"
[DllImport("user32.dll", SetLastError=true)]
public static extern bool EmptyClipboard();
[DllImport("user32.dll", SetLastError=true)]
public static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
[DllImport("user32.dll", SetLastError=true)]
public static extern IntPtr GetClipboardData(uint uFormat);
@danielmoore
danielmoore / gist:1238996
Created September 24, 2011 05:12
Testing perf of different representations of combined conditional logic
void Main()
{
Test(PerformIfBlocks).Dump("If blocks");
Test(PerformLogicalAnd).Dump("Logical AND");
Test(PerformLogicalOr).Dump("Logical OR");
}
private int Test(Func<int, int, bool> test) {
var cancel = false;
var task = Task.Factory.StartNew(() => {
@danielmoore
danielmoore / gist:1195440
Created September 5, 2011 16:47
Big ass match statement.
let rec processMethodCalls (rule : IRule) (processor : MethodCall -> Option<Problem>) (mbr : Member) : ProblemCollection =
let problems = new ProblemCollection(rule)
let rec processMbrs mbrs = Seq.iter processMbr mbrs
and processMbr (mbr : Member) =
let rec processStmts stmts = Seq.iter processStmt stmts
and processStmt (stmt : Statement) =
let rec processExprs exprs = Seq.iter processExpr exprs
and processExpr (expr : Expression) =
match expr with