Skip to content

Instantly share code, notes, and snippets.

View publicJorn's full-sized avatar

Jorn Luiten publicJorn

  • frontrain
  • Netherlands
View GitHub Profile
@publicJorn
publicJorn / jest-window-resizeTo.ts
Created March 28, 2022 10:15
Snippet to test different window sizes in jest
window.resizeTo = function resizeTo(width:number, height: number) {
Object.assign(this, {
innerWidth: width,
innerHeight: height,
outerWidth: width,
outerHeight: height,
}).dispatchEvent(new this.Event('resize'))
}
@publicJorn
publicJorn / MyComponent.test.tsx
Created November 24, 2021 10:19
jest mockImplementation for react component
// When you have a complex child component which you need to have different implemenations of
// in order to properly test your parent component
import React from 'react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import ParentComponent from './ParentComponent'
// Workaround so we can add a spy
import * as childComponent from './ChildComponent'

Automatically add issue number to git commit message

When working with issues/tickets in gitlab, -hub, Jira, etc. It's a good practise to add the issue number to the branch name and commit message.
This way you basically generate a documented history.

But adding the issue number manually to a git message is tedious. This git hook manages it for you.

prepare-commit-msg hook

Let's say your team has agreed on the branch name format: review/123_short-description

@publicJorn
publicJorn / multiple-ssh-keys-for-git.md
Last active June 17, 2022 16:41
How to setup extra ssh keys when using different

Setup multiple SSH Keys for different github accounts

For osx

Create different public key

Create different ssh key according the article: Generate new SSH key

$ ssh-keygen -t ed25519 -C "my_email@provider.com"
@publicJorn
publicJorn / singleton.dart
Last active April 25, 2020 11:17
Dart singleton explained. Try it out in https://dartpad.dev/
import 'dart:math';
class Randy {
String say;
int nr;
// Note: Randy constructs with a RANDOM number
Randy(say) {
this.say = say;
@publicJorn
publicJorn / jquery-plugin-template-es6.js
Last active June 4, 2023 21:43
jQuery plugin template ES6
/**
* jQuery plugin template by https://github.com/publicJorn
* Features:
* - ES6 (So, it requires a build step to transpile to ES5 for most environments)
* - Dynamic plugin name (only supply once) so it's easy to change later
* - Plugin factory to make it work in the browser, or with AMD / COMMONJS modules
* - Plugin instance is saved on the selector element
* - Default options are saved to the instance in case you need to figure out a difference between passed options
*/
(function(global, factory) {
@publicJorn
publicJorn / dev-breakpoints.css
Last active July 5, 2016 15:06
Shows the breakpoint in the upper left corner.
body::before {
position: fixed;
top: 0;
left: 0;
z-index: 100000;
box-sizing: border-box;
display: block;
padding: 5px;
font-size: 12px;
font-family: sans-serif;
@publicJorn
publicJorn / .editorconfig
Last active April 11, 2016 14:28
My preferred .editorconfig settings
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
max_line_length = off
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
@publicJorn
publicJorn / html-ie-tag.html
Created February 2, 2016 11:52
IE conditional comments set class on html tag
<!DOCTYPE html>
<!-- (remove me)
Also consider setting:
class `no-js` : remove (or set to `js`) with javascript
-->
<!--[if IEMobile 7 ]> <html dir="ltr" lang="nl" class="iem7"> <![endif]-->
<!--[if lt IE 7 ]> <html dir="ltr" lang="nl" class="ie6 oldie"> <![endif]-->
<!--[if IE 7 ]> <html dir="ltr" lang="nl" class="ie7 oldie"> <![endif]-->
@publicJorn
publicJorn / reactES6.jsx
Last active January 14, 2016 14:57
React component in ES6 class syntax
import React, {Component} from 'react';
export class MyComponent extends Component {
constructor (props) {
super(props);
}
render () {
return (
<p>