Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
wesleybliss / currency-flags.dart
Created March 17, 2025 04:45
Map of currency codes to unicode flag symbols
final Map<String, String> currencyFlags = {
"COP": "🇨🇴",
"USD": "🇺🇸",
"AED": "🇦🇪",
"AFN": "🇦🇫",
"ALL": "🇦🇱",
"AMD": "🇦🇲",
"ANG": "🇳🇱",
"AOA": "🇦🇴",
"ARS": "🇦🇷",
@wesleybliss
wesleybliss / html_table_to_csv.js
Created March 17, 2025 04:21
Converts a basic HTML table into a CSV
(function() {
const result = []
const tables = [...document.querySelectorAll('table')]
const quoteRow = cols => ('"' + cols
.map(it => it.textContent || '')
.join('","') + '"')
for (let i = 0, m = tables.length; i < m; i++) {
@wesleybliss
wesleybliss / download_text_as_file.js
Created March 15, 2025 01:53
Download a string as a file
const downloadCsv = (text, filename, encoding = 'text/plain') => {
// text/csv
const blob = new Blob([csvString], { type: encoding })
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.setAttribute('href', url)
a.setAttribute('download', filename || 'download.txt')
a.style.display = 'none'
@wesleybliss
wesleybliss / squarespace-dns-to-csv.js
Created March 4, 2025 17:45
Backup Squarespace DNS configs to CSV
const section = document.querySelector('[data-testid="desktop-custom-records"]')
const table = section.nextElementSibling.querySelector('table')
const headers = [...table.querySelector('thead')
.querySelector('tr')
.querySelectorAll('th')
].map(it => it.innerText)
const rows = table.querySelector('tbody').querySelectorAll('tr')
const csv = [headers]
for (let i = 0; i < rows.length; i++) {
@wesleybliss
wesleybliss / delete_sequelize_junk_indexes.js
Created February 20, 2023 23:46
Deletes extra junk indexes created by Sequelize when using alter: true
// https://github.com/sequelize/sequelize/issues/8984#issuecomment-738790473
// Here is a workaround to delete new indices after calling sequelize.sync({alter: true});
// Be careful, this will delete all indices of the current database that ends with a number after an underline character (e.g. index_1)
const rawTables = await this.sequelize.query("SHOW TABLES")
const tables = rawTables[0].map(i => i[Object.keys(rawTables[0][0])[0]])
for (const t of tables) {
const rawKeys = await this.sequelize.query(`SHOW INDEX FROM ${t}`)
@wesleybliss
wesleybliss / postgres_find_missing_indexes_2.sql
Created February 20, 2023 23:41
Find all missing indexes (version #2)
-- https://www.cybertec-postgresql.com/en/index-your-foreign-key/
SELECT c.conrelid::regclass AS "table",
/* list of key column names in order */
string_agg(a.attname, ',' ORDER BY x.n) AS columns,
pg_catalog.pg_size_pretty(
pg_catalog.pg_relation_size(c.conrelid)
) AS size,
c.conname AS constraint,
c.confrelid::regclass AS referenced_table
@wesleybliss
wesleybliss / postgres_find_missing_indexes_1.sql
Last active February 20, 2023 23:42
Find all missing indexes (version #1)
-- https://stackoverflow.com/a/33293747/717949
-- NOTE: the WHERE condition at the end can be removed for smaller tables
-- check for FKs where there is no matching index
-- on the referencing side
-- or a bad index
WITH fk_actions ( code, action ) AS (
VALUES ( 'a', 'error' ),
( 'r', 'restrict' ),
@wesleybliss
wesleybliss / EditableText.jsx
Created February 7, 2023 20:33
Editable text input field in React
import { useRef, useState, useEffect, useCallback } from 'react'
import cn from 'classnames'
import './EditableText.css'
const EditableText = ({
className,
inputClassName,
as: ElementTag = 'span',
value,
@wesleybliss
wesleybliss / Replace random key
Created September 28, 2022 19:58
Replace letters in a key with either uniform alpha or random letters
const randomInt = (from, to) => Math.floor(Math.random() * (to - from + 1) + from)
const rs = (input, random = false) => {
const len = input.length
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
const lower = 'abcdefghijklmnopqrstuvwxyz'.split('')
let lastUpper = -1
let lastLower = -1
let output = ''
@wesleybliss
wesleybliss / split_view.dart
Created July 7, 2022 04:47
Resizable split view widget
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// 2022-07-06 Updated to null safety
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
/// A widget that takes two children, lays them out along [axis], and allows
/// the user to resize them.