Skip to content

Instantly share code, notes, and snippets.

View marcelmokos's full-sized avatar

Marcel Mokoš marcelmokos

View GitHub Profile
@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 / jsdoc.js
Created October 16, 2019 15:12
jsdoc example
/**
* A person object with name, age and sayName method.
* @typedef {Object} Person
* @property {string} name The person's name.
* @property {number} age The person's age.
* @property {Function} sayName A function that alerts the person's name.
*/
const person = {
name: 'Joe',
age: 32,
import React from "react";
import {inject, observer} from "mobx-react";
export class SubjectsPresenter extends React.Component {...}
export default inject(
({subjectStore, translator}, {subjectSelections, ...props}) => {
const subjectOptions = subjectStore.getFilteredSubjects(subjectSelections);
return {
subjectOptions,
// see types of prompts:
// https://github.com/enquirer/enquirer/tree/master/examples
//
module.exports = [
{
type: "input",
name: "name",
message: "What's the name of your package?"
},
{
@marcelmokos
marcelmokos / index.js
Created January 18, 2019 15:36
Calendar
import React from "react";
import ReactDOM from "react-dom";
import Calendar from "./components/Calendar";
const App = () => (
<>
<Calendar>
{({ Wrapper, Column, Box, Item, headers }) => (
<Wrapper>
{headers.map((header, index) => (
@marcelmokos
marcelmokos / Calendar.defaultProps.js
Last active January 19, 2019 23:20
Calendar.defaultProps
Calendar.defaultProps = {
Wrapper: styled.div`
display: flex;
flex-direction: row;
`,
Column: styled.div`
display: flex;
flex-direction: column;
margin: 0.5rem;
`,
Original Value Converted to Number Converted to String Converted to Boolean
false 0 false false
true 1 true true
0 0 0 false
1 1 1 true
0 0 0 true
000 0 000 true
1 1 1 true
NaN NaN NaN false
Infinity Infinity Infinity true
function addDays(date = new Date(), days = 0) {
const dateClone = new Date(date); // date is an object provided by reference, we need to clone it
dateClone.setDate(date.getDate() + days);
return dateClone;
}
const tomorrowDate = (date, days = 1) => addDays(date, days);
@marcelmokos
marcelmokos / tomorrowDate.js
Last active November 8, 2018 23:34
Not testable
function tomorrowDate() {
const date = new Date();
date.setDate(date.getDate() + 1);
return date;
}
it("Test tomorrowDate function", () => {
expect(tomorrowDate()).toBe(/* ¯\_(ツ)_/¯ - it is imposible to test the function */)
@marcelmokos
marcelmokos / importing-bootstrap-scss-from-node-modules.scss
Last active October 26, 2018 13:48
In your custom.scss, you’ll import Bootstrap’s source Sass files. You have two options: include all of Bootstrap, or pick the parts you need. We encourage the latter, though be aware there are some requirements and dependencies across our components. You also will need to include some JavaScript for our plugins.
// Custom.scss
// Option B: Include parts of Bootstrap
// Required
@import "node_modules/bootstrap/scss/functions";
// Bootstrap default variables
@import "node_modules/bootstrap/scss/variables";
// Your variable overrides
@import "./variables";
@import "node_modules/bootstrap/scss/mixins";