Skip to content

Instantly share code, notes, and snippets.

View justinline's full-sized avatar

Justin Focus justinline

View GitHub Profile
@justinline
justinline / mob-research.tsx
Last active April 7, 2025 10:20
Digging into mobx + refetching. In this example, the data gets automatically refetched by mobx when the data from another store changes but only when the data that is being observed (in this case poked data) is being used in a mounted component
import { makeAutoObservable } from 'mobx';
import { observer } from 'mobx-react';
import { createContext, useContext } from 'react';
// ====== Stores ======
/** Stores Pokemon Search information */
class PokemonSearchStore {
name: string;
constructor() {
@justinline
justinline / day1.js
Created December 3, 2023 00:24
Advent of Code day 1
// Done purely in the browser console, using temp1 which is the input text as a Global Variable
// Might not give actual results, I started creating gists on day 2 and mostly recovered this from console history! 😆
const text = () => temp1.textContent.split('\n')
const getFirstAndLastInteger = (str) => {
const integers = str.split('').map(s => Number(s)).filter(Boolean)
return Number(`${integers[0]}${integers[integers.length - 1]}`)
}
@justinline
justinline / day2.js
Created December 3, 2023 00:15
Advent of code day 2
// Done in browser console only
// Saved text input as Global Variable to access temp1
const games = temp1.textContent.split('\n')
const regex = /(\d+) (green|red|blue)/g
const asObjects = games.map(game => [...game.matchAll(regex)].reduce((colors, matches) => {
const [_, number, color] = matches
@justinline
justinline / async-await.js
Created May 29, 2021 14:20
async/await with generators
// Recursively evaluates generator values
function customAsync(generatorFn) {
const generator = generatorFn();
const resolve = (generatorResult) => {
const noMoreIterations = generatorResult.done;
if (noMoreIterations) {
return Promise.resolve(generatorResult.value);
}
@justinline
justinline / generateLogger.ts
Last active December 13, 2023 10:44
Javascript generator logger
type LoggerProps = {
user: string;
status: string;
}
/** Generator function to log data, useful for understanding how yield works in generator calls */
function* generateLogger({user, status}: LoggerProps) {
while (true) {
const data = yield;
console.log(`${Date.now()} -- ${status} ${user}: ${data}`)
}
// Run on bitbucket PR overview page for an idea of metrics: qty, authors, reviewers
function getPRAuthors(){
return document.querySelectorAll('td.pull-request-author');
}
function getPRReviewers(){
return document.querySelectorAll('td.reviewers');
}
@justinline
justinline / 1password clipboard
Last active November 7, 2024 00:06
1password command line clipboard copying
# Short alias to allow automated copying of the 1password cli tool command 'op get somewebsite | jq ...' and then a timed clear on the gnome clipboard
# TODO: specify designation as an argument and maybe a command to open the website in chrome
pass=$(op get item $1 | jq -r '.details.fields[] | select(.designation=="password").value')
if [ -n "$pass" ]
then
echo $pass | xclip -selection clipboard
echo "Password was copied - clipboard will be wiped in 15 seconds"
sleep 15
import json
from django.core.management.base import BaseCommand, CommandError
from django.apps import apps
class Command(BaseCommand):
help = 'Takes a model argument in the form of app_label.model_name and outputs all fields and values as JSON'
def add_arguments(self, parser):
parser.add_argument('model', nargs="1", help='A model argument in the form of app_label.model_name')
'''
Prints a cutting list for all linear dims on a layout page - Rhino for Mac
Requires dims to be on unique layer name. Must also select the detail view that dim is scaled on to find scale factor.
'''
import Rhino
import scriptcontext
import System.Guid, System.Drawing.Color
import re
import rhinoscriptsyntax as rs
from collections import Counter
@justinline
justinline / coachella_picker.html
Created January 4, 2018 18:01
A javascript snippet to pick a random coachella performer 2018 to listen to.
<!DOCTYPE html>
<html>
<head>
<title>COACHELLA PICKER</title>
</head>
<body>
<script>
function randInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);