Skip to content

Instantly share code, notes, and snippets.

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

Johnny Benson johnnybenson

👽
let's go
View GitHub Profile
@johnnybenson
johnnybenson / clean_up_lambda.sh
Created March 29, 2023 21:17
Clean up old AWS Lambda Functions
function run() {
LAMBDA_FUNCTION=$1;
LAMBDA_VERSIONS_DATA=$(aws lambda list-versions-by-function --function-name $LAMBDA_FUNCTION);
LAMBDA_VERSIONS=$(echo $LAMBDA_VERSIONS_DATA | jq -r '.Versions | map(select(.Version != "$LATEST")) | map(.Version | tonumber)');
LAMBDA_VERSION_LATEST=$(echo $LAMBDA_VERSIONS | jq -r 'sort | .[-1:][0]');
echo "Latest Version: $LAMBDA_VERSION_LATEST";
LAMBDA_VERSIONS_ARR=($(echo $LAMBDA_VERSIONS | jq -r 'join(" ")'));
for version in "${LAMBDA_VERSIONS_ARR[@]}"; do
if (( version < LAMBDA_VERSION_LATEST )); then
echo "Removing old Version: $version";
@johnnybenson
johnnybenson / Dockerfile
Created March 10, 2022 20:39
Docker + Rust + Heroku + Cargo Chef -- Small multistage build that works on Heroku with dependency caching with working SSL
################################################################################
## Rust -- Recipe
################################################################################
FROM rust:latest AS chef
RUN cargo install cargo-chef
WORKDIR /var/app
FROM chef AS planner
@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 / isInt.ts
Last active October 30, 2020 18:11
is Integer
const isInt = (num: number) => num % 1 === 0;
@johnnybenson
johnnybenson / react-router-route-transition-example.js
Created May 15, 2020 16:15
React Router v5 TransitionGroup CSSTransition Directional Animation with CSS Modules
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { CSSTransition, TransitionGroup } from 'react-transition-group';
import styles from './styles.module.scss';
const TRANSITIONS = {
PUSH: {
enter: styles.LeftEnter,
enterActive: styles.LeftEnterActive,
exit: styles.LeftExit,
@johnnybenson
johnnybenson / offset-targetted-inline-anchor.css
Created April 26, 2020 21:21
Offset targeted inline anchor
:target {
&::before {
display: block;
content: ' ';
margin-top: -5vh;
height: 5vh;
visibility: hidden;
pointer-events: none;
}
}
@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
@johnnybenson
johnnybenson / routes.rb
Created May 3, 2019 16:40
Simple way to alias Devise gem /login /logout without changing underlying configuration
devise_scope :user do
get '/login' => 'users/sessions#new', :as => 'login'
get '/logout' => 'users/sessions#destroy', :as => 'logout'
end
// 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()