Skip to content

Instantly share code, notes, and snippets.

@lionel-rowe
lionel-rowe / cs_it_cloud_learning_resources.md
Last active October 30, 2018 00:09
Learning Resources (CS/Cloud/Tech Writing)
@lionel-rowe
lionel-rowe / linux-terminal.md
Last active October 17, 2018 10:11
Useful terminal commands/shortcuts (Linux::Ubuntu)

Useful terminal commands and shortcuts (Linux::Ubuntu)

Commands

  • sudo apt-get install <pkg name> install package
  • sudo apt-get remove <pkg name> remove package
  • apt list | grep <txt to search> search currently installed packages
  • xkill kill an unresponsive window w. mouse
  • touch to create file, mkdir to create dir
  • rm to delete file, rmdir to delete dir
/*
source: https://github.com/zeit/now-examples/blob/3f609858904e7dafbd016a255de325a936cf240f/nextjs-news/lib/get-stories.js
The actual functionality isn't anything special - it just gets data about news
stories for a typical hacker-news-clone demo app.
What I like is how this really short snippet shows off so many really nice
features of modern JavaScript. This is the snippet I'd show to rebut someone
claiming "JavaScript is a poorly-designed language created by Brendan Eich in
10 days".
@lionel-rowe
lionel-rowe / insaneOptions.js
Last active March 23, 2023 12:45
insane options for use with marked and highlightjs
const insaneOptions = {
allowedAttributes: {
a: ['href', 'name', 'target', 'rel', 'title'],
img: ['src', 'alt', 'title'],
input: ['type', 'checked', 'disabled'],
code: ['class'],
span: ['class'],
th: ['align'],
tr: ['align']
},
const alphabetMap = {
a: 'a@4', b: 'b8', c: 'c{\\[(', d: 'd', e: 'e3', f: 'f', g: 'g69', h: 'h',
i: 'i|', j: 'j', k: 'k', l: 'l', m: 'm', n: 'n', o: 'o0', p: 'p', q: 'q',
r: 'r', s: 's5', t: 't7', u: 'u', v: 'v', w: 'w', x: 'x', y: 'y', z: 'z2'
};
const makeRegex = str => {
const inner = str.split('').map(char => {
const chars = alphabetMap[char];
/*
Concepts covered:
concept | syntax
---------------------------------|--------------------------
testing for a match | test
replacing matches | replace
...with a string | replace(re, '...')
...with a function | replace(re, m => ...)
@lionel-rowe
lionel-rowe / QueryParams.js
Last active April 30, 2019 12:34
QueryParams - super-simple query string parser with comma-delimited arrays
const QueryParams = {};
QueryParams.options = {
usePlusSigns: false, // per RFC 1866 application/x-www-form-urlencoded; otherwise use "%20" for space
keyMustReturnArray: key => key.endsWith('_arr') // for URI-decoded keys that return `true` for this function, coerce the value to an array even if it contains no commas
};
const decode = str => {
if (QueryParams.options.usePlusSigns) {
str = str.replace(/\+/g, '%20');
@lionel-rowe
lionel-rowe / prepare-commit-msg.sh
Last active June 17, 2019 08:57 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
# curl <link_to_raw> > .git/hooks/prepare-commit-msg && chmod u+x .git/hooks/prepare-commit-msg
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
// ==UserScript==
// @name Highlightify
// @namespace https://github.com/lionel-rowe/
// @version 0.4
// @description Highlightify Stack Exchange
// @author @lionel-rowe
// @match https://meta.stackexchange.com/*
// @grant none
// ==/UserScript==
/* global StackExchange */
// https://web.archive.org/web/20160920191749/http://zhaoren.idtag.cn/samename/searchName!pmbyrepeatlist.htm
const 姓名 = [...document.querySelectorAll('li p')]
.map(x => x.textContent.trim().match(/^\d+\.(.+)$/))
.filter(Boolean)
.map(x => x[1])
const 姓 = [...new Set(姓名.map(x => x[0]))].join('')
const 名 = [...new Set(姓名.flatMap(x => [...x.slice(1)]))].join('')