Skip to content

Instantly share code, notes, and snippets.

Søren Louv-Jansen sqren

Block or report user

Report or block sqren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
sqren / gist:c948678c090fb6906208545d6a36196d
Last active Dec 17, 2019
Map tilde sign (`) to section sign (§) on MacOS
View gist:c948678c090fb6906208545d6a36196d
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064}]}'
sqren / .gitconfig
Created Apr 21, 2019
Example .gitconfig file
View .gitconfig
name = John Doe
email =
sqren / useComponentId.js
Last active Feb 22, 2020
React hook for getting a unique identifier for a component
View useComponentId.js
import { useRef } from 'react';
let uniqueId = 0;
const getUniqueId = () => uniqueId++;
export function useComponentId() {
const idRef = useRef(getUniqueId());
return idRef.current;
sqren / read-local-file.js
Created Feb 24, 2019
Bookmark to read local file
View read-local-file.js
encodeURIComponent(`(function() {
function readLocalFile(e) {
const file =[0];
if (!file) {
alert('No file selected!')
const reader = new FileReader();
reader.onload = function(e) {
const contents =;
sqren / github-changed-files-filter.js
Last active Nov 23, 2018
Count lines-of-code changed on Github PR excluding certain files
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' });
sqren / puppeteer-random-page.js
Last active Sep 6, 2018
Infinitely click around page
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();
sqren / package.json
Last active May 6, 2018
Browserify, Babel and React
View package.json
"scripts": {
"browserify": "browserify --standalone myModuleName ./src/index.js | uglifyjs --compress --source-map --output dist/index.min.js"
"browserify": {
"transform": [
"presets": [
sqren / replace-webpack-alias-with-relative-path.js
Created Apr 29, 2018
Replace webpack aliases with relative paths
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)
sqren / demo.js
Last active Apr 25, 2018
Recursively Iterate a nested structure and render strings as mustache templates
View demo.js
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!"}}
You can’t perform that action at this time.