Skip to content

Instantly share code, notes, and snippets.

View MrAntix's full-sized avatar
🏠
Working from home

Anthony Johnston MrAntix

🏠
Working from home
View GitHub Profile
@MrAntix
MrAntix / FindImplementationsInSameAssemblyAs.cs
Created May 28, 2017 23:41
Find Implementations In Same Assembly even generics
public static class ReflectionExtensions
{
public static void FindImplementationsInSameAssemblyAs<T>(
this Type type,
Action<Type, Type> action)
{
var assembly = typeof(T).GetTypeInfo().Assembly;
var query =
from implementationType in assembly.GetTypes()
@MrAntix
MrAntix / SpecialCamelCasePropertyNamesContractResolver.cs
Last active May 23, 2017 09:58
Configure JSON.NET for camels and dates
public class SpecialCamelCasePropertyNamesContractResolver :
CamelCasePropertyNamesContractResolver
{
protected override JsonDictionaryContract CreateDictionaryContract(
Type objectType)
{
var contract = base.CreateDictionaryContract(objectType);
contract.DictionaryKeyResolver = propertyName => propertyName;
@MrAntix
MrAntix / Int.cs
Created April 23, 2017 18:45
Validating Number Input for a UWP XAML TextBox
namespace MyApp
{
public sealed class Int
{
public static readonly DependencyProperty AttachedProperty = DependencyProperty.RegisterAttached(
"IntAttached", typeof(bool), typeof(Int), null);
public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
"Value", typeof(int), typeof(Int), new PropertyMetadata(null, OnAttach));
var properties = { Two:true, Three:1 };
var filters = ['One===true', 'Two===true', 'Three>6', 'Three<6 || Two===true'];
var fnString = '';
for(var name in properties) {
fnString +='var '+name+'='+properties[name]+';\n';
}
console.log(fnString);
@MrAntix
MrAntix / EFExtensions.cs
Last active October 27, 2015 10:40
AddOnce Seed extension for EF 6 using LinqKit
public static class Extensions
{
public static void AddOnce<TEntity>(
this IDbSet<TEntity> set,
Expression<Func<TEntity, object>> identifierExpression,
params TEntity[] entities) where TEntity : class
{
if (set == null) throw new ArgumentNullException("set");
if (identifierExpression == null) throw new ArgumentNullException("identifierExpression");
if (entities == null) throw new ArgumentNullException("entities");
@MrAntix
MrAntix / keyed-collection-tests.js
Last active August 29, 2015 14:23
Keyed Collection for AngularJS, tests using Jasmine in VS with Resharper
/// <reference path="~/Scripts/jasmine/jasmine.js" />
/// <reference path="~/Scripts/angular.js" />
/// <reference path="~/Scripts/angular-mocks.js" />
/// <reference path="~/Scripts/Common/Collections/keyed-collection.js" />
describe('keyed-collection', function () {
beforeEach(module('common.collections.keyedCollection'));
describe('keyed-collection service', function () {
@MrAntix
MrAntix / CreateQRService.cs
Last active August 29, 2015 14:23
Use a service resolved from a DI container with Owin Middleware
public class CreateQRService :
ICreateQRService
{
readonly Log.Delegate _log;
byte[] _qr;
public CreateQRService(
Log.Delegate log)
{
_log = log;
@MrAntix
MrAntix / param-array-example-use.js
Last active August 29, 2015 14:22
js param array
var someFunction = function(text, moreThings) {
var moreThingsArray = paramArray(moreThings, arguments, 1);
// ... do stuff
};
someFunction('test with array', [new thing(), new thing()]);
someFunction('test with params', new thing(), new thing());
@MrAntix
MrAntix / antix.select.multiple,json
Last active April 27, 2017 17:01
AngularJS Multi Select (checkbox list)
// what the data looks like
// demo http://jsbin.com/yocolomife/1/edit?html,js,output
scope.things = [
{ id : 1, name: 'raindrows on roses' },
{ id : 2, name: 'wiskers on kittens' },
{ id : 3, name: 'brown paper packages tied up with strings' }
];
scope.myModel = {
@MrAntix
MrAntix / index.html
Created January 7, 2015 00:09
angularjs cell layout // source http://jsbin.com/xeyife
<!DOCTYPE html>
<html ng-app="antix.cells">
<head>
<meta name="description" content="angularjs cell layout" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style>