Skip to content

Instantly share code, notes, and snippets.

View johnnybenson's full-sized avatar
👽
let's go

j-hnny johnnybenson

👽
let's go
View GitHub Profile
@johnnybenson
johnnybenson / interval.hook.ts
Created August 20, 2021 14:12 — forked from Danziger/interval.hook.ts
✨ Declarative useTimeout (setTimeout), useInterval (setInterval) and useThrottledCallback (useCallback combined with setTimeout) hooks for React (in Typescript)
import React, { useEffect, useRef } from 'react';
/**
* Use setInterval with Hooks in a declarative way.
*
* @see https://stackoverflow.com/a/59274004/3723993
* @see https://overreacted.io/making-setinterval-declarative-with-react-hooks/
*/
export function useInterval(
callback: React.EffectCallback,
@johnnybenson
johnnybenson / gist:373bc8ae43aee9a5b187c55c68d35631
Created June 4, 2019 15:39 — forked from spudbean/gist:1558257
Look of disapproval and other emoticons
ಠ_ಠ
( ͡° ͜ʖ ͡°)
¯\_(ツ)_/¯
(╯°□°)╯︵ ┻━┻
http://www.fileformat.info/convert/text/upside-down.htm
WRTTN http://wrttn.me/30dbfd/
Unicode Emoticons
// Create a function that checks if a given string is a palindrome.
// A palindrome is text that reads the same forwards and backwards, disregarding puncation, spaces, etc.
const testStrings = [
"b",
"aba",
"abc", // FALSE
"abba",
"Race Car",
"Mr. Owl ate my metal worm",
@johnnybenson
johnnybenson / what-forces-layout.md
Created September 12, 2017 15:19 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@johnnybenson
johnnybenson / ascii.php
Created September 5, 2016 18:38 — forked from donatj/ascii.php
Damn Simple PHP Ascii Art Generator
#!/usr/bin/php -q
<?php
if(isset($argv[1]) && strlen($argv[1])) {
$file = $argv[1];
}else{
echo 'Please Specify a File';
exit(1);
}
@johnnybenson
johnnybenson / uri.js
Created September 7, 2012 16:45 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"