Skip to content

Instantly share code, notes, and snippets.

View osbornm's full-sized avatar

Matthew Osborn osbornm

View GitHub Profile
@osbornm
osbornm / javascript.js
Created August 26, 2015 17:28
JS vs TS
var things = [
new Thing1(),
new Thing1(),
new Thing2()
];
var OnlyThingOnes = things.filter(function(t){return t.thingOneOnlyProperty !== undefined});
@osbornm
osbornm / anyEmptyBindings.js
Last active August 29, 2015 14:00
Any & Empty Bindings
function hasItems(data) {
var value = ko.unwrap(data),
result = false;
if (value.length && value.length > 0)
result = true;
return result;
}
@osbornm
osbornm / bindings.js
Created December 1, 2014 19:40
KnockoutJs href binding
ko.bindingHandlers.href = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
return ko.bindingHandlers['attr']['update'](element, function () {
return { href: valueAccessor() };
}, allBindings, viewModel, bindingContext);
}
}
$cd = Add-Type -memberDefinition @"
[DllImport("winmm.dll", CharSet = CharSet.Ansi)] public static extern int mciSendStringA(string lpstrCommand, string lpstrReturnString, int uReturnLength, IntPtr hwndCallback);
"@ -passthru -name mciSendString\
# Where F an G are the Drive letters
$cd::mciSendStringA("set cdaudio!F door closed wait", $null, 1, 1);
$cd::mciSendStringA("set cdaudio!G door closed wait", $null, 1, 1);
@osbornm
osbornm / Helpers.js
Created September 4, 2015 21:02
uppercut.js Announcement
// asObservable or asObservableArray: if passed an observable use that instance otherwise wrap it in a new observable
var myModel = function(options){
var self = this;
self.observable = ko.asObservable(options.possibleObservable);
self.observableArray = ko.asObservableArray(options.possibleObservableArray);
return self;
}
// Trackable Observables: the ability to revert to a "good" value
var myForm = function(){
<section class="release">
<h2>NuGet 1.6 Coming Soon!</h2>
<p>
NuGet 1.6 is coming soon so stay tuned for more information! Why, wait though NuGet 1.5 has already been released so
head over to our docs site and <a href="http://docs.nuget.org/docs/release-notes/nuget-1.5">read all the details</a> of that release.
</p>
</section>
@osbornm
osbornm / gist:1960960
Created March 2, 2012 20:11
NuGet Gallery Footer
if ($commitSha -eq $null) {
$commitSha = (& "$gitPath" rev-parse HEAD)
}
if ($commitBranch -eq $null) {
$commitBranch = (& "$gitPath" name-rev --name-only HEAD)
}
@osbornm
osbornm / jshint.formatters.js
Last active October 13, 2015 06:17
JSHint Formatters to get Visual Studio auto link to files, etc.
var formatters = {
errors: function (errors, lines, file) {
var i, error;
for (i = 0; i < errors.length; i++) {
error = errors[i];
if (!error) continue;
lines.push(file + '(' + error.line + ',' + error.character + '): error JSHint: ' + error.reason);
}
},
@osbornm
osbornm / gist:5043549
Created February 26, 2013 23:58
Knockout Widget Binding - Why does Knockout not have one of these built in?
function _getWidgetBindings(element, valueAccessor, allBindingsAccessor) {
var value = valueAccessor(),
myBinding = ko.utils.unwrapObservable(value),
allBindings = allBindingsAccessor();
if (typeof (myBinding) === 'string') {
myBinding = { 'name': myBinding };
}
var widgetName = myBinding.name,
<!-- Simple Binding -->
<input type="submit" value="OK" data-bind='widget: "button"' />
<!-- Complex Binding with options -->
<input id='search' data-bind='widget: { name: "autocomplete", options: { source: searchCompletions(), delay: 500 } }, value: searchString' />