Skip to content

Instantly share code, notes, and snippets.

View AndrewAllison's full-sized avatar

Andy Allison AndrewAllison

View GitHub Profile
@AndrewAllison
AndrewAllison / cookies.js
Created May 22, 2020 11:14
Cookie Reader
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
@AndrewAllison
AndrewAllison / Example.ps1
Created November 8, 2019 11:03 — forked from nblumhardt/Example.ps1
Seq from Powershell POC
Import-Module Seq
# Specify the Seq server URL; an -apiKey can also be provided.
# Any properties set here will be attached to all events.
$seq = Open-Seq "http://my-seq" -properties @{ Machine = $env:ComputerName }
# Simple information method
Send-SeqEvent $seq "Hello from PowerShell"
@AndrewAllison
AndrewAllison / commitizen.bat
Created November 7, 2019 17:02
Make global availability of commitizen
npm install -g commitizen cz-conventional-changelog
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
@AndrewAllison
AndrewAllison / docker-compose.yml
Created November 7, 2019 14:43
File for creating a docker ms sql server image
version: "3.2"
services:
sql-server-db:
container_name: sql-server-db
image: microsoft/mssql-server-linux:2017-latest
ports:
- "1433:1433"
environment:
SA_PASSWORD: "<BE$cur£>"
ACCEPT_EULA: "Y"
@AndrewAllison
AndrewAllison / Alphabetize.cs
Created October 10, 2019 14:23
One of those questions from a technical test that gave me an itch to scratch.
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace TestNinja.UnitTests
{
public class Alphabetize
{
public string FindLongestSequense(string sequence)
{
@AndrewAllison
AndrewAllison / Acronym.cs
Created October 9, 2019 07:59
Make nice Acronyms out of sentences.
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class Acronym
{
public static string Abbreviate(string phrase)
{
// Only letters, hyphens and spaces
phrase = new Regex("[^A-Za-z -]").Replace(phrase, "").ToUpperInvariant();
@AndrewAllison
AndrewAllison / grain.cs
Created October 9, 2019 07:57
Common C# test type thangs
using System;
/// <summary>
/// Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
/// </summary>
public static class Grains
{
public static ulong Square(int n)
{
if (n <= 0 || n > 64)
@AndrewAllison
AndrewAllison / last24_hrs.js
Created September 18, 2019 05:18
Mongo Queries
db.system.profile.find({
"timestamp" : {
$lt: new Date(),
$gte: new Date(new Date().setDate(new Date().getDate()-1))
}
})
@AndrewAllison
AndrewAllison / strong-password-regex.md
Created September 13, 2019 16:56 — forked from arielweinberger/strong-password-regex.md
Strong password Regular Expression - NestJS Course
  • Passwords will contain at least 1 upper case letter
  • Passwords will contain at least 1 lower case letter
  • Passwords will contain at least 1 number or special character
  • There is no length validation (min, max) in this regex!

Regular expression for JavaScript:

/((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
@AndrewAllison
AndrewAllison / fake-http-client.spec.ts
Created December 13, 2017 15:40 — forked from dherges/fake-http-client.spec.ts
Angular HttpClient (3)
describe(`FakeHttpClientResponses`, () => {
it(`should expect a GET /foo/bar`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.get('/foo/bar').subscribe();
backend.expectOne({
url: '/foo/bar',
method: 'GET'
});