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 / ExpandPaths.cs
Created June 24, 2014 12:15
Obtains all the file paths from the provided paths - if a directory is a path then expand it and obtain it's files
public IEnumerable<string> ExpandPaths(IEnumerable<string> paths)
{
var expandedPaths = new List<string>();
foreach (var p in paths)
{
if (Directory.Exists(p))
{
expandedPaths.AddRange(Directory.GetFiles(p));
expandedPaths.AddRange(ExpandPaths(Directory.GetDirectories(p)));
}
@Nate-Wilkins
Nate-Wilkins / gist:f2727f1d82263a6c3682
Created July 11, 2014 13:31
Watch ngModel $modelValue changes
var modelCtrl = ctrls[1];
if (modelCtrl) {
$scope.$watch(function () { return modelCtrl.$modelValue; }, function (newValue, old) {
$scope.ngModel = newValue;
});
}
function t(obj) {
var typeString = ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1];
if(typeString == "Object"){ return f(obj.constructor); }
else{ return typeString; }
}
function f(m){
return m.name || m.toString().match(/function\s+([^(]+)/)[1];
}
@Nate-Wilkins
Nate-Wilkins / flatten.js
Last active August 29, 2015 14:05
fatten
var flatten = function (v, cb, result) {
result = result || [];
if (v instanceof Array) {
v.forEach(function (v) { flatten(v, cb, result); });
return result
}
result.push(cb ? cb(v) : v);
return result;
};
// https://github.com/Automattic/cli-table/blob/db9f235d50680d7bdcdd0e42f1c85ab1de273ed1/lib/cli-table/utils.js#L79
// Strip unicode color data and get the underlying string length
exports.strlen = function(str){
var code = /\u001b\[(?:\d*;){0,5}\d*m/g;
var stripped = ("" + str).replace(code,'');
var split = stripped.split("\n");
return split.reduce(function (memo, s) { return (s.length > memo) ? s.length : memo }, 0);
}
@Nate-Wilkins
Nate-Wilkins / function-name-regex
Last active August 29, 2015 14:06
Function name regex
/^function\s?([^\s(]*)/
@Nate-Wilkins
Nate-Wilkins / SplitByLength
Created September 17, 2014 04:37
Regex to split a string by a specified 'x' length
((?:.{1,x}(?=\s|$)|[^\s]+)(?:\s?))
@Nate-Wilkins
Nate-Wilkins / DirectiveTemplateUrl
Created September 18, 2014 15:52
templateUrl custom directive
// taken from: https://github.com/esvit/ng-table/blob/master/ng-table.js
scope: {
'params': '=ngTablePagination',
'templateUrl': '='
},
replace: false,
link: function (scope, element, attrs) {
scope.params.settings().$scope.$on('ngTableAfterReloadData', function () {
@Nate-Wilkins
Nate-Wilkins / proxy.js
Created October 1, 2014 21:50
Get (generated) js file
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(File.ReadAllBytes("path"));
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/javascript");
return result;
@Nate-Wilkins
Nate-Wilkins / git-file-version
Created October 3, 2014 23:39
Git File Version
git rev-list HEAD -- lib/rules/space-in-brackets.js | tail -n1 | xargs git tag --contains | head -n1