Skip to content

Instantly share code, notes, and snippets.

View luke-rmaki's full-sized avatar
🏠
Working from home

Luke luke-rmaki

🏠
Working from home
View GitHub Profile
@luke-rmaki
luke-rmaki / Nav.ts
Created July 10, 2021 08:23
FSM React Nav
// STATE MACHINE
const states = {
MOBILE_DISPLAY: `MOBILE_DISPLAY`,
BUTTON_HIDDEN: `BUTTON_HIDDEN`,
BUTTON_DISPLAY: `BUTTON_DISPLAY`,
DESKTOP_DISPLAY: `DESKTOP_DISPLAY`,
DESKTOP_HIDDEN: `DEKSTOP_HIDDEN`,
};
const events = {
@luke-rmaki
luke-rmaki / index.js
Created February 14, 2021 22:11
Don't run useEffect on initial render
import React, {useEffect, useRef} from 'react';
const Component = () => {
const isFirstRender = useRef(true);
useEffect(() => {
if (isFirstRender.current) {
// this is the first render
isFirstRender.current = false;
return;
@luke-rmaki
luke-rmaki / .vimrc
Last active August 19, 2021 06:46
Dot Files
" -------------------------------------------------------BASIC SETUP
set nocompatible " be iMproved, required
filetype off " required
syntax on
"--------------------------------------------------------VUNDLE
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
@luke-rmaki
luke-rmaki / easing.js
Created January 2, 2020 09:49 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
@luke-rmaki
luke-rmaki / useGlobalState.js
Created June 8, 2019 06:41
React Hooks and Context State Management
import { useState } from 'react';
const store = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [state, setState] = useState('test state');
const actions = action => {
const { type, payload } = action;
switch (type) {
case 'setState':
setState(payload);
@luke-rmaki
luke-rmaki / script.js
Last active October 5, 2018 10:17
Function to see if element is in viewport
function elementInView(target) {
// selects target div
const targetDiv = document.querySelector(target);
// gets target position from top of viewport
const targetPosition = targetDiv.getBoundingClientRect();
switch (true) {
case targetPosition.top > 1:
console.log('hidden');
@luke-rmaki
luke-rmaki / index.html
Created October 3, 2018 23:56
Vanilla JavaScript Smooth Scroll
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Smooth Scroll</title>
<link rel="stylesheet" href="style.css">
</head>
<body>