Skip to content

Instantly share code, notes, and snippets.

View martinhj's full-sized avatar
🏴‍☠️

Martin Holt Juliussen martinhj

🏴‍☠️
View GitHub Profile
@martinhj
martinhj / prettify.ts
Created November 21, 2023 10:05
Matt Pocock's `Prettify` TypeScript helper type
/**
* A TypeScript type alias called `Prettify`.
* It takes a type as its argument and returns a new type that has the same properties as the original type,
* but the properties are not intersected. This means that the new type is easier to read and understand.
*/
export type Prettify<T> = {
[K in keyof T]: T[K]
} & {}
@martinhj
martinhj / convertParsedUrlQueryToUrlSearchParams.ts
Created November 21, 2023 10:03
Convert NodeJS' ParseUrlQuery to browser API URLSearchParams
import type { ParsedUrl } from 'next/dist/shared/lib/router/utils/parse-url'
export function convertUrlQueryToUrlSearchParams(
queryArgs: ParsedUrl['query'],
) {
const searchparams = new URLSearchParams()
Object.entries(queryArgs)
.filter(([key, value]) => Boolean(value))
.forEach(
@martinhj
martinhj / curl.sh
Last active October 13, 2022 08:55
Curl flags
curl -I https://website/webpage # show http headers
curl -L https://website/webpage # follow redirects
@martinhj
martinhj / DOCUMENTATION.md
Last active June 14, 2022 07:17
Cosmo related documentation

🐾 Cosmo tooling documentation

Sanity / Next.js / Vercel resources (our stack)

Nextjs:

Nextjs is a framework for building web sites in JS React getting data from any API.

@martinhj
martinhj / desktop sizes
Created June 7, 2022 09:14
Safari default desktop Responsive Design Mode sizes
Desktop safari:
800x600
1366x768
1920x1080
@martinhj
martinhj / heroku-commands.sh
Created March 5, 2021 13:53
Heroku cheat sheet
# Logs
heroku help logs
heroku logs --app=app-name # also for apps in teams (without defining team)
heroku logs --app=pwp-integrated-decameron --num=500 --tail # get 500 last lines and subscribe to future
# Plugins
heroku plugins:install heroku-plugin
heroku plugins:install heroku-builds
heroku help builds
@martinhj
martinhj / git-history.sh
Created November 18, 2020 08:39
Search git history for string
# search git commits for specific string
git log -S thestring
# search stashes for specific string
git stash list -S thestring
@martinhj
martinhj / reactredux-useDispatch-mock.test.js
Last active September 19, 2023 15:33
Mock implementation of useDispatch with possibility of dynamic response
import * as ReactRedux from 'react-redux';
describe('nothing', () => {
let loginFn = jest.fn(() => null);
jest.spyOn(ReactRedux, 'useDispatch').mockImplementation(() => {
return loginFn;
});
})
@martinhj
martinhj / adventofcode01-1.re
Last active December 7, 2019 17:23
AdventOfCode 2019 reasonml
[%raw "require('isomorphic-fetch')"]
let fetchUrl = "https://adventofcode.com/2019/day/1/input"
let calculateFuel = mass =>
mass / 3 - 2
let add = (i, j) => i + j;
let parseResponse = text =>
@martinhj
martinhj / Button.test.js
Created November 29, 2019 12:35
Jest / @testing-library/react-native test examples
import React from 'react';
import Button from '.';
import { AlertButton, SubmitButton } from '.';
import { fireEvent, render, wait } from '@testing-library/react-native';
import Icon from '../Icon';
const caption = 'Test button';
const color = '#f00f0f';
const accessibilityLabel = 'This is a test button';