Skip to content

Instantly share code, notes, and snippets.

View sorenlouv's full-sized avatar

Søren Louv-Jansen sorenlouv

View GitHub Profile
@sorenlouv
sorenlouv / mac-os-mapping-keys-uk-keyboard.md
Last active November 28, 2024 13:50
Map tilde sign (`) to section sign (§) on MacOS (useful for UK keyboards)
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064}]}'
@sorenlouv
sorenlouv / .gitconfig
Created April 21, 2019 23:31
Example .gitconfig file
[user]
name = John Doe
email = johndoe@gmail.com
@sorenlouv
sorenlouv / useComponentId.js
Last active June 16, 2023 15:26
React hook for getting a unique identifier for a component
import { useRef } from 'react';
let uniqueId = 0;
const getUniqueId = () => uniqueId++;
export function useComponentId() {
const idRef = useRef(getUniqueId());
return idRef.current;
}
@sorenlouv
sorenlouv / read-local-file.js
Created February 24, 2019 22:15
Bookmark to read local file
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;
@sorenlouv
sorenlouv / github-changed-files-filter.js
Last active November 23, 2018 14:33
Count lines-of-code changed on Github PR excluding certain files
/*
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'];
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' });
@sorenlouv
sorenlouv / puppeteer-random-page.js
Last active September 6, 2018 13:17
Infinitely click around page
# 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();
}
@sorenlouv
sorenlouv / package.json
Last active May 6, 2018 20:25
Browserify, Babel and React
{
"scripts": {
"browserify": "browserify --standalone myModuleName ./src/index.js | uglifyjs --compress --source-map --output dist/index.min.js"
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
@sorenlouv
sorenlouv / replace-webpack-alias-with-relative-path.js
Created April 29, 2018 17:18
Replace webpack aliases with relative paths
// 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();
}
@sorenlouv
sorenlouv / demo.js
Last active April 25, 2018 19:30
Recursively Iterate a nested structure and render strings as mustache templates
const input = {
email: {
subject: 'Happy birthday {{name}} 🎂',
body: 'Hi {{name}}, you are turning {{age}} today!'
}
};
const ctx = { name: 'Søren', age: 30 };
const tmpl = renderMustache(input, ctx);
// tmpl: {"email": {"subject": "Happy birthday Søren 🎂", "body": "Hi Søren, you are turning 30 today!"}}