Skip to content

Instantly share code, notes, and snippets.

View n3dst4's full-sized avatar
:octocat:
fgdxgfdxfg

Neil de Carteret n3dst4

:octocat:
fgdxgfdxfg
View GitHub Profile
@n3dst4
n3dst4 / git_pretty
Created June 18, 2013 14:08
A very useful git alias, "git pretty" prints a coloured, branched diagram of your repository. Obviously there are graphical tools which will do this but if you're working from the command line it's handy not to have to fire up a whole new window. Run the command line below to add the alias to your global ".gitconfig". I also have the same comman…
git config --global --add alias.pretty "log --oneline --abbrev-commit --branches=* --graph --decorate"
@n3dst4
n3dst4 / co-contra-variance.cs
Created June 28, 2013 16:18
A walkthough of why .net people care about variance in generic type parameters
// generic type:
public class Bag<T> {}
// simple usage:
Bag<Fruit> myBag;
myBag = new Bag<Fruit>();
// so far so good
@n3dst4
n3dst4 / gist:6621406
Last active December 23, 2015 10:29
{
// ...
Competition: '',
Participants: [
{
Name: "Manchester United",
Players: [
{
Name: "Fred Fredfredfred",
ShortName: "Fred",
@n3dst4
n3dst4 / no_caching.cs
Created November 8, 2013 13:32
Disabling absolutely all caching on an ASP.NET MVC controller action. Because this is always so much ballache.
Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
Response.Cache.SetValidUntilExpires(false);
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
@n3dst4
n3dst4 / pathshrink.sh
Created November 9, 2013 13:12
This is a bash script for use in Windows (for use with Cygwin/Git Bash etc) to shrink foldernames on shitty windows. Since shitty windows's shitty FS allows you to create files with a path length greater than the maximum allowable path length (!) you can end up with an undeletable folder structure. This script recurses through and renames everyt…
#!/bin/bash
# set this to the problem folder
BASE=/c/Users/ndc/Dropbox/projects/delete-me
cd $BASE
for i in `find $BASE -depth`
do
DIR=`dirname $i`
FILE=`basename $i`
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) (float64, int) {
last := 0.0
z := 1.0
@n3dst4
n3dst4 / api_blueprint_notes.md
Created March 6, 2014 14:15
API Blueprint Language notes

API Blueprint

Start with:

FORMAT: 1A
@n3dst4
n3dst4 / README.md
Last active February 19, 2016 16:29
Using node-retry to work around errors in Windows when using rimraf

Deleting a tree of folders using rimraf can be pretty fraught on MS Windows; the OS itself can lock files randomly, and there may be various processes getting in the way, like virus checkers or cloud file syncing apps. rimraf itself will do an exponential-backoff-and-retry for EBUSY and ENOTEMPTY errors on Windows, but you can still see EPERM and others. If you want to do exponential-backoff-and-retry for any error, see the below recipe, using node-retry.

@n3dst4
n3dst4 / bash_here.bat
Last active August 29, 2015 14:04
Start bash in Console2 with $HOME set to a folder of your choice
@echo off
rem If Windows's idea of $HOME is wrong for you, you can use
rem Console2 and instead of using bash directly, use this batch
rem file instead. It will set $HOME to wherever it is located.
set PATH=%PATH%;%~dp0
set HOME=%~dp0
rem adjust path to suit
@n3dst4
n3dst4 / requireTime.js
Created August 13, 2014 08:15
Time how long all your require()s take
/*
* requireTime.js
*
* require()s every thing in your node_modules and tells you how long each one
* took.
*
* USAGE:
* $ cd your_project_folder
* $ node loadTest.js
*