Skip to content

Instantly share code, notes, and snippets.

View MatthewBarker's full-sized avatar

Matt Barker MatthewBarker

  • Cheadle, Cheshire, England
View GitHub Profile
@MatthewBarker
MatthewBarker / DataContext.tt
Created March 30, 2016 14:20
DataContext template using DbSet
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".cs"#>
<#
var loader = new MetadataLoader(this);
var region = new CodeRegion(this);
var inputFile = @"TradingPartner.edmx";
var itemCollection = loader.CreateEdmItemCollection(inputFile);
var container = itemCollection.GetItems<EntityContainer>().FirstOrDefault();
var fileManager = EntityFrameworkTemplateFileManager.Create(this);
@MatthewBarker
MatthewBarker / svg2obj.js
Created February 16, 2016 14:54
Converts an SVG to an OBJ (only supports paths and hex colours in the fill attribute)
var fs = require('fs'),
glob = require('glob'),
hex2rgb = require('color-functions/lib/hex2rgb'),
os = require('os'),
svgMesh3d = require('svg-mesh-3d'),
xpath = require('xpath.js'),
DOMParser = require('xmldom').DOMParser;
function simplicialComplexToObj(mesh) {
var result = '';
@MatthewBarker
MatthewBarker / index.css
Created October 29, 2015 14:13
CSS Navigation Compass
/* Compass */
.compass {
background: #eee;
width: 200px;
height: 200px;
border-radius: 100%;
border: 5px solid #666;
position: relative;
}
.arrow {
@MatthewBarker
MatthewBarker / router.js
Created October 14, 2015 11:48
A router for Knockout.js
var ko = require('knockout');
var crossroads = require('crossroads');
var hasher = require('hasher');
function parseHash(newHash, oldHash) {
crossroads.parse(newHash);
}
function Router(routes) {
var self = this;
@MatthewBarker
MatthewBarker / bit-buffer.js
Created September 10, 2015 10:58
Wrapper for node's buffer allowing writing / reading of individual bits
'use strict';
function BitBuffer(size) {
size = Math.ceil(size / 8);
this.buffer = new Buffer(size);
this.buffer.fill(0);
}
BitBuffer.prototype = {
@MatthewBarker
MatthewBarker / gulpfile.js
Created August 11, 2015 12:46
Gulp tasks to build, lint & document actionscript / Flash
// Also depends on: npm install --save-dev flash-sdk
var colors = require('colors'),
flash = require('gulp-flash'),
flexPmd = require('flexpmd'),
fs = require('fs'),
gulp = require('gulp'),
process = require('child_process'),
xpath = require('xpath'),
xmldom = require('xmldom'),
config = {
@MatthewBarker
MatthewBarker / Glow.js
Created July 29, 2015 12:44
Phaser glow filter
/*jslint white: true*/
/*global Phaser*/
/**
* Defines a glow filter for Web GL.
* @module
*/
Phaser.Filter.Glow = function (game) {
'use strict';
/*----------------------------------------------------------
// Micro JavaScript Templating xtpl (minified version)
// Leo Lems - http://2basix.nl - MIT Licensed
------------------------------------------------------------*/
(function(){this.xtpl=function xtpl(templatestring,data){var ret='',xfn=new Function("o","var arr=['"+templatestring.replace(/[\r\t\n]/g,"").split("'").join("\\'").replace(/{%=\s*\(\s*(.+?)\s*\)\s*%}/g,"',($1),'").replace(/{%=\s*(.+?)\s*%}/g,"',(o.$1)?o.$1:'','")+"']; return arr.join('');");if(!data){return xfn}return xfn(data)}})();
@MatthewBarker
MatthewBarker / ObservableItemCollection.cs
Created April 17, 2015 13:05
Observes changes to properties on underlying items as well as the collection itself
namespace ViewModels
{
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
/// <summary>
/// Represents an observable item collection.
/// </summary>
@MatthewBarker
MatthewBarker / kendoBullet.js
Created March 24, 2015 12:25
Knockout-Kendo custom binding for a bullet graph HTML helper
ko.bindingHandlers.kendoBullet = {
init: function (element, valueAccessor,
allBindingsAccessor, viewModel, bindingContext) {
var options = ko.utils.unwrapObservable(valueAccessor());
options.type = 'bullet';
if (!options.chartArea) {
options.chartArea = {};
}