Skip to content

Instantly share code, notes, and snippets.

View junosuarez's full-sized avatar
💭
hi hello

juno suárez junosuarez

💭
hi hello
View GitHub Profile
@junosuarez
junosuarez / gist:c5a60a6bad213615ca2d4f2b1dc53f9a
Created April 24, 2024 16:38
Recover a docker run command from a running docker container
docker inspect \
--format "$(curl -s https://gist.githubusercontent.com/efrecon/8ce9c75d518b6eb863f667442d7bc679/raw/run.tpl)" \
name_or_id_of_your_running_container
# via https://stackoverflow.com/a/38077377
@junosuarez
junosuarez / gitstatus-prompt.zsh
Created October 28, 2022 07:46
starship + gitstatusd
#!/bin/zsh
# include this file in your shell config
autoload -Uz add-zsh-hook
# this file comes from installing https://github.com/romkatv/gitstatus
SOURCE "${HOMEBREW_PREFIX:-/usr/local}/opt/gitstatus/gitstatus.plugin.zsh" || return
gitstatusd_instance='GSD'
# the following are a mystery - why do they define the fn names with $1?
@junosuarez
junosuarez / gist:4003398
Created November 2, 2012 18:32
Micro-UMD format
/* The problem: writing boiler plate sucks.
* Writing modules that aren't portable between Node.js and AMD also sucks.
* Writing monolithic code (and not using modules) is perhaps worst of all, and
* should be punishable by death.
*
* UMD stands for Universal Module Definition (https://github.com/umdjs/umd)
* and provides boiler plate to create modules that work anywhere - but it's
* bulky.
*
* Here's a minimal implementation which makes certain assumptions about
@junosuarez
junosuarez / find-selection-vars.js
Last active April 17, 2023 21:21
A workaround for "broken" text selection on some sites in Chrome
// Find all css vars used in ::selection styles - use this snippet in dev tools
new Set(
Array.from(document.styleSheets)
.flatMap(s => { try { return Array.from(s.rules) } catch (e) { return [] } })
.filter(rule => rule.selectorText?.includes('::selection'))
.flatMap(rule => Array.from(rule.cssText.matchAll(RE_CSS_VAR))
.map(match => match.groups.varName)
)
)
@junosuarez
junosuarez / setup.md
Last active December 19, 2022 17:17
how to setup mastodon forwarding from your custom domain using webfinger and github pages

how to setup mastodon forwarding from your custom domain using webfinger and github pages

by @me@juno.lol

tldr

say you have your own domain, cool.example, and you'd rather use very@cool.example as your identity instead of cool23234543@mastodon.social. you can!

prerequisites

I'll assume you already have a repo setup with github pages turned on (or some other static site hosting), and that you already have a mastodon account somewhere.

theory

@junosuarez
junosuarez / π.js
Created January 9, 2020 06:11
Approximating π by simulation
/*
Approximating π by simulation
see live on runkit at https://runkit.com/junosuarez/5e16c3e9ccfea2001ae2c8f5
In 1733 the French naturalist Georges Louis Leclerc, Comte de Buffon, posed and
solved the following problem in geometric probability: when a needle of length L is
dropped onto a wooden floor constructed from boards of width D (where D ≥ L),
what is the probability that it will lie across a seam between two boards?
Buffon determined that the probability is 2L/Dπ.
via https://www.maa.org/sites/default/files/s1000042.pdf
@junosuarez
junosuarez / index.js
Last active June 21, 2019 01:32
async cli app boilerplate
#!/usr/bin/env node
if (process.mainModule === module) setImmediate(() => main(process.argv).catch(e => console.log(e.stack) && process.exit(1)))
async function main(argv) {
console.log(argv.slice(2))
}
@junosuarez
junosuarez / jq.sh
Created January 31, 2019 20:40
export repos
cat repos.json | jq '.repos | sort_by(.nameWithOwner) | .[].nameWithOwner | "https://github.com/\(.)"'
@junosuarez
junosuarez / gist:5394373
Created April 16, 2013 08:38
Explanation of liftA2 in JavaScript via http://www.techtangents.com/explanation-of-lifta2-in-javascript/ with examples rewritten in jsig

This came out of the recent JS Promises debate. @ForbesLindesay was confused by liftA2, so I thought I’d try to explain it.

Let me explain liftA2. I’ll tweak @pufuwozu’s examples so that they return values.

// Promises (called when both succeed)
liftA2(readFIle('hello.txt'), readFile('world.txt'), function(hello, world) {
 return hello + ' ' + world;
});
// Optional values (only inserted into database when both exist)

liftA2(optionalUsername, optionalPassword, function(username, password) {

@junosuarez
junosuarez / tap.js
Created September 11, 2012 23:19
Easily support tap events without modifying your click event handlers
/*global define: false, window: false */
define(['jquery'], function ($) {
'use strict';
return function () {
/* Begin monkey-patch Tap event support into $ */
var x = 0,
y = 0,
threshold = 40,
// Sometimes there is lag between the last update and touchend.