Skip to content

Instantly share code, notes, and snippets.

Avatar

Søren Louv-Jansen sqren

View GitHub Profile
@sqren
sqren / CommitsByAuthor.gql
Created August 26, 2022 08:22
Example of a graphql query
View CommitsByAuthor.gql
query CommitsByAuthor($authorId: ID, $commitPath: String, $dateSince: GitTimestamp, $dateUntil: GitTimestamp, $maxNumber: Int!, $repoName: String!, $repoOwner: String!, $sourceBranch: String!) {
repository(owner: $repoOwner, name: $repoName) {
ref(qualifiedName: $sourceBranch) {
target {
... on Commit {
history(first: $maxNumber, author: {id: $authorId}, path: $commitPath, since: $dateSince, until: $dateUntil) {
edges {
node {
...SourceCommitWithTargetPullRequestFragment
}
@sqren
sqren / cypress-tips.md
Last active September 1, 2022 18:40
Cypress tips and tricks
View cypress-tips.md

Don't await Cypress methods

Given this backend task:

// plugins.ts
const plugin: Cypress.PluginConfig = (on, config) => {
  on('task', {
    async waitForMe(ms: number) {
 return new Promise((resolve) => {
@sqren
sqren / macos-fix.md
Last active May 25, 2021 08:21
"UNTRUSTED_CERT_TITLE" while updating MacOS
View macos-fix.md

Fix the date

Automatic fix

Open the terminal and set the correct date:

ntpdate -u time.apple.com
@sqren
sqren / jest-run-timers-until-resolved.ts
Last active April 1, 2020 08:10
Simplifies testing promise-returning-functions that executes timers (setTimeout / setInterval). The helper `runTimersUntilResolved` will run the timers repeatedly until the promise resolves. Jest helper.
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));
@sqren
sqren / mac-os-mapping-keys-uk-keyboard.md
Last active January 7, 2023 17:10
Map tilde sign (`) to section sign (§) on MacOS (useful for UK keyboards)
View mac-os-mapping-keys-uk-keyboard.md
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064}]}'
@sqren
sqren / .gitconfig
Created April 21, 2019 23:31
Example .gitconfig file
View .gitconfig
[user]
name = John Doe
email = johndoe@gmail.com
@sqren
sqren / useComponentId.js
Last active August 5, 2022 23:12
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
sqren / read-local-file.js
Created February 24, 2019 22:15
Bookmark to read local file
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;
@sqren
sqren / github-changed-files-filter.js
Last active November 23, 2018 14:33
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' });