Skip to content

Instantly share code, notes, and snippets.

View geoffreycrofte's full-sized avatar
📚
Writing books

Geoffrey Crofte geoffreycrofte

📚
Writing books
View GitHub Profile
@geoffreycrofte
geoffreycrofte / terminal
Created November 28, 2018 13:13
Get a count of lines of code in a Github Repository
$ git ls-files | xargs wc -l
@geoffreycrofte
geoffreycrofte / Get-Element-By-Style.js
Last active January 23, 2019 10:54
Get and mark elements on a page regarding their color or any other style.
// Paste that in your Browser console
let allBodyElements = document.querySelectorAll('body *'),
thePropertyName = 'color',
theExpectedValue = 'rgb(0, 82, 204)';
allBodyElements.forEach(function(el){
let style = window.getComputedStyle(el);
if ( style.getPropertyValue(thePropertyName) == theExpectedValue ) {
console.log(el);
el.style.boxShadow = '0 0 0 2px red';
@geoffreycrofte
geoffreycrofte / Some solutions to fix it.
Created October 9, 2019 18:41
How to fix Gulp Issue: gulpInst.start.apply(gulpInst, toRun); TypeError: Cannot read property 'apply' of undefined.
npm i -g gulp-cli

IE CSS Hacks: IE6, 7, 8, 9, 10, 11, and even Edge

I always struggle with hacks for Edge and IE. See also for other tips: http://browserhacks.com/

IE6 Only

_selector {...}
@geoffreycrofte
geoffreycrofte / defer-enqueue-hook.php
Last active April 15, 2021 09:18
Defer specific CSS and JS with WordPress (for theme or plugins)
<?php
/**
* gc_my_scripts & gc_my_styles are two handles for enqueued CSS and JS.
*
* The CSS trick for defering CSS load and make it non blocking loading if offered by SitePoint
*/
if ( ! function_exists( 'gc_defer_non_critical_css' ) ) {
/**
* Changes the LINK HTML tags to make it load async (deferred)
@geoffreycrofte
geoffreycrofte / coinbase-hack.js
Last active April 30, 2021 13:44
Coinbase Better Tab Title that includes Currency Price and Wallet Amount
// Add value info into title
// Replace thousand_separator and real_currency for your own needs
// Add value info into title
// Replace thousand_separator and real_currency for your own needs
(function(){
let gc_new_title = '';
let sel_asset_amount = '[class*="AssetChartAmount__Wrapper"]';
let sel_wallet_amount = '[class*="BuySellStepper__Containe"] footer span:last-child';
let sel_asset_name = '[class*="styles__Symbol"][data-element-handle="asset-symbol"]';
@geoffreycrofte
geoffreycrofte / page-categories.php
Last active July 23, 2021 08:22
Page Template to list all your categories with their title, description and RSS link
<?php
/**
* @package WordPress
* @subpackage Creative Juiz v2
* Template Name: Category List
* @see: https://gist.github.com/geoffreycrofte/d3b5c0ab64e97278248df59bc53082f0
* @author: Geoffrey Crofte
*/
get_header(); ?>
@geoffreycrofte
geoffreycrofte / functions.php
Last active January 4, 2022 11:32
Save and display the last modified post date in WordPress
<?php
/**
* Adds a timestamp in the first blog option.
* @return void
*/
function juiz_update_last_edit_date() {
if ( is_multisite() ) {
add_blog_option( 1, 'last_post_modified_timestamp', time() );
} else {
add_option( 'last_post_modified_timestamp', time() );
@geoffreycrofte
geoffreycrofte / crofte-admin.js
Last active June 21, 2022 10:30
Get theme color palette from the active WordPress Theme (WP REST API)
;( function( $, window, document, undefined ) {
// Prepare the async function
async function fetchColorsJSON() {
const response = await fetch(crofte.rest_theme_url, {
"headers": {
"Accept": "application/json, */*;q=0.1", // optional
"X-WP-Nonce": crofte.rest_nonce,
"Sec-Fetch-Mode": "cors", // optional
"Sec-Fetch-Site": "same-origin" // optional
@geoffreycrofte
geoffreycrofte / Code.js
Last active November 26, 2022 15:54
Google Docs: Numbering Document headings (titles) Script
/**!
* NUMBER THE HEADINGS
* This script can't be used for commercial purpose.
*
* Script improved by: Geoffrey Crofte / GeoffreyCrofte.com / 2022
* Inspired by: Antoine Martin / ThierrryVanoffe.com / 2020
*/
// Constants will be used later on.
const ui = DocumentApp.getUi();