Skip to content

Instantly share code, notes, and snippets.

View StevenJL's full-sized avatar

Steven Li StevenJL

  • Fountain Inc.
  • SF Bay Area
  • 11:35 (UTC -07:00)
View GitHub Profile
@StevenJL
StevenJL / coin_change.rb
Last active February 3, 2025 07:17
Coin Change
# https://leetcode.com/problems/coin-change/?envType=problem-list-v2&envId=oizxjoit
def coin_change(coins, amount)
# The cache remembers how many coins it takes to make a certain amount
cache = {}
coin_change_recurser(
original_amount: amount,
coins: coins.sort.reverse,
current_coin_count: 0,
@StevenJL
StevenJL / typescript_quirk.ts
Created January 8, 2025 22:58
TypeScript array conditional splatting quirk
// Consider an array of typed elements
type actions = "fart" | "burp" | "poop" | "barf"
let arrayOfActions: actions[] = [
"fart",
"burp",
"poop"
]
@StevenJL
StevenJL / find_moved_element.rb
Created September 11, 2024 06:56
find_moved_element
# Algorithm to detect delete/insertion change (ie. drag-n-drop) in array of unique elements
# From https://webshittery.com/blog/cumbersome-apis/
# Note that in certain situations where there is more than one correct answer
# For example:
#
# find_moved_element([1, 2, 3, 4, 5], [1, 3, 2, 4, 5]),
#
# Correct answers include:
#
@StevenJL
StevenJL / periodoxical_linked_in_discussion.rb
Created June 3, 2024 00:26
Periodoxical LinkedIn Discussion
# https://www.linkedin.com/feed/update/urn:li:activity:7202561717019578368?commentUrn=urn%3Ali%3Acomment%3A%28activity%3A7202561717019578368%2C7202905522717552640%29&dashCommentUrn=urn%3Ali%3Afsd_comment%3A%287202905522717552640%2Curn%3Ali%3Aactivity%3A7202561717019578368%29
# Schedule A is a meeting every other Monday at 4pm
# Schedule B is a reminder email for the meeting sent 2 days before it
require "periodoxical"
schedule_a = Periodoxical.generate(
time_zone: 'America/Los_Angeles',
start_date: '2024-06-02',
@StevenJL
StevenJL / .ctags
Created March 25, 2024 22:30
ctags config for tsx support
# Typescript TSX ctags
# Based on https://github.com/romainl/ctags-patterns-for-javascript/blob/d965c4abfd00e438a24f6f828b5a1d00258f330c/ctagsrc
--langdef=tsx
--langmap=tsx:.tsx
# These are the added ctags
--regex-tsx=/^[ \t]*(export[ \t]{1,})?type[ \t]{1,}([A-Za-z0-9_$]{1,})/\2/t,Type,Types/{pcre2}
--regex-tsx=/^[ \t]*(export[ \t]{1,})?interface[ \t]{1,}([A-Za-z0-9_$]{1,})/\2/t,Type,Types/{pcre2}
@StevenJL
StevenJL / aoc2002.txt
Last active December 11, 2022 07:23
aoc2022
# _____ _ _ _____ ______ ______ ______ ______ ______ ______ ______ _______
# / ____| | | |_ _| ____| ____| ____| ____| ____| ____| ____|__ __|
# | (___ | |__| | | | | |__ | |__ | |__ | |__ | |__ | |__ | |__ | |
# \___ \| __ | | | | __| | __| | __| | __| | __| | __| | __| | |
# ____) | | | |_| |_| |____| |____| |____| |____| |____| |____| |____ | |
# |_____/|_| |_|_____|______|______|______|______|______|______|______| |_|
######################## Day 1 ################################
@StevenJL
StevenJL / zsmnli_chatbot.py
Last active July 31, 2022 03:57
Zero-shot MNLI Chatbot Demo
#
# ```
# which python3
# pip3 install torch
# pip3 install transformers
# ```
import numpy as np
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
@StevenJL
StevenJL / slow_running_queries.sql
Last active September 1, 2021 07:44
Slowest queries right now
# See the slowest queries right now
SELECT
pid,
age(clock_timestamp(), query_start) as time_running,
substr(query, 0, 75)
FROM pg_stat_activity WHERE state != 'idle'
ORDER BY time_running DESC;
# pid | time_running | query
@StevenJL
StevenJL / psql_connections.sql
Last active July 27, 2021 06:12
See postgres connections
SELECT state, COUNT(*) FROM pg_stat_activity
WHERE pid <> pg_backend_pid()
GROUP BY 1;
# state | count
# ---------------------+-------
# active | 7
# idle | 569
# idle in transaction | 2
# | 9
@StevenJL
StevenJL / blocking_queries.sql
Created June 15, 2021 07:00
Blocking Queries
SELECT blocked_activity.query AS blocked_statement,
blocking_activity.query AS current_statement_in_blocking_process
FROM pg_catalog.pg_locks blocked_locks
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks blocking_locks
ON blocking_locks.locktype = blocked_locks.locktype
AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple