Skip to content

Instantly share code, notes, and snippets.

View nathan815's full-sized avatar

Nathan Johnson nathan815

View GitHub Profile
@nathan815
nathan815 / AllPlayingCards.tsx
Last active January 5, 2023 02:06
React Playing Card component
import React from 'react';
import { Flex } from '@chakra-ui/react';
import { PlayingCard, ALL_RANKS, ALL_SUITS } from './PlayingCard';
export function AllCards() {
return (
<Flex flexWrap="wrap" gap={5} mt={20} padding={10}>
{ALL_RANKS.map((rank) =>
ALL_SUITS.map((suit, idx) => (
<PlayingCard key={idx} suit={suit} rank={rank} width="22%" minWidth="200px" />
@nathan815
nathan815 / CardIcon.tsx
Created January 2, 2023 08:58
React component to dynamically render playing card icons from 'react-icons' pkg
import React from 'react';
import { IconBaseProps } from 'react-icons';
import {
GiCardAceDiamonds,
GiCard2Diamonds,
GiCard3Diamonds,
GiCard4Diamonds,
GiCard5Diamonds,
GiCard6Diamonds,
GiCard7Diamonds,
@nathan815
nathan815 / StateMachine.kt
Created March 31, 2022 05:23
Kotlin state machine
package me.nathanjohnson
import android.util.Log
import kotlin.reflect.KClass
/**
* Transition from one state to another on a specific event.
*/
data class StateTransition<StateT, ResourceT>(
@nathan815
nathan815 / powershell.py
Last active February 8, 2022 06:54
PowerShell from Python: Call PowerShell functions Python code with support for returning data, colored console output, and exception handling
import subprocess
import json
from json.decoder import JSONDecodeError
import subprocess
from typing import Union, Any
from termcolor import colored
import shlex
def run_pwsh(
@nathan815
nathan815 / run_cmd_tty_stream.py
Last active February 6, 2022 00:57
Python run a command with TTYs for stdin, stdout, stderr with output streaming (generator function)
def run_cmd_tty_stream(cmd, bytes_input=b''):
"""Streams the output of cmd with bytes_input to stdin,
with stdin, stdout and stderr as TTYs.
Each yield from this function is a tuple of (stream name [str], data [bytes])
Adapted from https://stackoverflow.com/a/52954716/507629
and https://gist.github.com/hayd/4f46a68fc697ba8888a7b517a414583e
"""
# provide tty to enable line-buffering
@nathan815
nathan815 / powershell_with_tty.py
Last active February 8, 2022 06:55
Call PowerShell from Python with support for color output and exception handling - using PTY to simulate a TTY
import subprocess
import json
from json.decoder import JSONDecodeError
import errno
import os
import pty
import select
import subprocess
import re
from typing import Tuple, Any, Union
@nathan815
nathan815 / fider.css
Last active October 13, 2021 04:22
Custom CSS for Fider instance for The Swan Station
:root {
--header-bg: #0f2413;
--header-foreground: #fff; /* #20bf20 */
--primary-color: #118311;
--primary-color-dark: #107010;
--primary-color-light: #118311;
}
#c-header {
background: var(--header-bg);
@nathan815
nathan815 / AWX Auto Fill Survey Script
Last active August 13, 2021 00:08
AWX auto-fill survey
This bookmarklet will autofill all the survey fields in an AWX Launch Job Prompt in one click. It gets the values from the extra vars which are much easier to paste or edit.
Just add the `javascript:...` code as the URL in a bookmark.
@nathan815
nathan815 / Log.java
Last active July 11, 2021 06:13
android.util.Log class override for unit tests
package android.util;
public class Log {
public static int v(String tag, String msg) {
print("VERBOSE", tag, msg);
return 0;
}
public static int d(String tag, String msg) {
@nathan815
nathan815 / awx_workflow_extra_data_tooltip.js
Last active February 5, 2021 19:05
AWX Workflows - Add an extra_data tooltip to workflow nodes
/*
AWX Workflow extra_data tooltips
This script adds a blue circle on each node, with a hover tooltip containing the node's extra_data.
It grabs each workflow node's extra_data from the angular component scope.
*/
(function () {
const workflowChart = document.querySelector('#aw-workflow-chart-g');
if (!workflowChart) return;
const scope = angular.element(workflowChart).scope();
if (!scope) return;