Skip to content

Instantly share code, notes, and snippets.

@well1791
well1791 / get_relevant_changes.py
Last active April 3, 2024 09:20
get_difference
from typing import Union, List, TypedDict
import unittest
type Filenames = List[str]
type Action = TypedDict('Action', {
'added': Filenames,
'removed': Filenames,
})
def get_relevant_changes(list_of_actions: List[Action]) -> Action:
@well1791
well1791 / _tide_pwd.fish.diff
Last active January 30, 2024 08:14
reduce dir levels tidy.fish
/// ~/.configh/fish/functions/_tide_pwd.fish
-if set -l split_pwd (string replace -r '^$HOME' '~' -- \$PWD | string split /)
+if set -l split_pwd (string replace -r '^$HOME' '~' -- \$PWD | string split /)[-2..]
// see https://github.com/IlanCosman/tide/issues/428#issuecomment-1765244274
@well1791
well1791 / bigram.ts
Last active June 11, 2023 22:29
get bigrams
// see: http://norvig.com/mayzner.html
all = [...document.querySelectorAll('tbody td')]
.filter((td) => td.title.includes(": "))
.map((td) => {
const [bi, val] = td.title
.split('%')[0]
.split(': ')
return [bi.toLowerCase(), Number(val)]
})
import type * as t from './types.d'
const ONE_IN_TO_CM = 2.54
const metricMap: t.UnitMap<t.MetricUnit> = {
mapList: ['km', 'hm', 'dam', 'm', 'dm', 'cm', 'mm'],
updater: {
inc: (a) => a * 10,
dec: (a) => a / 10,
}
@well1791
well1791 / ThemeProvider.tsx
Last active April 12, 2022 17:33
Stitches with a tailwindcss flavor
import * as React from 'react'
import { themes } from './theme'
import useCurrentTheme from './useCurrentTheme'
export type Props = {
children?: React.ReactNode
}
export function ThemeProvider({ children }: Props) {
@well1791
well1791 / matrix.js
Last active April 3, 2024 10:39
matrix function
const last = (arr) => arr.slice(-1)[0];
const init = (arr) => arr.slice(0, -1);
const matrix = (row, fnRow) => (col, fnItem) =>
[...Array(row * col).keys()].reduce((z, x) => {
const lastRow = last(z);
const initRows = init(z);
const item = fnItem(x);
if (lastRow.length < col) {
const rowUpdated = lastRow.concat(item);
@well1791
well1791 / spiral_operations.py
Last active April 3, 2024 10:25
spiral operations
import unittest
###
# Utility functions
###
def fromIndex(i, arr):
try:
return arr[i]
except:

Keybase proof

I hereby claim:

  • I am well1791 on github.
  • I am well1791 (https://keybase.io/well1791) on keybase.
  • I have a public key whose fingerprint is DBBF 8866 7E6A B660 1843 031F BE02 F52B 30AE 15AC

To claim this, I am signing this object:

@well1791
well1791 / bitwise.rb
Last active July 11, 2017 17:55 — forked from ggilder/fizz.rb
FizzBuzz
def fizzbuzz(n)
acc = 810092048
messages = [nil, "Fizz", "Buzz", "FizzBuzz"]
(1..n).each do |i|
c = acc & 3
puts messages[c] || i
acc = acc >> 2 | c << 28
end
end
const curryN = (n, f) => (...args) => args.length < n
? curryN(n, f).bind(null, ...args)
: f(...args);