Skip to content

Instantly share code, notes, and snippets.

require 'fileutils'
# For use in cleaning scanned book/magazine/etc pages and preparing the scans
# for distribution/OCR.
#
# Assume you've been scanning a book as double-page scans. You can
# automatically split them into two files via ImageMagick `mogrify`:
#
# mogrify -path "./Auto-Halved Pages" -format png -crop 50%x100% +repage "./Double-Page Scans/*.png"
#
@Snarp
Snarp / superscripts_subscripts_normalized_via_nfkc.yml
Last active February 18, 2024 00:40
Unicode superscripts and subscripts normalized via NFKC
---
:subscripts:
"₀": '0'
"₁": '1'
"₂": '2'
"₃": '3'
"₄": '4'
"₅": '5'
"₆": '6'
"₇": '7'
@Snarp
Snarp / 01_tumblr_glitch_demonstration_text_raw.txt
Last active December 9, 2023 01:31
Tumblr WYSWIG editor formatting offset glitch raw demonstration text (the sourcing line is not part of the post)
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em#i_vs._em
<i> vs. <em>
Some developers may be confused by how multiple elements seemingly produce similar visual results. <em> and <i> are a common example, since they both italicize text. What's the difference? Which should you use?
By default, the visual result is the same. However, the semantic meaning is different. The <em> element represents stress emphasis of its contents, while the <i> element represents text that is set off from the normal prose, such as a foreign word, fictional character thoughts, or when the text refers to the definition of a word instead of representing its semantic meaning. (The title of a work, such as the name of a book or movie, should use <cite>.)
This means the right one to use depends on the situation. Neither is for purely decorative purposes, that's what CSS styling is for.
@Snarp
Snarp / HTML Named Color Keywords.md
Last active April 24, 2024 02:52 — forked from jennyknuth/README.md
140 html color names as an array of json objects—enjoy!

HTML Colors

All 140 HTML colors as JSON objects with fields:

  • name
  • hex
  • rgb
  • families

Changelog

@Snarp
Snarp / sticky_footer_example_flexbox.html
Last active December 7, 2023 18:50
Minimal sticky footer examples - vertical flexbox
@Snarp
Snarp / compress-pdf-with-gs.md
Created August 11, 2023 19:59 — forked from mammuth/compress-pdf-with-gs.md
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -r72 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dCompressFonts=true -sOutputFile=output.pdf input.pdf

Change -r for the resolution.

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
@Snarp
Snarp / hash_array_to_csv.rb
Created April 10, 2023 19:07
Array of hashes to CSV
require 'csv'
def hash_array_to_csv(hash_arr, fname='csv.csv')
headers = hash_arr.map{|hsh| hsh.keys}.flatten.uniq
csv = CSV.generate do |csv|
csv << headers
hash_arr.each do |hsh|
csv << (headers.map{|k| hsh[k]})
end
end
@Snarp
Snarp / exposeClassKeys.js
Created April 4, 2023 00:05 — forked from AprilSylph/exposeClassKeys.js
expose source names on Tumblr
tumblr.getCssMap().then(cssMap => {
const keys = Object.keys(cssMap);
const elements = document.querySelectorAll("[class]");
for (const {classList} of elements) {
for (const className of classList) {
const mappedClassName = keys.find(key => cssMap[key].includes(className));
if (mappedClassName) classList.add(`tumblr--${mappedClassName}`);
}
}
});
@Snarp
Snarp / oz_per_linear_yd_to_gsm.rb
Created October 30, 2022 23:41
Converts ounces per linear yard (a common measurement of fabric density in North America) to GSM (grams per square meter)
# Converts ounces per linear yard (a common measurement of fabric density in
# North America) to GSM (grams per square meter).
#
# When buying fabric, a "linear yard" refers to a yard-long piece of fabric cut
# from a bolt. Ounces per linear yard are calculated by weighing a bolt of
# fabric, then dividing its weight by its length in yards when fully unspooled.
# Fabric bolts may be of varying heights, but are generally more than 1 yard
# tall; 4-5 feet is a common height.
#
# (Q) Given this variability in bolt size, why do so many vendors describe
@Snarp
Snarp / jquery_ui_autocomplete_examples.html
Created May 27, 2022 23:52
JQuery UI autocomplete widget examples with various select/sort options
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Autocomplete Example - JQuery UI</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.min.js" integrity="sha256-eTyxS0rkjpLEo16uXTS0uVCS4815lc40K2iVpWDvdSY=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css" integrity="sha256-WKb0npL30v0SRtmMVowqx9a+gy3f7OZ+yffvMzJ2at8=" crossorigin="anonymous">