Skip to content

Instantly share code, notes, and snippets.

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

Martin Holt Juliussen martinhj

🏴‍☠️
View GitHub Profile
@martinhj
martinhj / greed.md
Last active November 18, 2020 08:53
Regex greed quantifiers
Greedy quantifier Lazy quantifier Description
* *? Star Quantifier: 0 or more
+ +? Plus Quantifier: 1 or more
? ?? Optional Quantifier: 0 or 1
{n} {n}? Quantifier: exactly n
{n,} {n,}? Quantifier: n or more
{n,m} {n,m}? Quantifier: between n and m
@martinhj
martinhj / mount_disk_images.sh
Last active October 16, 2019 11:44
mount disk images: scan image for partition and set up loop independent devices for each
# Linux (when in need for read/write on ext*
losetup -Pf --show imageFilePath.img
mount /dev/loop0p1 /mnt/
# Mac
hdiutil attach -nomount imageFilePath.img
sudo diskutil mountDisk /dev/disk2
# don't need this anymore... sudo mount -t msdos /dev/disk2s1 /Volumes/somethingsomething
@martinhj
martinhj / overwrite_file_before_deletion.sh
Created October 16, 2019 11:44
safe deletion: overwrite file before deletion
dd if=/dev/zero of=filewithsecret bs=1 count=12342 conv=notrunc
# ^^^^^- filesize (ls -l filewithsecret)
# ^^^^^- notrunc: do not truncate the file if count is < filesize (do not leave secret bits and bytes hanging around on your disk....)
# Could combine this with a for loop to do it a couple of times if feeling extra
@martinhj
martinhj / github-clean-layout-for-code-print.js
Last active December 3, 2019 08:18
Clean up github code for printing (including main view for readme print)
(() => {
const flattenArray = (acc, cur) => acc = [...acc, ...cur]
const queryElement = selector => document.querySelector(selector)
const getAllChildren = elem => elem.children
const removeElem = elem => elem && elem.parentElement.removeChild(elem);
const removeClassFromElem = (elem, styleclass) => elem && elem.classList.remove(styleclass);
const removeClassesFromElem = ([elem, styleclasses]) => styleclasses.forEach(styleclass => removeClassFromElem(elem, styleclass));
const findAllChildrensExcept = (elemToRemoveExcept) => elemToRemoveExcept
.map(([elem, keepChildrenQueries]) => [queryElement(elem), keepChildrenQueries.map(queryElement)])
@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';
@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 / 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 / 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 / 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 / desktop sizes
Created June 7, 2022 09:14
Safari default desktop Responsive Design Mode sizes
Desktop safari:
800x600
1366x768
1920x1080