Skip to content

Instantly share code, notes, and snippets.

View Nate-Wilkins's full-sized avatar
🐧

Nate-Wilkins Nate-Wilkins

🐧
View GitHub Profile
@Nate-Wilkins
Nate-Wilkins / Assertion.cs
Created October 29, 2014 03:29
Assert expression
[Conditional("DEBUG")]
public static void Assert(Expression<Func<bool>> assertion, string message, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
{
bool condition = assertion.Compile()();
if (!condition)
{
string errorMssage = string.Format("Failed assertion in {0} in file {1} line {2}: {3}", memberName, sourceFilePath, sourceLineNumber, assertion.Body.ToString());
throw new AssertionException(message);
}
}
@Nate-Wilkins
Nate-Wilkins / isolate-form.md
Created November 18, 2014 19:19
Angular isolate form

Taken directly from: http://jsfiddle.net/gikoo/qNrFX/

var demoApp = angular.module('demoApp', []);


demoApp.controller('nestedFormIsolation', function ($scope) {
    $scope.setPristine = function(form){
		form.$setPristine();
	};
// https://github.com/angular/angular.js/blob/51d6774286202b55ade402ca097e417e70fd546b/src/ng/filter/filters.js#L428
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
// 1 2 3 4 5 6 7 8 9 10 11
// https://github.com/angular/angular.js/blob/5a60302389162c6ef45f311c1aaa65a00d538c66/i18n/src/parser.js
// e.g. '#,##0.###'
function parsePattern(pattern) {
var p = {
minInt: 1,
minFrac: 0,
maxFrac: 0,
posPre: '',
posSuf: '',
negPre: '',
// Taken from: https://daveaglick.com/posts/capturing-standard-input-in-csharp
string stdin = null;
if (Console.IsInputRedirected)
{
using (Stream stream = Console.OpenStandardInput())
{
byte[] buffer = new byte[1000]; // Use whatever size you want
StringBuilder builder = new StringBuilder();
int read = -1;
while (true)
@Nate-Wilkins
Nate-Wilkins / gist:ab4bd10e13521ff91b80ed30463612e4
Created July 3, 2017 06:32
Whitespace Project Conversion - Tabs to Spaces
find . -name '*.java' ! -type d -exec bash -c 'expand -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;
@Nate-Wilkins
Nate-Wilkins / emacs-pipe
Created July 8, 2018 20:41
Pipe to emacs
#! /usr/bin/perl
# https://www.emacswiki.org/emacs/GnuClient#toc13
##
## This script uses gnudoit to put the contents of STDIN
## in an Emacs buffer called *Piped*
##
if (! `which gnudoit 2>/dev/null`) {
print STDERR "This script requires gnudoit\n";
@Nate-Wilkins
Nate-Wilkins / flowjs-boolean-filter.js
Created October 25, 2018 20:24
FlowJS hackery to filter down arrays to specific types.
type A = {
a: number
};
const myA: A = { a: 1 };
const ac = [undefined, myA];
const ba: $ReadOnlyArray<A> = ac.filter(Boolean);
/*
* Create an animation frame with a specified callback with
* a target frame rate.
*/
const createAnimationFrame = (
callback,
targetFrameRate,
timePrevious,
timeCurrent,
) => {
@Nate-Wilkins
Nate-Wilkins / createAnimationFrame.ts
Last active October 12, 2023 01:20
createAnimationFrame.ts
/*
* Create an animation frame with a specified callback with
* a target frame rate.
*/
const createAnimationFrame = (
callback: (timeDelta: number) => boolean,
targetFrameRate?: number,
timePrevious?: number,
timeCurrent?: number,
): null | number => {