Skip to content

Instantly share code, notes, and snippets.

@jkominek
jkominek / solarcron.py
Created February 2, 2022 05:52
generate cron jobs based on sunrise/sunset, independent of daylight savings time
#!/usr/bin/env python3
import ephem
from datetime import datetime, timedelta, timezone
# don't generate any invocations until
SKIP_UNTIL = datetime(2021, 10, 16, 12, 0, 0)
# times to run per day
FOODS = 8
# thing to run
@jkominek
jkominek / 14impacts.txt
Created March 15, 2021 06:27
Grand piano hammer striking a CNY70 with roughly increasing intensity
This file has been truncated, but you can view the full file.
0.22188506458333335 0
0.22195119791666668 504
0.22201742291666668 511
0.22208362291666667 510
0.22214973125 511
0.22221593958333333 0
0.22228210625 511
0.22234823958333333 511
0.22241446875 504
0.22248198125 511
@jkominek
jkominek / casttojson.py
Created September 21, 2020 02:22
sqlalchemy postgresql poor man's custom types
# I had a fancy custom type in PG, and wanted to use it in
# SQLAlchemy. I didn't care to jump through all of the custom
# type stuff, and the type had an reasonable representation
# to JSON, and PG could convert it to/from JSON very easily.
# So I added cast conversions to PG, and then this special
# type:
class CastToJSONB(sqlalchemy.types.TypeDecorator):
'''A JSON object where we force PostgreSQL to cast our
interactions with the value to JSON. Useful when we've
got a PG data type that is a pain in the ass, but has an
@jkominek
jkominek / solo-piano-with-midi.ly
Last active October 22, 2019 06:12
Lilypond template for solo piano with correct dynamics and pedalling in the MIDI
\version "2.18.2"
\language "english"
right = \relative c'' {
\key c \major
\numericTimeSignature
\time 4/4
\tempo "Whatever" 4=60
% ...
}
@jkominek
jkominek / NumericNegationFunctionKeyExpression.java
Created August 12, 2019 21:32
numeric negation function key expression
age record.layer.demo;
import com.apple.foundationdb.record.metadata.expressions.FunctionKeyExpression;
import com.apple.foundationdb.record.metadata.expressions.QueryableKeyExpression;
import com.apple.foundationdb.record.metadata.expressions.KeyExpression;
import com.apple.foundationdb.annotation.API;
import com.apple.foundationdb.record.metadata.Key;
import com.apple.foundationdb.record.metadata.MetaDataException;
import com.apple.foundationdb.record.provider.foundationdb.FDBRecord;
import com.google.protobuf.Message;
@jkominek
jkominek / ami.rkt
Created June 15, 2015 23:20
Asterisk Manager Interface for Racket
#lang racket/base
(require racket/tcp racket/async-channel racket/match racket/function)
(define-struct ami [input-port
output-port thread
request-channel
response-channel
event-channel
[dead? #:mutable]]
@jkominek
jkominek / updatestars.py
Last active March 26, 2022 15:21
Maintain a mirror of all your Github stars.
#!/usr/bin/python
#################
# NOTE
# Now at https://github.com/jkominek/updatestars
#################
import requests
import json
import re
@jkominek
jkominek / KellysFavorite.java
Created May 28, 2015 23:59
Kelly's Favorite
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class KellysFavorite implements Player {
private ArrayList<Double> cache = new ArrayList<Double>();
@jkominek
jkominek / locked-boxes.rkt
Created May 28, 2015 18:28
inspectors & parameters to limit the dynamic extent values can be used within
#lang racket
; idea: use inspectors & parameters to protect values so they
; can't be used outside of approved dynamic extents.
; probably not fully baked? (continuations, etc)
; (define-values (b lock) (locked-box important-v key))
; (parameterize ([lock key])
; ; in here b can be used
; (less-trusted-code b))
#lang racket/base
(require racket/cmdline)
(define-syntax-rule
(while<> line body ...)
(let ([process-port
(lambda ()
(for ([line (in-port read-line)])
body ...))])