Skip to content

Instantly share code, notes, and snippets.

View nebomilic's full-sized avatar
👋

Nebo Milic nebomilic

👋
View GitHub Profile
@nebomilic
nebomilic / styleguide.config.js
Last active July 1, 2023 22:50
Styleguidist configuration for Create React App 5 + Typescript + Tailwind CSS
const webpack = require('webpack');
const path = require('path');
// Styleguidist (v11.2.0) doesn't display components with create ract app 5
// This webpackConfig is a workaround for that
// For more information see https://github.com/styleguidist/react-styleguidist/issues/1910#issuecomment-1013763698
const webpackConfig = {
module: {
rules: [
@nebomilic
nebomilic / patternMatching.js
Created December 31, 2019 10:51
Pattern matching pattern in javascript
// pattern matching is a nice mechanism supported by most functional languages (eg see scala examples: https://docs.scala-lang.org/tour/pattern-matching.html)
// here are some ways to use javascript switch and if statement for pattern matching
// we are using IIFE pattern to immediately invoke switch (or if) statement
const value1 = 1;
// version using switch case
const value2 = (_ => {
switch (true) {
case value1 === 1: return 'first case';
case value1 === 2: return 'second case';
@nebomilic
nebomilic / listFilesInDirectory.ts
Last active December 7, 2023 14:38
Async reading directory content with fs.readdir in Typescript
import fs from 'fs'
export const listFilesInDirectory = async (path: string) =>
new Promise((resolve, reject) =>
fs.readdir(path, (err, content) =>
err ? reject(err) : resolve(content)
)
)