Skip to content

Instantly share code, notes, and snippets.

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

Joshua Cerbito joshuacerbito

🔥
🎸🎛🎛🎚🔊
View GitHub Profile
@joshuacerbito
joshuacerbito / sw.js
Created March 1, 2021 07:03
Simple Caching Strategy for Service Workers
const cacheName = 'mycache';
self.onFetch = event => {
const request = event.request;
const networkResponsePromise = fetch(request).catch(_ => {});
const cachedResponsePromise = caches.match(request);
event.respondWith(async function () {
const cacheResponse = await cachedResponsePromise;
@joshuacerbito
joshuacerbito / github-markdown-preview.css
Created February 22, 2021 06:09
Github's Markdown Preview Styles
.markdown-body .octicon {
display: inline-block;
fill: currentColor;
vertical-align: text-bottom;
}
.markdown-body .anchor {
float: left;
line-height: 1;
margin-left: -20px;
@joshuacerbito
joshuacerbito / .editorconfig
Created February 6, 2021 14:11
Useful Dot Files
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[**.{css,scss}]
indent_style = tab
@joshuacerbito
joshuacerbito / README.md
Last active January 26, 2021 05:16
Custom Title Bar Colors for VS Code

Custom Title Bar Colors for VS Code

A simple tool that changes your VS Code's Title Bar Colors depending on the type of workspace that you're currently in. Useful for Full-Stack developers who like to jump from workspace to workspace.

Setup Instructions

  1. Open your terminal and cd into your root directory (e.g. cd ~, or cd /Users/YOURNAME/)
  2. Create a new folder named bin if you don't have one yet
  3. Export your bin directory to the PATH (e.g. for bash: export PATH=$PATH:/Users/YOURNAME/bin, for ZSH: export PATH=$HOME/bin:/usr/local/bin:$PATH)
  4. Copy the two files vs-fe and vs-be into your bin directory
@joshuacerbito
joshuacerbito / wp_allow_webp.php
Last active March 4, 2022 06:32
Wordpress Allow WP Uploads
<?php
/**
* Sets the extension and mime type for .webp files.
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
@joshuacerbito
joshuacerbito / disable_gutenberg.php
Created July 16, 2020 14:06
Wordpress Action for disabling Block-Editor (Gutenberg)
<?php
add_filter('use_block_editor_for_post_type', '__return_false');
@joshuacerbito
joshuacerbito / instructions_speedwatch.md
Last active October 12, 2022 20:45
Simple shell script for watching Internet Speed using Ookla's Speed Test CLI

IMPORTANT NOTE: This only works for MacOS!

The speedwatch shell script requires Homebrew. If you don't have it yet, speedwatch will install it for you. It might take a while, but once installed, using speedwatch should be instant.

Installation Instruction

  1. Open your terminal and paste the following lines:
curl https://gist.githubusercontent.com/joshuacerbito/afdb962d32fc8c1b6e62c7a4ea60528e/raw/speedwatch -o speedwatch
@joshuacerbito
joshuacerbito / gutenberg-custom-category.php
Last active April 1, 2020 15:38
Adding a Custom Category to Gutenberg
<?php
add_filter( 'block_categories', function( $categories, $post ) {
return array_merge(
$categories,
[
[
'slug' => 'my-category',
'title' => __( 'My Custom Category', 'my-namespace' ),
],
@joshuacerbito
joshuacerbito / Blog.jsx
Last active November 20, 2019 09:35
Code Splitting in React
import React from 'react';
export function Blog(props) {
// const [posts] = useState(props.posts);
return (
props.posts.map(({ id, title, body }) => {
return (
<article key={id}>
<h3>{title}</h3>
<div>{body}</div>
@joshuacerbito
joshuacerbito / useSessionStorage.js
Created July 25, 2019 07:10
Custom React Hook for handling session storage
import { useState } from 'react';
export default function useSessionStorage(key, initialValue) {
const [item, setInnerValue] = useState(() => {
try {
return window.sessionStorage.getItem(key)
? JSON.parse(window.sessionStorage.getItem(key))
: initialValue;
} catch (error) {
return initialValue;