Skip to content

Instantly share code, notes, and snippets.

View TehShrike's full-sized avatar
Shiny.

Josh Duff TehShrike

Shiny.
View GitHub Profile
@TehShrike
TehShrike / parse_csv_line.ts
Created March 13, 2024 15:33
parse a csv line
import test from 'lib/tester';
const parse_csv_line = (line: string): string[] => {
const chunks: string[] = [];
let inside_quotes = false;
let current_chunk = '';
for (let i = 0; i < line.length; ++i) {
const char = line[i];
@TehShrike
TehShrike / get_utc_offset.mjs
Last active April 8, 2022 15:15
get utc offset
import tz_tokenize_date from './tz_tokenize_date.mjs'
const ZERO_HOUR_UTC = `T00:00:00.000Z`
const ZERO_HOUR_MINUS_TWENTY_HOURS_UTC = `T00:00:00.000-20:00`
const ZERO_HOUR_PLUS_TWENTY_HOURS_UTC = `T00:00:00.000+20:00`
export const day_to_offset_at_start_of_day = (iana_timezone_string, iso_day_string) => {
const valid_offset = [
iso_day_string + ZERO_HOUR_MINUS_TWENTY_HOURS_UTC,
iso_day_string + ZERO_HOUR_UTC,
1 cup water
1Tbsp active yeast
1tsp honey
2 eggs, room temperature, slightly beaten
1 cup oat fiber
2/3 cup ground golden flax meal
1 cup vital wheat gluten
1/2tsp xanthum gum
1tsp salt
2Tbsp softened butter
@TehShrike
TehShrike / get_timezone_offset_for_point_in_time.js
Created April 19, 2021 17:39
get_timezone_offset_for_point_in_time
// from https://github.com/bsvetlik/date-fns-tz/blob/eb2bb6209931c5abe1cfcdf2faaa41de5493648a/src/_lib/tzParseTimezone/index.js#L86-L98
export default (iana_timezone_string, date_object) => {
const [ year, month, day, hour, minute, second ] = tz_tokenize_date(
date_object,
iana_timezone_string,
)
const asUTC = Date.UTC(year, month - 1, day, hour, minute, second, date_object.getMilliseconds())
return asUTC - date_object.getTime()
@TehShrike
TehShrike / .eslintrc.js
Last active November 16, 2020 15:27
.eslintrc.js
const warn = [ 'warn' ]
const error = [ 'error' ]
const never = [ 'warn', 'never' ]
const always = [ 'warn', 'always' ]
const asNeeded = [ 'error', 'as-needed' ]
module.exports = {
plugins: [
// 'html',
@TehShrike
TehShrike / date-range-input.js
Last active July 24, 2023 17:39
Svelte custom element wrapper
import DateRangeInput from "@equipmentshare/date-range-input"
import makeCeFromSvelte from "common/svelte-ce"
export default makeCeFromSvelte(DateRangeInput, {
mirrorProps: [ "start", "end", "visibleStartMonth", "visibleEndMonth" ],
requiredToInstantiate: [ "start", "end" ],
mirrorEvents: [ "change" ],
// Shouldn't be necessary now that https://github.com/sveltejs/svelte/issues/3940 is fixed
initialHtml: "<style>@import './date-range-input/component.css';</style>",
@TehShrike
TehShrike / weekday-names.js
Created January 21, 2020 23:04
The names of the days of the week using browser locale
const anArbitrarySundayEarlyInTheMonth = new Date(2020, 0, 5)
const dayNumbers = [ 0, 1, 2, 3, 4, 5, 6 ]
const formatter = new Intl.DateTimeFormat(undefined, {
weekday: `short`,
})
const weekdayNames = dayNumbers.map(dayNumber => {
const date = new Date(anArbitrarySundayEarlyInTheMonth)
date.setDate(date.getDate() + dayNumber)
return formatter.format(date)
const Jimp = require(`jimp`)
const imagemin = require('imagemin')
const imageminPngquant = require('imagemin-pngquant')
const { readdirSync } = require(`fs`)
const { join } = require(`path`)
const relativeToThisFile = relativePath => join(__dirname, relativePath)
const inputPath = relativeToThisFile(`../../book-cover-image`)
const outputPath = relativeToThisFile(`../../Markdown/Web/book-image/thumbnail`)
@TehShrike
TehShrike / daysInMonth.js
Last active January 10, 2020 19:43
daysInMonth.js
// An expansion of https://stackoverflow.com/a/1184359/201789
function daysInMonth (oneIndexedInputMonth, year) {
const zeroIndexedInputMonth = oneIndexedInputMonth - 1
const theNextZeroIndexedMonth = zeroIndexedInputMonth + 1
const theFinalDayOfThePreviousMonth = 0
return new Date(year, theNextZeroIndexedMonth, theFinalDayOfThePreviousMonth).getDate()
}
@TehShrike
TehShrike / command.sh
Created July 4, 2019 11:50
Sublime Text as git editor
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"