Skip to content

Instantly share code, notes, and snippets.

View mcsf's full-sized avatar

Miguel Fonseca mcsf

View GitHub Profile
@mcsf
mcsf / derp-case.js
Created August 7, 2020 14:34
It's a silly world out there.
#!/usr/bin/env node
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false,
});
set -e
# Clean
if pgrep -f Docker.app ; then
echo "Please manually quit Docker and try again."
exit 1
fi
# Prep
echo "Starting Docker daemon…"
#!/bin/sh
ffmpeg -i "$1" -vf "fps=10,scale=740:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
@mcsf
mcsf / my-test.php
Last active March 19, 2020 06:19
[Per Slack request] Illustrating the use of WordPress data selectors in conjunction with React hooks to react to post saving within a custom sidebar in Gutenberg. Move advanced entity-centric selectors may be used from the 'core' store instead.
<?php
/*
Plugin Name: Test
*/
function my_test_enqueue_scripts() {
wp_enqueue_style(
'my-test-style',
plugins_url( 'style.css', __FILE__ )
);
@mcsf
mcsf / proj.sh
Created March 9, 2020 10:48
Given a command such as "docker-compose up", identifies the project root (the nearest ancestor containing e.g. "docker-compose.yml") and runs the command from there
#!/bin/sh
set -e
callee="$1"
invocation="$@"
target=""
case "$callee" in
docker-compose)
#!/bin/bash
TEST_SUITE="change-detection"
TEST_NAME="consecutive edits"
E2E_PATCH="bisect-e2e.diff"
skip() {
echo Skipping: $@; exit 125
}
let mapleader = " "
let maplocalleader = " "
filetype plugin on
" === Begin Plug
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
@mcsf
mcsf / .ctags
Created July 4, 2019 12:43
ctags definitions for ES6 JavaScript
--langdef=js
--langmap=js:.js
--regex-js=/(export )?function\*?[ \t]+([A-Za-z0-9_$]+)[ \t]*\([^)]*\)/\2/,function/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\{/\5/,object/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*function\*?[ \t]*\(/\5/,function/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*\[/\5/,array/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[^"]'[^']*/\5/,string/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*(true|false)/\5/,boolean/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*[0-9]+/\5/,number/
--regex-js=/(,|(;|^)[ \t]*(var|let|const|([A-Za-z_$][A-Za-z0-9_$.]+\.)*))[ \t]*([A-Za-z0-9_$]+)[ \t]*=[ \t]*.+([,;=]|$)/\5/,variab
#!/bin/bash
INPUT="$1"
OUTPUT=$(perl -C -Mutf8 -pe 's/\.mp4$/.converted.mp4/i' <<< "$INPUT")
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
RESET=$(tput sgr0)
#!/bin/bash
# Given an input documentation file, output all JavaScript code snippets
# contained therein.
INPUT_DOC="$1"
OPENING_LINES=$( sed -n '/^```js$/=' "$INPUT_DOC" )
for LINE in $OPENING_LINES; do