hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064}]}'
View jest-run-timers-until-resolved.ts
/* | |
* Run timers (setInterval/setTimeout) every tick continuously until the promise has been resolved | |
*/ | |
async function runTimersUntilResolved(fn: () => Promise<any>) { | |
jest.useFakeTimers(); | |
let isResolved = false; | |
const p = fn(); | |
p.finally(() => (isResolved = true)); |
View mac-os-mapping-keys-uk-keyboard.md
View .gitconfig
[user] | |
name = John Doe | |
email = johndoe@gmail.com |
View useComponentId.js
import { useRef } from 'react'; | |
let uniqueId = 0; | |
const getUniqueId = () => uniqueId++; | |
export function useComponentId() { | |
const idRef = useRef(getUniqueId()); | |
return idRef.current; | |
} |
View read-local-file.js
copy( | |
encodeURIComponent(`(function() { | |
function readLocalFile(e) { | |
const file = e.target.files[0]; | |
if (!file) { | |
alert('No file selected!') | |
} | |
const reader = new FileReader(); | |
reader.onload = function(e) { | |
const contents = e.target.result; |
View github-changed-files-filter.js
/* | |
The number of changed files (additions/deletions) includes all files. | |
I wanted to see how many files I had changed, excluding tests and test snapshots. | |
This filter will help you do that. | |
To use it, go to the PR, navigate to "Files" and invoke the following | |
*/ | |
(function() { | |
const excludeWords = ['test', 'mock-responses', 'typings']; |
View gist:83f9e5b8f40c5fa0bc4dd4cafe6c0f2b
const hypercore = require('hypercore'); | |
const discovery = require('discovery-swarm'); | |
const multifeed = require('multifeed'); | |
const pump = require('pump'); | |
const suffix = process.argv[2]; | |
const db = `./multichat-${suffix}`; | |
console.log(`Using db: ${db}`); | |
const multi = multifeed(hypercore, db, { valueEncoding: 'json' }); |
View puppeteer-random-page.js
# yarn add puppeteer | |
# node ./puppeteer-random-page.js | |
const puppeteer = require('puppeteer'); | |
const initialUrl = process.env.url || 'http://localhost:8080'; | |
async function init() { | |
const browser = await puppeteer.launch({ headless: true }); | |
return browser.newPage(); | |
} |
View package.json
{ | |
"scripts": { | |
"browserify": "browserify --standalone myModuleName ./src/index.js | uglifyjs --compress --source-map --output dist/index.min.js" | |
}, | |
"browserify": { | |
"transform": [ | |
[ | |
"babelify", | |
{ | |
"presets": [ |
View replace-webpack-alias-with-relative-path.js
// Usage: jscodeshift -t replace-webpack-alias-with-relative-path.js ./kibana/x-pack/plugins ./kibana/src | |
const path = require('path'); | |
const URI = require('urijs'); | |
function getRelativePath(currentFilePath, dependencyPath) { | |
return URI(dependencyPath) | |
.relativeTo(currentFilePath) | |
.toString(); | |
} |
NewerOlder