Skip to content

Instantly share code, notes, and snippets.

@kpmiller
kpmiller / SFSymbolToPNG.py
Last active March 14, 2022 21:46
Create a PNG from a SF Symbol for a Stream Deck icon, Mac only (requires pyobjc bridge), tested on MacOS Monterey and python 3.8.9
#!/usr/bin/env python3
import Cocoa #from PyObjC, https://pyobjc.readthedocs.io/
import argparse
import sys, re
#taken from https://stackoverflow.com/questions/29643352/converting-hex-to-rgb-value-in-python
def hex_to_rgb(hx, hsl=False):
"""Converts a HEX code into RGB or HSL.
Args:
@kpmiller
kpmiller / ElementLabels.py
Created December 23, 2021 23:10
Source for making labels for spice jars
#!/usr/bin/env python3
import Quartz
from Quartz.CoreGraphics import *
import Cocoa
# element : [ element width, name width word 1, name width word 2 (or 0.0), name ]
labels = {
"Cp" : [0.0, 0.0, 0.0, "Chili Powder"],
"Bs" : [0.0, 0.0, 0.0, "Black Sesame"],
@kpmiller
kpmiller / automator-insert-date-time
Last active April 1, 2021 17:34
python automator workflow for inserting time and date
import datetime
print (datetime.datetime.now().strftime("%d %b %Y %-H:%M %p"))
@kpmiller
kpmiller / ironsudoku-bookmarklets.js
Created December 29, 2020 18:33
A collection of bookmarklets for the ironsudoku.com site
//bookmaklet to fill in current puzzle with all pencil marks
// I don't know the source of this
javascript:javascript:var%20kMax=1;for(i=1;i<10;i++){var%20lMax=1;if(i==kMax)kMax+=3;for(j=1;j<10;j++){if(j==lMax)lMax+=3;if(grid[i][j].value==''){ClearTinySquares(i,j);for(k=1;k<10;k++)grid[i][j]['mini'][k]=1;for(k=1;k<10;k++){var%20tmp=grid[i][k].value;if(tmp!='')grid[i][j]['mini'][tmp]=0;tmp=grid[k][j].value;if(tmp!='')grid[i][j]['mini'][tmp]=0}for(k=kMax-3;k<kMax;k++){for(l=lMax-3;l<lMax;l++){var%20tmp=grid[k][l].value;if(tmp!='')grid[i][j]['mini'][tmp]=0}}}}}PopulatePuzzle(grid);
//bookmarklet to show alert with puzzle in good sudoku format
javascript:(function()%7Bms%20%3D%20master_string%20%2B%20'%2C'%3Bga%20%3D%20ms.split('%2C')%3Bgg%20%3D%20%22%22%3Bfor%20(j%3D0%3B%20j%3C41%3B%20j%2B%2B)%20%7Bi%20%3D%20j*2%3Bif%20(ga%5Bi%5D%20!%3D%20%22%22)%20%7Bs%20%3D%20parseInt(ga%5Bi%5D)%3B%7Delse%20%7Bs%20%3D%200%3B%7Dif%20(ga%5Bi%2B1%5D%20!%3D%20%22%22)%20%7Bt%20%3D%20parseInt(ga%5Bi%2B1%5D)%7Delse%20%7Bt%20%3D%200
@kpmiller
kpmiller / ironsudoku-ss.js
Last active December 29, 2020 18:28
javascript to convert the current puzzle to Simple Sudoku (.ss) format from ironsudoku.com
ga=master_string.split(',');
gg="";
for (j=0;j<81;j++){
if (ga[j]=="")gg=gg+".";
else gg=gg+ga[j];
if (j==0) continue;
else if (j==80) break;
else if (j%27==26) gg=gg+"\n---+---+---\n";
else if (j%9==8) gg=gg+"\n";
else if (j%3==2) gg=gg + "|";
@kpmiller
kpmiller / goodsudoku.py
Created December 28, 2020 21:06
Good Sudoku clipboard format
#!/usr/bin/env python3
import base64
#Good Sudoku's share puzzle clipboard format
#given the starting puzzle:
#7.. 64. 2..
#.6. 7.. 4..
#..8 ..5 .9.
#
//
// main.c
// Sodoku
//
// Created by Kent Miller on 4/7/20.
// Copyright © 2020 Kent Miller. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
@kpmiller
kpmiller / vscode_xcode.txt
Last active March 5, 2020 16:13
Make visual studio code's multi cursor settings match Xcode
in keybindings.json
[
{ "key": "shift+ctrl+down", "command": "cursorColumnSelectDown",
"when": "editorTextFocus" },
{ "key": "shift+ctrl+up", "command": "cursorColumnSelectUp",
"when": "editorTextFocus" },
{ "key": "PageUp", "command": "scrollPageUp",
"when": "editorTextFocus" },
{ "key": "PageDown", "command": "scrollPageDown",
@kpmiller
kpmiller / rgbshades.py
Created April 1, 2019 18:24
python colorsys
#!/usr/bin/python
import colorsys
def PrintHex(v):
vv0 = v[0] * 255.0
vv1 = v[1] * 255.0
vv2 = v[2] * 255.0
print ( "#%02X%02X%02X" % (vv0, vv1, vv2))
@kpmiller
kpmiller / quartzexample.py
Created September 11, 2018 18:58
Example of using core graphics from quartz to make a pdf file, using Apple built in python bindings
#!/usr/bin/python
#tested on 10.12 and 10.13
import Quartz
from Quartz.CoreGraphics import *
import Cocoa
import random
random.seed()