Skip to content

Instantly share code, notes, and snippets.

@cef62
cef62 / sed cheatsheet
Created Jan 5, 2018 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
View sed cheatsheet
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@cef62
cef62 / ag-replace.sh
Created Jul 6, 2017
Search and replace using the silver searcher and sed
View ag-replace.sh
#!/usr/bin/env zsh
# Currently the script will choke on tilde characters used in either search or
# replace terms
# inspired by
# https://gist.github.com/hlissner/db74d23fc00bed81ff62
# https://gist.github.com/kates/5915285
# ag
@cef62
cef62 / flow-type.js
Created Jun 12, 2017
Flow-type workaround for peer dependencies
View flow-type.js
#!/usr/bin/env node
const { installFlowTypeDefinitions } = require('./flow-typed')
const { echo, exit } = require('shelljs')
installFlowTypeDefinitions().then(() => exit(0)).catch(err => {
echo(err)
exit(1)
})
View babel.js
import createBabelFile from 'babel-file';
import createBabylonOptions from 'babel-options';
import {buildCodeFrameError} from 'babel-errors';
let code = `
console.log('hello world');
`;
let file = createBabelFile(code, {
filename: 'hello-world.js',
View TweetPresenter.js
// paste this to chrome console on anybody's twitter page
// and it'll turn into an instant presentation :)
(function TweetPresent() {
const presenter = $(`<div id="tpd" style=" position: fixed; top: 0; left: 0; height: 100vh; width: 100vw; padding: 10vh 10vw; box-sizing: border-box; background-color: white; font-size: 5vw; text-align: center; z-index: 9999; display: flex; align-items: center; justify-content: center;"></div>`);
const tweets = $$(`div.tweet p.js-tweet-text`)
.map(el => el.innerHTML)
.map(t => ({t, s: Math.random()}))
.sort((a, b) => a.s > b.s ? -1 : 1)
.map(c => c.t);
@cef62
cef62 / .flowconfig
Created Apr 27, 2017 — forked from MoOx/.flowconfig
flow config webpack adjustements to avoid the "Required module not found" for png, css, svg etcc
View .flowconfig
# ...
[options]
# webpack loaders
module.name_mapper='.*\.css$' -> '<PROJECT_ROOT>/flow/stub/css-modules.js'
module.name_mapper='.*\.\(svg\|png\|jpg\|gif\)$' -> '<PROJECT_ROOT>/flow/stub/url-loader.js'
@cef62
cef62 / isValidISODate.js
Last active Mar 3, 2017
Validate ISO date strings with custom separators
View isValidISODate.js
export default function isValidISODate(dateString, separator, minYear = 1980, maxYear = 2030) {
const sep = separator ? `\\${separator}` : ''
const regex = new RegExp(`^(\\d{4})${sep}{0,1}(\\d{2})${sep}{0,1}(\\d{2})$`)
const groups = dateString.match(regex)
if (!groups) {
return false
}
@cef62
cef62 / iterm2.md
Created Feb 22, 2017
iterm2 cheatsheet
View iterm2.md

Tabs and Windows

Function Shortcut
Previous Tab + Left Arrow
Next Tab + Right Arrow
Go to Tab + Number
Go to Window + Option + Number
Go to Split Pane by Direction + Option + Arrow
Go to Split Pane by Order of Use + ] , + [
@cef62
cef62 / event-emitter.js
Created Nov 21, 2016 — forked from domenic/event-emitter.js
Revealing constructor pattern event-emitter
View event-emitter.js
// This event emitter emits events, but reserves the right to publish events to
// for its creator. It uses a WeakMap for true encapsulation.
const eesToEventMaps = new WeakMap();
export default class EventEmitter {
constructor(publisher) {
const eventMap = Object.create(null);
eesToEventMaps.set(this, eventMap);
@cef62
cef62 / git-helpers.js
Created Nov 15, 2016
Run npm install after post-merge hook only when package.json changes. Javascript only.
View git-helpers.js
const { exec } = require('./helpers')
const changedFile = (filename, partial) => exec(
`git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD`,
`Something went wrong reading last git-pulled files list.`,
true
).then((stdout) => stdout.split('\n')
.some((name) => {
let match
if (partial) {