Skip to content

Instantly share code, notes, and snippets.

Lee Cooper lski

Block or report user

Report or block lski

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lski
lski / createLogger.js
Last active Nov 2, 2019
Create a logger that will only log values if the initial currentLevel is equal to or greater than the initially passed in level
View createLogger.js
/**
* Creates a logger that optional runs depending on the current level set for logging in the application
*
* Levels:
* 0 = debug
* 1 = trace (alias for verbose)
* 2 = info
* 3 = warn
* 4 = error
* 5+ = none
@lski
lski / toMarkdownTable.js
Created Oct 27, 2019
Converts a list of objects to a Markdown table
View toMarkdownTable.js
export const toMarkdownTable = (keys = null) => (list) => {
if (list == null) throw new Error('The list needs to be an array');
if (list.length === 0) return '';
keys = keys || Object.keys(list[0]);
if (keys.length === 0) return '';
@lski
lski / AutheticationProvider.jsx
Created Oct 6, 2019
Wrappers the Okta Auth for React, includes support for hooks
View AutheticationProvider.jsx
import React, { createContext, useContext, useMemo, useState, useEffect } from "react";
import { Route, withRouter } from "react-router-dom";
import { Auth } from "@okta/okta-react";
import { useExpensiveRef } from '../features/useExpensiveRef';
import { Redirect } from "react-router";
import { getLocationStorage } from "../utils/localStorage";
import { log } from '../utils/log';
const settings = {
issuer: process.env.REACT_APP_OKTA_ISSUER,
@lski
lski / localStorage.js
Created Oct 2, 2019
A simple localStorage wrapper storing objects, rather than strings
View localStorage.js
function setLocationStorage(key, value) {
localStorage.setItem(key, JSON.stringify(value));
return value;
}
function getLocationStorage(key, clear = false) {
const value = localStorage.getItem(key);
if(clear === true) {
removeLocationStorage(key);
@lski
lski / VsCode.ps1
Created Apr 22, 2019
A backup and restore script for VSCode
View VsCode.ps1
$root = if($PSScriptRoot) { $PSScriptRoot } else { '.' }
function Backup-VsCode(
[string]
$backupDir = "$root"
) {
if($null -ne ($code = FindVsCodeExe)) {
Extract-VsCodeSettings -backupDir $backupDir
@lski
lski / Launch.cs
Created Apr 18, 2019
Launch a web broswer with optional URL on Win/Mac/Linux
View Launch.cs
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WebBrowser
{
public static class Browser
{
public static Process Launch(string url, string browser = null)
{
@lski
lski / HttpClientWrapper.cs
Created Apr 18, 2019
A wrapper for HttpClient to allow for mocking... however do not use, see readme
View HttpClientWrapper.cs
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace HttpWrapper
{
/// <summary>
/// A concrete implementation of IHttpClient, which can be used easily for mocking
/// </summary>
@lski
lski / GuidExtensions.cs
Last active Apr 16, 2019
A short format GUID/UUID based on Mads Kristensens work
View GuidExtensions.cs
public static class GuidExtensions {
/// <summary>
/// Converts a Guid into a short format useful urls
/// </summary>
/// <remarks>
/// See <see>https://madskristensen.net/blog/A-shorter-and-URL-friendly-GUID</see> for a more detailed explantion.
/// </remarks>
public static string ToShortFormat(this Guid guid) =>
Convert.ToBase64String(guid.ToByteArray())
@lski
lski / wslpath.ps1
Created Apr 6, 2019
wslpath wrapper for using directly in powershell
View wslpath.ps1
<#
.SYNOPSIS
Converts windows path into a linux path and vice versa.
.DESCRIPTION
Converts windows path into a linux path and vice versa. Use WSL under the hood, so needs to be installed.
See docs wslpath docs for more information.
.PARAMETER path
The path to convert
@lski
lski / createElement.js
Last active Sep 22, 2019
Shorthand function for document.createElement, with added functionality... very similar to Reacts createElement :/ lol
View createElement.js
/**
* Shorthand function for document.createElement. Accepts and appends attributes to the newly created element and appends child element, if any.
* @param tagName The name of the element eg. a or script
* @param attributes Any additional attributes to add to the element after creating. Eg. href
* @param children Any child elements you want appended on creating this element, obviously they could be createElement calls as well
*/
export function createElement(tagName, attributes, children) {
const ele = attributes === (void 0)
? document.createElement(tagName)
: Object.assign(document.createElement(tagName), attributes);
You can’t perform that action at this time.