Skip to content

Instantly share code, notes, and snippets.

View marcelmokos's full-sized avatar

Marcel Mokoš marcelmokos

View GitHub Profile
#!/bin/bash
# bash script that can setup environment with common linting and testing tools
yes="${@}"
function yes_or_no {
if [[ $yes == "-y" ]]; then
echo "🛑👍🛑 !!! skipping question !!! 🛑👍🛑"
else
import { getChangesOnList } from './getChangesOnList';
describe('getChangesOnList', () => {
type TestItem = { id: number; value: string };
const testItemA: TestItem = { id: 1, value: 'A' };
const testItemB: TestItem = { id: 2, value: 'B' };
const testItemC: TestItem = { id: 3, value: 'C' };
const testItems: TestItem[] = [testItemA, testItemB, testItemC];
import { getChangesOnList } from './getChangesOnList';
describe('getChangesOnList', () => {
it('should return the correct changes', () => {
const prev = [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
];
const curr = [
{ id: 1, name: 'foo' },
import { getChangesOnList } from './getChangesOnList';
describe('getChangesOnList', () => {
const prevList = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Mary' },
{ id: 3, name: 'Bob' },
];
const currList = [
{ id: 1, name: 'John' },
@marcelmokos
marcelmokos / getChangesOnList.ts
Created March 10, 2023 00:18
/** * Computes the changes between two lists of items. * @param prev The previous list of items. * @param curr The current list of items. * @param isEqual The comparison function to use to determine if two items are deep equal. * @returns An object containing three properties: * - add: the items that were added to the current list. * - update: t…
import isEqualFn from 'lodash/fp/isEqual';
type Item = { id: string | number };
/**
* Computes the changes between two lists of items.
* @param prev The previous list of items.
* @param curr The current list of items.
* @param isEqual The comparison function to use to determine if two items are deep equal.
* @returns An object containing three properties:
@marcelmokos
marcelmokos / typescript-basic-types-table.csv
Last active March 22, 2022 13:40
Typescript Basic Types table
Javascript type constructor example values typescript type example usage alternative syntax
Boolean Boolean(1); true, false boolean const isOpen: boolean = true;
Number Number('1'); 1, 2 number const n: number = 1;
String String('');, '',", `` 'ok' string const str: string = 'ok';
Array new Array(); []; [1, 2, 3]; number[]; Array<number>; const list: number[] = [1, 2, 3]; const list: Array<number> = [1, 2, 3];
Null null null null const n: null = null;
Undefined undefined undefined undefined const u: undefined = undefined;
Object new Object(); {key: 'value'}; object const item: object = {key: 'value'}; const item: {[key: string]: string} = {key: 'value'};
['Hello', true]; Touple const hi: [string, boolean] = ['Hello', true]
enum enum Color {Red, Green, Blue}
@marcelmokos
marcelmokos / axiosInstance.ts
Created December 7, 2021 14:57
Axios instance
import axios from "axios";
import {history} from "../helpers/history";
import {
makeAuthorizationHeader,
isTokenValid,
getToken,
setToken,
tokenIsExpired,
} from "../helpers/token";
const article = {
"id": "a2f693f1-e63c-4190-81b3-7a0b459a2517",
"author": {
"id": "6e9418c3-8658-466f-81d6-58ac5548d3dd",
"displayName": "Gene Price",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/iamsteffen/128.jpg",
"color": "#486071",
"url": "author/Gene-Price_6e9418c3-8658-466f-81d6-58ac5548d3dd"
},
"title": "at odit nulla",
@marcelmokos
marcelmokos / propTypes-isRequired.js
Created October 16, 2019 21:08
propTypes isRequired
Component.propTypes = {
requiredArray: PropTypes.array.isRequired,
requiredBool: PropTypes.bool.isRequired,
requiredFunc: PropTypes.func.isRequired,
requiredNumber: PropTypes.number.isRequired,
requiredObject: PropTypes.object.isRequired,
requiredString: PropTypes.string.isRequired,
requiredSymbol: PropTypes.symbol.isRequired,
// ...
};
@marcelmokos
marcelmokos / propTypes.js
Created October 16, 2019 21:06
propTypes
Component.propTypes = {
optionalArray: PropTypes.array,
optionalBool: PropTypes.bool,
optionalFunc: PropTypes.func,
optionalNumber: PropTypes.number,
optionalObject: PropTypes.object,
optionalString: PropTypes.string,
optionalSymbol: PropTypes.symbol,
// ...
};