Skip to content

Instantly share code, notes, and snippets.

@bpb54321
bpb54321 / counter.tsx
Created August 14, 2024 19:34
Monitor why a React component was called
import React, { useEffect, useRef, useState } from 'react';
export const Counter: React.FC = () => {
const [count, setCount] = useState(0);
const previousValueRef = useRef(count);
const isMountRef = useRef(true);
console.log('Counter called');
console.log(`Previous value = ${previousValueRef.current}`);
@bpb54321
bpb54321 / bazel-commands.sh
Created January 20, 2024 18:22
Useful Bazel commands
# Clean out the Bazel cache
bazel clean --expunge --async
@bpb54321
bpb54321 / useful-linux-commands.sh
Last active January 18, 2024 18:21
Useful Linux Commands
#!/bin/bash
# Interactive disk utilization utility
ncdu /
# report file system disk space usage, -h = human-readable
df -h
@bpb54321
bpb54321 / exampleUsage.js
Last active March 11, 2021 14:55
Custom React Hook for tracking when a given value changes, which would cause a component to re-render. Should be called for every prop or state value in a component if you want to figure out what is causing a re-render.
import { COUNT_INCREMENTED } from "./countReducer";
import useCount from "./useCount";
import useValueDifference from "./useValueDifference";
const Counter = () => {
console.log("Counter");
const [count, dispatchCount] = useCount();
useValueDifference({ count });
return (
<>
@bpb54321
bpb54321 / launch.json
Created May 30, 2018 21:31
VSCode debug configuration for WebdriverIO
{
"version": "0.2.0",
"configurations": [
{
"name": "WebdriverIO",
"type": "node",
"request": "launch",
"protocol": "inspector",
"address": "localhost",
"port": 5859,
@bpb54321
bpb54321 / php-in-html.php
Last active January 29, 2018 20:26
Formatting for PHP in HTML.
<?php
// Example formatting for PHP/HTML Templates.
// Use WordPress coding standards: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/
?>
<?php
/*
* Order of classes:
* BEM element and modifiers, BEM block and modifiers, Bootstrap layout/grid classes, state/javascript classes.
*/
@bpb54321
bpb54321 / deploy.sh
Created December 8, 2017 20:44
WordPress Deploy Bash Script
#!/usr/bin/env bash
# Variables
DB_FILENAME=
LOCAL_DIR=
LOCAL_UPLOADS_DIR=
SERVER_DIR=
SERVER_UPLOADS_DIR=
SERVER_THEME_DIR=
LOCAL_DB_PASS=
LOCAL_DB_USER=
@bpb54321
bpb54321 / change_permissions.sh
Created December 5, 2017 21:01
Change file permissions recursively using 'find'
chown -R [username]:cndls-admins [directory]
cd [directory]
find ./ -type d -exec chmod 775 {} \;
find ./ -type f -exec chmod 664 {} \;
@bpb54321
bpb54321 / _body.scss
Created July 20, 2017 20:26
Fix for keeping body from scrolling when there is an overlay on iOS Safari 10.
body {
overflow-y: scroll;
&.js-nav-menu-open,
&.js-social-menu-open,
&.js-search-menu-open {
position: fixed;
width: 100%;
height: 100%;
@bpb54321
bpb54321 / _hero.php
Last active June 4, 2018 00:01
Script which responsively loads a background video from a number of video resolutions based on screen size. Fades the new video in.
<div class="hero js-scale-media-container">
<video class="hero__video js-scale-media" autoplay playsinline loop muted>
<source src="fpo/video/toky_background_sd_640x360.mp4" type="video/mp4">
</video>
<div class="hero__overlay-block">
<div class="hero__slash-label animate-slide-up-100px-from-below-fade-in">At Toky</div>
<h1 class="hero__header-1 animate-slide-up-100px-from-below-fade-in-first-delay">We believe our world can be more thoughtful, more humane, and more beautiful.</h1>
<a href="/what-we-do/" class="hero__link-button animate-slide-up-100px-from-below-fade-in-second-delay">About TOKY</a>
</div>
<a href="#expertise" aria-label="Scroll to the next section.">