Skip to content

Instantly share code, notes, and snippets.

View sqren's full-sized avatar

Søren Louv-Jansen sqren

View GitHub Profile
@sqren
sqren / cpu-intensive.js
Last active October 27, 2023 18:13
A CPU intensive operation. Use to test imitate blocking code, test WebWorkers etc.
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
@sqren
sqren / _doc_count_example.md
Last active September 21, 2023 14:53
`_doc_count` example
View _doc_count_example.md

Setup

PUT doc-count-fun

POST doc-count-fun/_doc
{
  "_doc_count": 10,
  "@timestamp": "2023-09-14T10:00:00.477Z"
}
@sqren
sqren / vurderingsportal-roadname.md
Last active September 15, 2023 21:10
Vurderingsportal: søg efter vejnavn
View vurderingsportal-roadname.md

Available fields to filter by:

  • adresseID
  • adgangsAdresseID
  • vurderingsEjendomID
  • vurderingsaar
  • juridiskKategori
  • juridiskUnderkategori
  • propertyValue
  • groundValue
@sqren
sqren / pagination-vurderingsportalen.MD
Last active September 12, 2023 20:42
Paginating vurderingsportalen.dk
View pagination-vurderingsportalen.MD

Der kan max trækkes ca. 5000 boliger via api'et af gangen. Man er derfor nødt til at bruge pagination og filtering for at få det hele med.

Pagination

Pagination, page 1: Hent de første 5000 boliger i 2300 (København S)

Vis curl command
@sqren
sqren / mac-os-mapping-keys-uk-keyboard.md
Last active August 18, 2023 06:50
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 / determine-changed-props.js
Last active July 21, 2023 02:23
Determine which props causes React components to re-render
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 => {
@sqren
sqren / useComponentId.js
Last active June 16, 2023 15:26
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 / simple-port-forwarding.js
Last active February 19, 2023 22:06
Simple Port forwarding with Node.js
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);
@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 / 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
}