hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064}]}'
View useComponentId.js
import { useRef } from 'react'; | |
let uniqueId = 0; | |
const getUniqueId = () => uniqueId++; | |
export function useComponentId() { | |
const idRef = useRef(getUniqueId()); | |
return idRef.current; | |
} |
View cpu-intensive.js
function mySlowFunction(baseNumber) { | |
console.time('mySlowFunction'); | |
let result = 0; | |
for (var i = Math.pow(baseNumber, 7); i >= 0; i--) { | |
result += Math.atan(i) * Math.tan(i); | |
}; | |
console.timeEnd('mySlowFunction'); | |
} | |
mySlowFunction(8); // higher number => more iterations => slower |
View determine-changed-props.js
import React, { Component } from 'react'; | |
export default function withPropsChecker(WrappedComponent) { | |
return class PropsChecker extends Component { | |
componentWillReceiveProps(nextProps) { | |
Object.keys(nextProps) | |
.filter(key => { | |
return nextProps[key] !== this.props[key]; | |
}) | |
.map(key => { |
View signed_request.js
var request = require('request-promise'); | |
var crypto = require('crypto'); | |
var config = {...}; | |
function getAccessToken(cookies) { | |
var cookieName = 'fbsr_' + config.client_id; | |
var signedRequest = cookies[cookieName]; | |
var code = getCode(signedRequest); | |
return exchangeCodeForAccessToken(code); | |
}; |
View mac-os-mapping-keys-uk-keyboard.md
View batch-promise.js
var Q = require('q'); | |
function batchPromises(items, fn, options) { | |
var results = []; | |
var index = (options.batchSize - 1); | |
function getNextItem() { | |
index++; | |
if (items.length > index) { | |
var nextItem = items[index]; |
View simple-port-forwarding.js
// npm install http-proxy | |
var httpProxy = require('http-proxy'); | |
var targetHost = '192.168.99.100'; | |
var port = 8489; | |
httpProxy.createProxyServer({target:'http://' + targetHost + ':' + port}).listen(port); |
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(); | |
} |
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)); |
NewerOlder