Skip to content

Instantly share code, notes, and snippets.

View joshuacerbito's full-sized avatar
🔥
🎸🎛🎛🎚🔊

Joshua Cerbito joshuacerbito

🔥
🎸🎛🎛🎚🔊
View GitHub Profile
@joshuacerbito
joshuacerbito / setAttributes.js
Created July 25, 2019 05:13
Sets multiple html element attributes at once
/**
* setAttributes
* Sets multiple html element attributes at once
*
* @param elm html element that the at attributes will be applied to
* @param attrs object with key (attribute name) and value (attribute value)
*
* e.g.
* setAttributes(document.querySelector('.sample'), {
* 'title': 'Sample Title',
@joshuacerbito
joshuacerbito / LocalValetDriver.php
Created May 16, 2019 08:45
Local Valet Driver for Themosis
<?php
class LocalValetDriver extends BasicValetDriver
{
/**
* Mutate the incoming URI.
*
* @param string $uri
* @return string
*/
@joshuacerbito
joshuacerbito / useScroll.js
Last active January 8, 2024 13:44
Custom React hook for listening to scroll events
/**
* useScroll React custom hook
* Usage:
* const { scrollX, scrollY, scrollDirection } = useScroll();
*/
import { useState, useEffect } from "react";
export function useScroll() {
const [lastScrollTop, setLastScrollTop] = useState(0);
@joshuacerbito
joshuacerbito / useWindowDimension.js
Last active February 11, 2019 04:45
Custom React hook for reading the window's dimension
/**
* useWindowDimension React custom hook
* Usage:
* const { width, height } = useWindowDimension();
*/
import { useState, useEffect } from "react";
export function useWindowDimension() {
const [width, setWidth] = useState(window.innerWidth);
@joshuacerbito
joshuacerbito / useLocalStorage.js
Last active April 16, 2020 20:26
Custom React Hook for handling local storage
import { useState } from 'react';
export default function useLocalStorage(key, initialValue) {
const [item, setInnerValue] = useState(() => {
try {
return window.localStorage.getItem(key)
? JSON.parse(window.localStorage.getItem(key))
: initialValue;
} catch (error) {
return initialValue;
@joshuacerbito
joshuacerbito / _base.scss
Created January 19, 2019 16:41
Web Typography Scale
/*
* Based off of the blog post "A More Modern Scale for Web Typography"
* - http://typecast.com/blog/a-more-modern-scale-for-web-typography
*/
html {
font-size: 16px;
}
body {
@joshuacerbito
joshuacerbito / debounce2019.js
Last active January 7, 2019 06:32
Debounce + Throttle
export function debounce (fn, time) {
let timeout;
return function() {
const functionCall = () => fn.apply(this, arguments);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
}
}
@joshuacerbito
joshuacerbito / animateCount.js
Last active December 17, 2018 04:16
Little script to animate numeric values
/**
* animateCount
*
* Usage:
* animateCount({
* selector: '.your-selector', // the selector for the element to animate
* from: 0, // the value to animate from
* to: 50, // the value to animate to
* duration: 1000 // animation duration in miliseconds, defaults to 1000
* })
@joshuacerbito
joshuacerbito / system_default.css
Created December 5, 2018 09:37
System Default font declaration
element {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
@joshuacerbito
joshuacerbito / animateScrollTo.js
Last active November 28, 2018 09:22
Scroll Animator using requestAnimationFrame
// Add requestAnimationFrame shim
// http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
window._animate = (function() {
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
}