Skip to content

Instantly share code, notes, and snippets.

View pwelter34's full-sized avatar

Paul Welter pwelter34

View GitHub Profile
@pwelter34
pwelter34 / formatPhone.ts
Created March 16, 2016 20:42
format phone number
static formatPhone(phone: string): string {
var regexPhone = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
var regexExtension = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})[-. ]?[A-Za-z:. ]*([0-9]+)$/;
if (regexExtension.test(phone)) {
return phone.replace(regexExtension, "($1) $2-$3 x$4");
} else if (regexPhone.test(phone)) {
return phone.replace(regexPhone, "($1) $2-$3");
} else {
return phone;
@pwelter34
pwelter34 / ChangeTracker.cs
Created May 4, 2016 21:02
Change tracking api
ChangeTracker.Default.Configure(c => c
.Entity<User>(e =>
{
e.AutoMap();
e.Property(p => p.FirstName).Equality((original, current) => string.Equal(original, current, IgnoreCase));
e.Property(p => p.Updated).Ignore();
e.Descriptor(e => $"{e.FirstName} {e.LastName}");
@pwelter34
pwelter34 / app.html
Created December 28, 2017 04:26 — forked from freshcutdevelopment/app.html
Aurelia Gist - Add book form
<template>
<require from="book-form"></require>
<book-form></book-form>
<div class="notification" show.bind="notification.length > 0">
${notification}
</div>
</template>
@pwelter34
pwelter34 / audiobook.ps1
Created October 5, 2018 23:45
Convert mp3 files into m4b audiobook
$outFile = ".\output.m4a"
$mergeText = ".\merge.txt"
$metadataText = ".\metadata.txt"
# cleanup working files
If (Test-Path $outFile){
Remove-Item $outFile
}
If (Test-Path $mergeText){
Remove-Item $mergeText
@pwelter34
pwelter34 / DeltaCompare.cs
Created May 10, 2019 18:10
Compare two lists giving edits, creates and deletes
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Xunit;
namespace DeltaCompare.Tests
{
public class DeltaCompareTests
{
@pwelter34
pwelter34 / index.html
Created January 28, 2020 14:43
fix blazor startup to not require sticky sessions
<script src="~/_framework/blazor.server.js" autostart="false" asp-append-version="true"></script>
<script>
Blazor.start({
configureSignalR: function (builder) {
builder.withUrl('_blazor', {
skipNegotiation: true,
transport: 1
});
builder.configureLogging(1);
}
@pwelter34
pwelter34 / Retry.cs
Created February 27, 2020 19:41
Retry code
/// <summary>
/// Retry helpers for common retry scenario
/// </summary>
public static class Retry
{
/// <summary>
/// The default retry count
/// </summary>
public const int RetryCount = 5;
@pwelter34
pwelter34 / ConfigurationLoader.tsx
Created March 31, 2020 17:29
React Configuration Loader
import React, { useState, useEffect, createContext } from "react";
import Loader from './Loader';
interface Props {
children: JSX.Element;
file?: string;
}
interface IConfiguration{
@pwelter34
pwelter34 / sqlserver.yaml
Created May 18, 2020 19:35
use sql server in azure devops
resources:
containers:
- container: sqlserver
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- 1433:1433
env:
ACCEPT_EULA: 'Y'
SA_PASSWORD: $(SqlPassword)
public static class DictionaryExtensions
{
/// <summary>
/// Adds a key/value pair to the Dictionary if the key does not already exist.
/// </summary>
/// <typeparam name="TKey">The type of the keys in the dictionary.</typeparam>
/// <typeparam name="TValue">The type of the values in the dictionary.</typeparam>
/// <param name="dictionary"></param>
/// <param name="key">The key of the element to add.</param>
/// <param name="valueFactory">The function used to generate a value for the key.</param>