Skip to content

Instantly share code, notes, and snippets.

View mcsf's full-sized avatar

Miguel Fonseca mcsf

View GitHub Profile
@mcsf
mcsf / work.sh
Last active September 24, 2018 10:42
#!/bin/bash
for app in \
Docker \
Slack \
Firefox\ Developer\ Edition
Your\ Other\ Work\ Applications
do
echo -n "Launch $app? [Yn] "
read answer
@mcsf
mcsf / posts-blocks-endpoint.php
Created September 1, 2018 09:18
(For testing purposes) WP API endpoint for parsing a post for blocks.
<?php
/**
* Plugin Name: Blocks endpoint for Posts
* Description: —
*/
add_action( 'rest_api_init', 'mcsf_register_post_blocks_endpoint' );
function mcsf_register_post_blocks_endpoint() {
register_rest_route(
'wp/v2', '/posts/(?P<id>[\d]+)/blocks', array(
#!/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
diff --git a/lib/blocks.php b/lib/blocks.php
index e28971bad..a2c1d0a89 100644
--- a/lib/blocks.php
+++ b/lib/blocks.php
@@ -177,14 +177,18 @@ function do_blocks( $content ) {
}
}
- // Replace dynamic block with server-rendered output.
- $rendered_content .= $block_type->render( $attributes );
@mcsf
mcsf / roman-numerals.py
Created March 24, 2018 21:59
Detect and wrap roman numerals with a special "small-caps" span tag
#!/usr/bin/env python
import sys
import re
re_full = r'(MMM|MM|M)?(CM|CD|DCCC|DCC|DC|D|CCC|CC|C)?(XC|XL|LXXX|LXX|LX|L|XXX|XX|X)?(IX|IV|VIII|VII|VI|V|III|II|I)?'
re_appr = r'\b[MDCLXVI]+\b'
def wrap_roman(matchobj):
s = matchobj.group(0)
@mcsf
mcsf / github-copy-pull-request
Last active February 5, 2018 13:03
Given a GitHub pull request or issue, this bookmarklet copies a string of "<title> <url>"
javascript:(function() { var s=getSelection(),r=document.createRange(),e=document.createElement('input'); e.value=[document.querySelector('.js-issue-title').innerText,location.origin+location.pathname].join(' '); document.body.appendChild(e); r.selectNode(e); s.removeAllRanges(); s.addRange(r); document.execCommand('copy'); e.remove(); }());
/**
* Please don't use this pattern.
*
* Explores a sweetened syntax for (p)react event handlers akin to Vue's, which
* allows:
* - <my-el v-on:click="say" />
* - <my-el v-on:click="say( 'hi' )" />
* - <my-el v-on:click="counter += 1" />
*
* In this case, the following become possible:
@mcsf
mcsf / concat-flips.js
Created August 22, 2017 17:49
Coin-flip chaining: more concision with `lift`
import { concat, liftN } from 'ramda'
const flip = () => [ [ 'h' ], [ 't' ] ]
const concatFlips = liftN(2, concat)
const twoFlips = concatFlips(flip(), flip())
const threeFlips = concatFlips(twoFlips, flip())
twoFlips
// [ [ 'h', 'h' ], [ 'h', 't' ], [ 't', 'h' ], [ 't', 't' ] ]
@mcsf
mcsf / git-better-checkout.md
Created August 12, 2017 16:57
Better ways to switch between Git branches

A GIF worth a thousand words

self-explanatory gif

git-recent

cat ~/bin/git-recent
if (typeof Object.assign != 'function') {
// from MDN
Object.assign = function(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);