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 / 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 / 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");
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 / 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));
@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 / 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 / DI Config for a DbContext Factory
Created November 28, 2017 11:48
EF: Allows usual transactions for scope injected instances and a factory method to create contexts which are disposed of by the caller
services.AddDbContext<MyDataContext>(
o => o.UseSqlServer(settings.ConnectionString),
ServiceLifetime.Scoped,
ServiceLifetime.Singleton);
services.TryAddSingleton<Func<MyDataContext>>(sp =>
() => new MyDataContext(sp.GetService<DbContextOptions<MyDataContext>>())
);
@MrAntix
MrAntix / scroll.service.ts
Last active December 15, 2017 09:52
smooth scroll to in angular
import { Injectable, NgZone } from '@angular/core';
@Injectable()
export class ScrollService {
constructor(
private ngZone: NgZone) {
}
scrollTo(selector: string, focus?: boolean): void {
@MrAntix
MrAntix / UpdateVersionAndPack.cs
Last active December 22, 2017 12:52
DotNetCore - Update project files with passed version and pack
internal class Program
{
static readonly Regex VersionRE = new Regex(@"(\d+\.\d+\.\d+)(\-.*(\-\d+))?");
static void Main(string[] args)
{
var app = new CommandLineApplication();
var pack = app.Command("pack", config =>
{
var versionArg = config.Argument("version", "Semamtic Version to pack e.g. (1.0.0-beta-1)", false);
@MrAntix
MrAntix / ObservableExtensions.cs
Last active January 19, 2018 23:34
Route events based on type on the same observable
public static class ObservableExtensions
{
public static Builder<TBase> SwitchType<TBase>(
this IObservable<TBase> observable)
{
return new Builder<TBase>(observable);
}
public class Builder<TBase>
{