Skip to content

Instantly share code, notes, and snippets.

View akatakritos's full-sized avatar

Matt Burke akatakritos

View GitHub Profile
@akatakritos
akatakritos / angularjs-rxjs-utils.ts
Created February 14, 2020 16:06
angular.js rxjs misc
/** AngularJS function to unsubscribe from observables when scope destroyed.
* @param $scope - Scope that is listening to an observable.
*/
export function registerDestroyedObservable($scope: any) {
if($scope.destroyed$) {
return;
}
$scope.destroyed$ = new Subject();
$scope.$on('$destroy', () => {
@akatakritos
akatakritos / injectables.ts
Created January 14, 2020 20:03
angular.js injectables and dependencies
function getInjectables(appName) {
const queue = (angular.module(appName) as any)._invokeQueue;
const injectables = [];
function injectable(type, name, deps) {
return { name, type, deps, depsCount: deps.length, depsJoin: deps.join() };
}
queue.forEach(q => {
@akatakritos
akatakritos / Program.cs
Last active March 15, 2019 14:40
log4net config
log4net.Config.XmlConfigurator.Configure();
@akatakritos
akatakritos / Test.cs
Last active March 8, 2019 19:24
C# Fixture Classes
public class FooServiceTests
{
private Fixture _fixture = new Fixture();
[Test]
public void WhenLoggedIn_TheReportHasTheUsersNameIncluded()
{
var subject = _fixture.LogIn("George Washington").CreateService();
var result = subject.GetReportData();
Check.That(result.CurrentUserName).IsEqualTo("George Washington");
@akatakritos
akatakritos / RequiredIfAttribute.cs
Last active June 19, 2018 19:19
RequiredIf Validator
// [RequiredIf("SomeOtherProperty")] -- required if the other property is true
// [RequiredIf("SomeIntProperty", OtherPropertyValue = 42)] -- required if the other property is 42
public class RequiredIfAttribute : ValidationAttribute, IClientValidatable
{
public string OtherPropertyName { get; }
public object OtherPropertyValue { get; set; }
public RequiredIfAttribute(string otherPropertyName)
{
@akatakritos
akatakritos / create-aspnet-core-identity-schema.sql
Created June 5, 2018 03:19
Script to create the ASPNET core Identity tables
USE [HobbyDB]
GO
/****** Object: Table [dbo].[AspNetRoleClaims] Script Date: 6/4/2018 10:18:03 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AspNetRoleClaims]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AspNetRoleClaims](
@akatakritos
akatakritos / Program.cs
Created June 1, 2018 18:44
Stripping Non-AlphaNumerics in C# Benchmark
[MemoryDiagnoser]
public class Benchmark1
{
[Params("555-55-5555", "555-123-fsdfjksdf-xxx_fdslfs fkslfd_fkdlsf")]
public string Input { get; set; }
[Benchmark]
public string StringBuilderForeach()
{
var sb = new StringBuilder();
@akatakritos
akatakritos / Program.cs
Created May 31, 2018 15:00
Async Rate Limiting with SemaphoreSlim
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
@akatakritos
akatakritos / Global.asax.cs
Created October 26, 2017 15:36
Log4Net Config
protected void Application_Start()
{
log4net.Config.XmlConfigurator.Configure();
log4net.GlobalContext.Properties["userid"] = new Log4NetUserIdResolver();
}
@akatakritos
akatakritos / backup.bat
Created September 25, 2017 17:01
Simple robocopy backup script for archiving projects on an external drive
SET folder=%1
echo "C:\projects\%folder%"
robocopy "C:\projects\%folder%" "E:\projects-archive\%folder%" /E /FFT /R:3 /W:10 /Z /NP /NDL /MT /XD node_modules /XD bower_components /XD packages