Skip to content

Instantly share code, notes, and snippets.

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

Joshua Cerbito joshuacerbito

🔥
🎸🎛🎛🎚🔊
View GitHub Profile
const ObjectSingleton = {
_instance: null,
get instance() {
if (!this._instance) {
this._instance = {
singletonMethod() {
return 'singletonMethod';
},
_type: 'ObjectSingleton',
@joshuacerbito
joshuacerbito / wp_remove_emojis.php
Last active August 27, 2018 18:54
Wordpress Remove Emoji Scripts
<?php
/*
* REMOVE WORDPRESS' CRAPPY EMOJI
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
@joshuacerbito
joshuacerbito / find-and-delete.sh
Last active January 3, 2022 19:13
Recursively find (and delete) all files of the same type in current directory
# Recursively find all files of the same type in current directory
find . -name "*.bak" -type f
# Recursively find and delete all files of the same type in current directory
find . -name "*.bak" -type f -delete
# Print out a list of directories to be deleted:
find . -name 'node_modules' -type d -prune
# Delete directories from the current working directory:
@joshuacerbito
joshuacerbito / countries.geojson.js
Last active March 14, 2018 11:59 — forked from markmarkoh/gist:2969317
World Map Geo JSON data
export default {"type":"FeatureCollection","features":[
{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[74.92,37.24],[74.57,37.03],[72.56,36.82],[71.24,36.13],[71.65,35.42],[71.08,34.06],[69.91,34.04],[70.33,33.33],[69.51,33.03],[69.33,31.94],[66.72,31.21],[66.26,29.85],[62.48,29.41],[60.87,29.86],[61.85,31.02],[60.84,31.5],[60.58,33.07],[60.94,33.52],[60.51,34.14],[61.28,35.61],[62.72,35.25],[63.12,35.86],[64.5,36.28],[64.8,37.12],[66.54,37.37],[67.78,37.19],[69.32,37.12],[70.97,38.47],[71.59,37.9],[71.68,36.68],[73.31,37.46],[74.92,37.24]]]]},"properties":{"name":"Afghanistan"},"id":"AF"},
{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[19.44,41.02],[19.37,41.85],[19.65,42.62],[20.07,42.56],[20.59,41.88],[20.82,40.91],[20.98,40.86],[20.01,39.69],[19.29,40.42],[19.44,41.02]]]]},"properties":{"name":"Albania"},"id":"AL"},
{"type":"Feature","geometry":{"type":"MultiPolygon","coordinates":[[[[2.96,36.8],[8.62,36.94],[8.18,36.52],[8.25,34.64],[7.49,33.89],[9.06,32.1],[
@joshuacerbito
joshuacerbito / pre-fill-acf-repeater.php
Last active August 29, 2023 07:51
Pre-Fill Wordpress ACF Repeater Field
<?php
// Pre-fills a repeater field (and its sub-fields) with default values
// - assuming we have a Repeater field with the key "repeater_field_123"
// - with the sub-fields "sub_field_1" and "sub_field_2"
function prefill_repeater( $field ) {
if ($field['value'] === false) {
$field['value'] = array(
array(
@joshuacerbito
joshuacerbito / fetch-worker.js
Last active October 25, 2018 07:54
Web Worker for a generic Fetch
/*
* Fetch Worker
* Usage:
* const fetchWorker = new Worker('./fetch-worker.js');
* fetchWorker.postMessage('https://some.api/with-data.json');
*/
self.addEventListener(‘message’, e => {
let url = e.data;
@joshuacerbito
joshuacerbito / react-webpack-config.js
Created October 25, 2018 09:14
Sample Webpack Config for React JS Development
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const devMode = process.env.NODE_ENV !== 'production'
const config = {
entry: './src/index.js',
output: {
/**
* Return the value if the conditional provided passes.
*
* @param {Boolean} conditional
* @param {*} template
*/
export const when = (conditional, thing, output = null) => !!conditional ? thing : output;
@joshuacerbito
joshuacerbito / _mixins.scss
Last active November 17, 2018 17:14
Common SCSS Setup
@mixin breakpoint($breakpoint) {
@if map-has-key($breakpoints, $breakpoint) {
@media (min-width: #{map-get($breakpoints, $breakpoint)}) {
@content;
}
} @else {
@media (min-width: $breakpoint) {
@content;
}
}
@joshuacerbito
joshuacerbito / array-forward-backward.js
Created November 20, 2018 04:15
Optimal logic for moving foward and backward through your array
/*
* Optimal logic to move through your array forward and backward
*/
const arr = ['a', 'b', 'c', 'd', 'e'];
let currentIndex = 0;
function moveForward(current, array) {
return (current + 1) % array.length;
}