Skip to content

Instantly share code, notes, and snippets.

View r-k-b's full-sized avatar

Robert K. Bell r-k-b

View GitHub Profile
@r-k-b
r-k-b / type-safety-for-redux-loop-cmd-run.md
Created December 19, 2018 05:09
Getting type safety when using redux-loop's `Cmd.run`

The recommended usage of [redux-loop]'s [Cmd.run] lacks type safety, which is problematic when a project relies on TypeScript.

Firstly, the args are typed any, and will not error when they don't match the arguments of the function to be run.

Second, the arguments to successActionCreator don't need to match the return type of the function to be run.

Replace usages of Cmd.run with typesafeCmdRun to get type safety.

@r-k-b
r-k-b / test.js
Last active August 28, 2018 01:24
jQuery.ready(function(){
let target = $('[data-ng-show="payment.paymentType === PaymentType.InternetBanking && canPayBy(PaymentType.InternetBanking)"]')
let temporaryMessage = '<p><strong>Poli Payments are temporarily unavailable.'+
' If you are unable to pay with credit card, please contact us on 1800 884 305.' +
'</p>'
target.replaceWith(temporaryMessage)
});
@r-k-b
r-k-b / report-used-fonts-on-page.js
Last active June 5, 2018 23:47
Report on the font families & weights used on all elements in a page
// Based on https://stackoverflow.com/a/39900099/2014893
// https://gist.github.com/r-k-b/8ae1a7d47ee41b4c53eec603e4f1e2ac
function listFonts () {
let fonts = []
for (let node of document.querySelectorAll('*')) {
if (!node.style) continue
for (let pseudo of ['', ':before', ':after']) {
@r-k-b
r-k-b / email-subscription-states.dot
Last active April 9, 2018 22:44
Email subscription "state machine"
digraph G {
"new user" -> "double opt-in\nrequested";
"double opt-in\nrequested" -> "double opt-in\nconfirmed";
"new user" -> "unsubscribed" [color=grey];
"double opt-in\nrequested" -> "unsubscribed" [color=grey];
"double opt-in\nconfirmed" -> "unsubscribed";
}
@r-k-b
r-k-b / xml-picker.cs
Created April 5, 2018 03:20
c# one-offs
// Pick fields from an XML doc to create an object, without having to recreate the whole XML structure in C#
var rawXml = "<ms:list xmlns:ms=\\\"http:\\/\\/www.marketingstudio.com\\/API\\/Gateway\\\"><ms:t101><ms:fld_3000>13045525<\\/ms:fld_3000><ms:fld_3001>Booked<\\/ms:fld_3001><ms:fld_3002>S-2308222<\\/ms:fld_3002><ms:fld_3003>robert.bell@envoyat.com<\\/ms:fld_3003><ms:fld_3004>2018-03-28T14:18:42<\\/ms:fld_3004><ms:fld_3005><\\/ms:fld_3005><ms:fld_3006>2<\\/ms:fld_3006><ms:fld_3007>ADL<\\/ms:fld_3007><ms:fld_3008>S-2308222<\\/ms:fld_3008><ms:fld_3009>MD<\\/ms:fld_3009><ms:fld_3010>N<\\/ms:fld_3010><ms:fld_3011>2018-08-01T19:30:00<\\/ms:fld_3011><ms:fld_3012>SPIRIT17<\\/ms:fld_3012><ms:fld_3013>SAVER<\\/ms:fld_3013><ms:fld_3014>N<\\/ms:fld_3014><ms:fld_3015>N<\\/ms:fld_3015><ms:fld_3016>N<\\/ms:fld_3016><ms:fld_3017>Y<\\/ms:fld_3017><ms:fld_3018>N<\\/ms:fld_3018><ms:fld_3020>N<\\/ms:fld_3020><ms:fld_3021>N<\\/ms:fld_3021><ms:fld_3022>N<\\/ms:fld_3022><ms:fld_3100><\\/ms:fld_3100><\\/ms:t101><\\/ms:list>";
@r-k-b
r-k-b / cartesian-product.py
Created September 26, 2017 03:09
Quickly enumerate a human-readable Cartesian Product for some choices.
import itertools
somelists = [
[
'There is no last-seen catalog for this product',
'The last-seen category is the same as the current category',
'The last-seen category is different to the current category',
],
[
'The last-seen category matches to a BigCommerce category',
'The last-seen category does not match to a BigCommerce category',
@r-k-b
r-k-b / slack-wide-attachment-groups.user.css
Created July 20, 2017 23:15
Allow full-width "attachment groups" in Slack.
@-moz-document domain("*.slack.com") {
.attachment_group {
max-width: 100%;
}
}
@r-k-b
r-k-b / bc-webapp-field-schema-helper.markdown
Last active July 24, 2017 03:57
BC webapp field schema helper

BC webapp field schema helper

BC webapp fields are too obtuse ("What does CAT_Custom_48142 represent, again?"), and they're a pain to write out. Grab the select option HTML from the admin UI (under 'Edit Webapp Fields'), and paste the options in here.

A Pen by Robert K. Bell on CodePen.

License.

@r-k-b
r-k-b / BC webapp admin UI schema.js
Created July 13, 2017 06:04
BC webapp admin UI schema
const ordering = ['fieldID', 'type', 'mandatory', 'dataSourceID', 'useWYSIWYG', 'unknownProperty']
const fieldTypes = {
'1': 'Text (string)',
'3': 'Boolean',
'5': 'List (Dropdown List)',
'8': 'Media',
'6': 'List (Checkbox List)',
'9': 'Text (Multiline)',
'11': 'Hyperlink',
@r-k-b
r-k-b / dump-liquid-scope-to-console.html
Last active July 20, 2017 05:58
A quick way to inspect the contents of the Global Scope in Liquid Markup, using the browser's dev tools.
<script type='text/javascript' data-source='https://gist.github.com/r-k-b/6617f49ec6922050802471ff229f7e86'>
// # dump-liquid-scope-to-console
//
// A quick way to inspect the contents of the Global Scope in Liquid Markup, using the browser's dev tools.
(function () {
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;