Skip to content

Instantly share code, notes, and snippets.

View justinline's full-sized avatar
🌈

Justin Focus justinline

🌈
View GitHub Profile
@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 December 13, 2023 10:34
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);
@justinline
justinline / html_tags.py
Created November 28, 2017 20:02 — forked from epicserve/html_tags.py
Example of using bleach to strip out bad/evil code.
from django import template
from django.utils.safestring import mark_safe
import bleach
register = template.Library()
@register.filter
def strip_tags(text, valid_tags=['p', 'a', 'strong', 'em', 'ol', 'ul', 'li']):
if not isinstance(valid_tags, list):