Skip to content

Instantly share code, notes, and snippets.

View jwatney's full-sized avatar

Jonathon Watney jwatney

  • Victoria, BC, Canada
View GitHub Profile
@jwatney
jwatney / gist:62bb3b3b1eca0f0754e1faea6cbcddc6
Created March 11, 2024 21:46
Playwright test for grepping webpage responses
import { Response, test } from '@playwright/test'
const pattern = new RegExp('some string...', 'i')
const urls = ['https://some.url.com/some/page.html']
const requestURLValidator = (response: Response) => {
const requestURL = response.url()
if (pattern.test(requestURL)) {
@jwatney
jwatney / .eslintrc.js
Created March 26, 2023 02:47 — forked from onlime/.eslintrc.js
ESLint/Prettier config for Vue 3 in VS Code
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:vue/vue3-recommended',
'prettier'
@jwatney
jwatney / Browser.js
Created July 31, 2020 16:20
Determines if the browser is IE and which version.
var Browser = (function() {
'use strict';
var version = -1;
var isIE = false;
var map = {
'5.6': 6,
'5.7': 7,
'5.8': 8,
'9': 9,
@jwatney
jwatney / write-env-vars.ps1
Last active June 5, 2019 23:34
Writes env vars matching a prefix to a file. E.g. `write-env-vars.ps1 -Prefix MYAPP_ -Path Environment.config` Useful if you want env vars from your build system to be available to your deployed app.
param([String] $prefix, [String] $path)
# Write-Out environment variables to file.
Get-ChildItem env:* | Where-Object Name -Like "$($prefix)*" | ForEach-Object {
$name = $_.Name.Replace("_", ".")
$key = $name -Replace ":([\d]+):", "[`${1}]"
Write-Output "$key=$($_.Value)"
} | Out-File -FilePath $path
@jwatney
jwatney / EnvironmentVariables.cs
Created June 5, 2019 23:27
Call this at the top of Application_Start. Any key/value pairs (delimited by '=') will be loaded into the processes environment.
public static class EnvironmentVariables {
public static void SetUp() {
var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "Environment.config");
if(File.Exists(configFile)) {
var lines = File.ReadAllLines(configFile);
foreach(var line in lines) {
var index = line.IndexOf("=", StringComparison.Ordinal);
@jwatney
jwatney / DependencyResolution.cs
Created August 8, 2018 22:42
WebForms dependency resolution.
public static class DependencyResolution {
public static void ConfigureServices(IContainer container = null, ServiceCollection services = null) {
container = container ?? new Container();
services = services ?? new ServiceCollection();
container.Populate(services);
var provider = container.GetInstance<IServiceProvider>();
HttpRuntime.WebObjectActivator = new HttpRequestScopedServiceProvider(provider);
}
# This script runs our web-based tests, running IISExpress via TeamCity's
# dotCover, then runing the tests (also in dotCover) and then importing the
# test results and coverage results back into TeamCity.
# Note that some of the following is based on the comments by Tony Fabris on
# 20th Jan 2016 from here: https://youtrack.jetbrains.com/issue/DCVR-5921
# Configuration.
# The path to IIS Express.
$IISExpressPath = "C:\Program Files (x86)\IIS Express\IISExpress.exe"
public static class StringConverter {
public static T To<T>(this string value) {
if(String.IsNullOrEmpty(value)) {
return default(T);
}
try {
var convertibleValue = (IConvertible)value;
var conversionType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
return (T)convertibleValue.ToType(conversionType, CultureInfo.CurrentCulture);
function Archive-Logs {
[CmdLetBinding()]
PARAM (
[string][parameter(Mandatory = $true)][ValidateNotNullOrEmpty()]$LogsPath,
[string][parameter(Mandatory = $true)][ValidateNotNullOrEmpty()]$ArchivesPath
)
BEGIN {
}
PROCESS {
$today = (Get-Date)
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using Dapper;
using Microsoft.EntityFrameworkCore;
public static class DbContextExtensions {
public static IQueryable<object> Set(this DbContext context, Type type) {