Skip to content

Instantly share code, notes, and snippets.

View tjunghans's full-sized avatar
💭
Open for business

Thomas Junghans tjunghans

💭
Open for business
View GitHub Profile
@sibelius
sibelius / mock-uuid.ts
Created August 30, 2021 16:06
mock uuid v4 unique and stable for tests
jest.mock('uuid', () => {
const base = '9134e286-6f71-427a-bf00-';
let current = 100000000000;
return {
v4: () => {
const uuid = base + current.toString();
current++;
return uuid;
@sindresorhus
sindresorhus / esm-package.md
Last active November 15, 2024 15:20
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@JannisRex
JannisRex / ErrorBoundary.test.native.js
Created April 1, 2020 07:05
Jest Test for <ErrorBoundary />
import React from 'react'
import { Text, View } from 'react-native'
import renderer from 'react-test-renderer'
import { ErrorBoundary } from '../../src/components/index'
describe('ErrorBoundary', () => {
let consoleErrorSpy
let errorMock
let workingComponent
@btoo
btoo / usePrevious.ts
Last active September 11, 2022 15:30
typescript type-safe version of usePrevious taken directly from the react docs https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
import { useRef, useEffect } from 'react';
/**
* a type-safe version of the `usePrevious` hook described here:
* @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state}
*/
export function usePrevious<T>(
value: T,
): ReturnType<typeof useRef<T>>['current'] {
const ref = useRef<T>();
@lkrych
lkrych / stubbing_fetch_api.js
Created November 6, 2017 16:16
Stubbing the fetch API with sinon
////Constants //////////////////////////////////////////////
function jsonOk (body) {
var mockResponse = new window.Response(JSON.stringify(body), { //the fetch API returns a resolved window Response object
status: 200,
headers: {
'Content-type': 'application/json'
}
});
@valotas
valotas / index.html
Last active May 15, 2017 12:00
Promise.inSequence
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.min.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine-html.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/boot.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Promise.inSequence</title>
@staltz
staltz / adnetworks.txt
Created November 20, 2016 10:34
Ban these domains of ad networks
101com.com, 101order.com, 123found.com, 180hits.de, 180searchassistant.com, 1x1rank.com, 207.net, 247media.com, 24log.com, 24log.de, 24pm-affiliation.com, 2mdn.net, 2o7.net, 360yield.com, 4affiliate.net, 4d5.net, 50websads.com, 518ad.com, 51yes.com, 600z.com, 777partner.com, 77tracking.com, 7bpeople.com, 7search.com, 99count.com, a-ads.com, a-counter.kiev.ua, a.0day.kiev.ua, a.aproductmsg.com, a.collective-media.net, a.consumer.net, a.mktw.net, a.sakh.com, a.ucoz.net, a.ucoz.ru, a.xanga.com, a32.g.a.yimg.com, aaddzz.com, abacho.net, abc-ads.com, absoluteclickscom.com, abz.com, ac.rnm.ca, accounts.pkr.com.invalid, acsseo.com, actionsplash.com, actualdeals.com, acuityads.com, ad-balancer.at, ad-balancer.net, ad-center.com, ad-images.suntimes.com, ad-pay.de, ad-rotator.com, ad-server.gulasidorna.se, ad-serverparc.nl, ad-souk.com, ad-space.net, ad-tech.com, ad-up.com, ad.100.tbn.ru, ad.71i.de, ad.980x.com, ad.a8.net, ad.abcnews.com, ad.abctv.com, ad.about.com, ad.aboutit.de, ad.aboutwebservices.com, ad.abum.com,
@amirbehzad
amirbehzad / phpunit_pdo_mock.php
Created January 21, 2016 04:18
How to mock PDO for test-cases written in PHPUnit
<?php
// ...
protected function getMockedPDO()
{
$query = $this->getMock('\PDOStatement');
$query->method('execute')->willReturn(true);
$db = $this->getMockBuilder('\PDO')
->disableOriginalConstructor()
@staltz
staltz / introrx.md
Last active November 14, 2024 11:27
The introduction to Reactive Programming you've been missing
@thomd
thomd / LC_COLORS.md
Last active October 13, 2024 07:12
LSCOLORS & LS_COLORS

alternatively use: http://geoff.greer.fm/lscolors/

LSCOLORS

The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.

The color designators are as follows:

a black