Skip to content

Instantly share code, notes, and snippets.

View Siemko's full-sized avatar

Dominik Guzy Siemko

View GitHub Profile
@Siemko
Siemko / docker-compose.yml
Created July 7, 2020 07:17
Development docker compose environment
version: "3.8"
services:
webapp:
image: node:lts-alpine # always using the same image - no building, less space taken
working_dir: /usr/app/webapp
volumes:
- "./webapp/package.json:/usr/app/webapp/package.json"
- "./webapp/yarn.lock:/usr/app/webapp/yarn.lock"
- "./webapp/tsconfig.json:/usr/app/webapp/tsconfig.json"
@Siemko
Siemko / snip.code-snippets
Created June 3, 2020 19:19
"Print to console"
{
"Print to console": {
"scope": "javascript,typescript",
"prefix": "log",
"body": ["console.log('$1');"],
"description": "Log output to console"
}
}
import { useState, useCallback } from 'react'
import produce from 'immer'
const useImmerState = initialState => {
const [state, setState] = useState(initialState)
const setImmerState = useCallback(setter => setState(produce(setter)), [])
return [state, setImmerState]
}
import React from "react";
import useWindowSize from "./useWindowSize";
const WindowSize = () => {
const { width, height } = useWindowSize();
return (
<>
<h2>Window size: {width} x {height}</h2>
</>
);
import { useState, useEffect } from "react";
export default function useWindowSize() {
const [{width, height}, setSize] = useState({ window.innerWidth, window.innerHeight });
useEffect(() => {
const handleResize = () => setSize({ window.innerWidth, window.innerHeight });
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
import React, { useState, useEffect } from "react";
const WindowSize = () => {
const [{width, height}, setSize] = useState({ window.innerWidth, window.innerHeight });
useEffect(() => {
const handleResize = () => setSize({ window.innerWidth, window.innerHeight });
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
@Siemko
Siemko / class-component.js
Created November 7, 2019 15:05
Class component
import React, { Component } from "react";
class WindowSize extends Component {
state = {
width: window.innerWidth,
height: window.innerHeight
};
handleResize = () => this.setState({
width: window.innerWidth,
@Siemko
Siemko / api.js
Last active June 23, 2019 11:17
[async fetch api request] #js #javascript #http
export const request = async (url, method = 'GET', type = 'json', body = null) => {
const requestOptions = {
method: method,
headers: { 'Content-Type': 'application/json' },
};
if (body) {
requestOptions.body = JSON.stringify(body);
}
if (type === 'json') {
return await (await fetch(url, requestOptions)).json();
@Siemko
Siemko / Counter.vue
Created February 3, 2018 15:54
Counter component in Vue.js
<template>
<section class="section">
<div class="container">
<h2 class="title">{{title}}</h2>
<div class="level">
<div class="level-item">
<button class="button" @click="incrementCounter">
<span class="icon">
<i class="fa fa-plus"></i>
@Siemko
Siemko / FormSample.js
Created January 28, 2018 20:48
FormSample React.js component
import React, { Component } from "react";
export default class FormSample extends Component {
state = {
employer: "Gorrion"
};
handleEmployerChange = e => {
this.setState({ employer: e.target.value });
};