Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar
🚀
Extremely busy. Open source activity paused.

Artem Zakharchenko kettanaito

🚀
Extremely busy. Open source activity paused.
View GitHub Profile
@kettanaito
kettanaito / gatsby-config.js
Created March 18, 2020 10:36
Gatsby custom field resolver
// Importing this fails, as the plugin is distributed in modern module format
// and `gatsby-config.js` is not transpiled.
const firebase = require('gatsby-plugin-firebase')
exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
Query: {
customField: {
type: 'String',
resolve() {
@kettanaito
kettanaito / usage.jsx
Last active March 16, 2020 18:29
useFetch React hook
import React from 'react'
import { useFetch } from './hooks/useFetch'
const Example = () => {
const { data, loading, error } = useFetch('https://api.github.com/user/octocat')
if (loading) {
return <Spinner />
}
@kettanaito
kettanaito / styles.scss
Created February 5, 2020 13:39
Tooltip tick via pseudo-elements
.tooltip {
position: absolute;
top: 100%;
left: 0;
width: 100%;
max-width: 350px;
padding: 0.5rem 1rem;
background-color: #fff;
border: 1px solid #000;
border-radius: 4px;
@kettanaito
kettanaito / README.md
Created February 3, 2020 11:27
Getting started with Redux

Getting started with Redux

What is Redux?

Redux is a state management library. It implements a Flux pattern of handling the data and its primary feature is the reducing of the previous state to produce the next state.

What is Flux?

Flux is an architecture pattern to handle data fetching. It splits data fetching into separate layers, making them predictable, but also embeds a "model" and "controller" parts of traditional MVC into modern applications.

@kettanaito
kettanaito / code.js
Created January 25, 2020 10:26
Boolean: De Morgan's Laws
!(A && B) // is equivalent to
!A || !B
!(A || B) // is equivalent to
!A && !B
@kettanaito
kettanaito / Canvas.jsx
Created December 22, 2019 13:48
Question code
export const VendorMachine = ({
ballRadius,
gravity,
density,
drag,
onButtonClick,
}) => {
const canvasRef = React.useRef()
const { intersection, setIntersectionRef } = useIntersection({
threshold: 0.5,
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;