Skip to content

Instantly share code, notes, and snippets.

View KerryRitter's full-sized avatar

Kerry Ritter KerryRitter

View GitHub Profile
@KerryRitter
KerryRitter / ComponentModalService.ts
Created July 7, 2016 15:10
ComponentModalService
export class ComponentModalService {
public static $inject = ["$uibModal"];
private _modalInstance: ng.ui.bootstrap.IModalServiceInstance;
public constructor(
private _modalService: ng.ui.bootstrap.IModalService
) {
}
@KerryRitter
KerryRitter / arraySafeReplace.ts
Created July 6, 2016 18:49
Array safe replace for when Angular isn't kind
declare module _ {
interface LoDashStatic {
arraySafeReplace: (existingArray: any[], newArray: any[]) => any[];
}
}
_.mixin({ "arraySafeReplace": (existingArray: any[], newArray: any[]) => {
if (existingArray) {
existingArray.length = 0;
} else {
@KerryRitter
KerryRitter / Startup.cs
Last active May 4, 2024 09:11
OpenIddict Startup Example (with postgres and custom password rules)
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace MyApp.Api
@KerryRitter
KerryRitter / gist:6e997d6e89701269572444de059c914c
Created May 12, 2016 14:15
Bootstrap Multi-Select Angular 1.5 Typescript
class MultiselectController {
public static $inject = ["$timeout", "$scope"];
public allSelectedLabel: string;
public options: IMultiselectOption[];
public ngModel: IMultiselectOption[];
private _maxLabelItems: number = 3;
private _clickTracker: IMultiselectOption[];
@KerryRitter
KerryRitter / bootstrap-checkbox.ts
Created May 12, 2016 14:15
Bootstrap Checkbox Angular 1.5 Typescript
export class Checkbox implements ng.IComponentOptions {
public bindings: any = {
ngModel: "=",
defaultValue: "<",
label: "<"
};
public template: string = `
<div type="button"
class="btn btn-default"
@KerryRitter
KerryRitter / isEmptyOrWhiteSpace.js
Created May 12, 2016 13:58
isEmptyOrWhiteSpace lodash
function isEmptyOrWhiteSpace(val) {
return _.isObject(val)
? _.isEmpty(val)
: _.chain(val).trim().isEmpty().value();
}
_.mixin({ 'isEmptyOrWhiteSpace': isEmptyOrWhiteSpace });
console.log(_.isEmptyOrWhiteSpace(""), true);
console.log(_.isEmptyOrWhiteSpace(" "), true);
@KerryRitter
KerryRitter / authService.js
Last active February 3, 2016 18:06
Angular services for ASP.NET Web API
/// <reference path="../app.js" />
'use strict';
app.factory('authService', ['$http', '$q', '$log', 'apiBaseUrl', 'localStorageService', function ($http, $q, $log, apiBaseUrl, localStorageService) {
var setupHttp = function() {
$http.defaults.headers.common["Content-Type"] = "application/x-www-form-urlencoded";
$http.defaults.headers.common['Authorization'] = "Bearer " + authentication.access_token;
}
var authServiceFactory = {};
@KerryRitter
KerryRitter / IpRangeCalculator.cs
Created October 30, 2015 19:09
Does calculations and math on IP Addresses, CIDR ranges, subnet masks
/// <summary>
/// Class for doing IP Address and network calculations
/// </summary>
public class IpRangeCalculator
{
public readonly Dictionary<string, string> CidrSuffixesForMask = new Dictionary<string, string>
{
{ "255.255.255.255", "32" },
{ "255.255.255.254", "31" },
{ "255.255.255.252", "30" },
@KerryRitter
KerryRitter / App Pool Recycle Listener.cs
Created October 29, 2015 17:15
Listens to the event log to detect when app pool recycle events are triggered (IIS must be configured to write these to the logs)
using System;
using System.Diagnostics;
using System.Net;
namespace EventLogListener
{
class Program
{
static void Main(string[] args)
{
@KerryRitter
KerryRitter / confirmByTypingDirective.js
Created September 10, 2015 20:16
Confirm-by-typing Directive
/**
* This directive asks the user for a Yes/No confirmation, and then requires the user to type a value to confirm the action.
*
* Usage:
<button confirm-by-typing confirm-action="deleteSite(site)" confirm-value="{{site.Path}}" alert-message="Are you sure you want to delete '{{site.Name}}'?" modal-title="Are you sure you want to delete '{{site.Name}}'?" modal-message="Enter the site path <strong>'{{site.Path}}'</strong> below to confirm.">
Delete
</button>
*/
adminApp.directive("confirmByTyping", ["$modal", function ($modal) {
var getConfirmTypingModalTemplate = function (title, message) {