Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar

Artem Zakharchenko kettanaito

View GitHub Profile
const express = require('express');
const app = express();
// Application
app.get('/', function(req, res) {
if (process.env.NODE_ENV === 'development') {
for (var key in require.cache) {
delete require.cache[key];
}
}
@kettanaito
kettanaito / ElementQueryAPI.jsx
Last active October 19, 2019 00:27
Atomic Layout - Element Queries API
import React from 'react'
import { Box, useElementQuery } from 'atomic-layout'
// Initially, I thought of EQ as a standalone query-value binding
// with the React component being an application surface.
// The problem with this is that the props assignment becomes abstracted,
// and it's not easy to scan which props are assigned to a component,
// and which comes from the EQ declared eslewhere.
const InitialIdea = () => {
const styles = useElementQuery(
@kettanaito
kettanaito / throttle.js
Last active July 22, 2024 11:49
Debounce vs Throttle: Throttle
function throttle(func, timeout) {
let wait = false;
return function (...args) {
if (!wait) {
func(...args)
wait = true;
setTimeout(function () {
wait = false;
@kettanaito
kettanaito / windowResizeExample.js
Last active September 28, 2019 08:20
Throttle/Debounce Article
// Adding this event listener prints the message
// into browser's console whenever the window
// is resized (emits the "resize" event).
//
// Note that the "resize" event occurs for each
// pixel that the browser being resized.
window.addEventListener('resize', function () {
console.log('Resize happened!')
})
@kettanaito
kettanaito / debounce.js
Last active December 19, 2019 15:01
Debounce
function debounce(func, duration) {
let timeout
return (...args) => {
const effect = () => {
timeout = null
return func(...args)
}
clearTimeout(timeout)
@kettanaito
kettanaito / changelog.md
Created September 22, 2019 12:13
Unified Change Log Format

1.0.0

@kettanaito
kettanaito / perspective-tilt.css
Created September 21, 2019 13:23
Tilt (translate) an element in perspective
body {
-webkit-perspective: 1000px;
}
#style-text {
-webkit-transform: translateX(98.5%) rotateY(-10deg);
-webkit-transform-origin: right;
max-height: 94.5%;
}
@kettanaito
kettanaito / myFunc.test.ts
Created September 4, 2019 18:35
Thinking in Functions — The Input/Output pattern
expect(myFunc(['a', 'b']).toEqual(2)
@kettanaito
kettanaito / functionalChain.ts
Created September 4, 2019 18:04
Thinking in Functions — The Input/Output pattern
const getUser = (id: string) => User
const getPosts = (user: User) => Post[]
const getTotalLikes = (posts: Post[]) => number
// getUser -> getPosts -> getTotalLikes
@kettanaito
kettanaito / myFunc.ts
Created September 4, 2019 17:42
Thinking in Functions – The Input/Output pattern
function myFunc(list: number[]): string {}