Skip to content

Instantly share code, notes, and snippets.

Working with the amazing team at Landing. #liveeverywhere

Sterling Hamilton grok

Working with the amazing team at Landing. #liveeverywhere
View GitHub Profile
grok /
Last active Aug 27, 2022
Chrome DevTools / console.log Expand All / Collapse All

Hacking Chrome DevTools

You ever have a bunch of console.log instances you wish you could just expand or collapse at once? Well this will do that.

You of course need to open your DevTools Console, on a mac that shortcut is ⌘ (Command) + ⌥ (Shift) + J

Now hit ⌘ (Command) + ⌥ (Shift) + J again to open DevTools for your DevTools.

Then run the code below. If you run it once, it will collapse everything it can. If you run it again, it will expand.

grok / simple-sitemap.xml
Created Sep 23, 2019
Very simple sitemap -- totally valid, but not very useful.
View simple-sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
grok / houroftheyear.js
Created Aug 21, 2016
This is the current hour of the year... but rolled back to the beginning of the day.
View houroftheyear.js
var timestmp = new Date().setFullYear(new Date().getFullYear(), 0, 1);
var yearFirstDay = Math.floor(timestmp / 86400000);
var today = Math.ceil((new Date().getTime()) / 86400000);
var dayOfYear = today - yearFirstDay;
var currentHourOfYear = dayOfYear * 24 - 24
grok / example.php
Created Aug 3, 2016
This is an example implementation of the patch for
View example.php
add_filter( 'wp_generate_attachment_metadata', __NAMESPACE__ . '\\update_attachment_metadata', 10, 2 );
function update_attachment_metadata( $data, $attachment_id ) {
$dimensions = false;
$post = get_post( $attachment_id );
$file = wp_get_attachment_url( $attachment_id );
$path = get_attached_file( $attachment_id );
grok / commitstrip.html
Last active Jul 20, 2016
Maximum-scale Maximum-scale define maximum zoom. When you access website top priority is maximum-scale=1 won’t allow the user to zoom.
View commitstrip.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<!--[if IE 6]>
<html id="ie6" lang="en-US">
<!--[if IE 7]>
<html id="ie7" lang="en-US">
<!--[if IE 8]>
<html id="ie8" lang="en-US">
grok / pre-commit
Last active Jul 6, 2016
git pre-commit hook for checking for debug code you don't want committed. Basically add a comment that says // @debug or @debug or @debug -- and this will not let you commit that line.
View pre-commit
NC='\033[0m' # No Color
git diff --cached --name-status | while read x file; do
if [ "$x" == 'D' ]; then continue; fi
grok / duplicate-emails.js
Created Jun 16, 2016
I have a dirty install of Magento 1.7 -- one of the things I noticed is that I have duplicate e-mail addresses across clients. So I wrote a quick hack that helps find them visually.
View duplicate-emails.js
var emails = [];
// Intended to be ran from the Customer Management screen of Magento 1.7
// This really only works if you have < 3000 accounts.
// Why? Because 1.7 only shows up to 3000 at a time. If pagination comes into play, this thing becomes less effective.
// But you could probably still hack it to get some data out and still do what you were looking to do.
jQuery('.data tr td:nth-child(4)').each(function() { // Email is in the forth column of the table.
var email = $(this).text().trim();
if(jQuery.inArray(email, emails) === -1) {
grok / gist:cce113792c13fa1cb35631feed6213b3
Created Jun 16, 2016
I have a dirty install of Magento. One of the things I noticed is that e-mails are duplicated for some accounts. This is a quick hack to track them down.
View gist:cce113792c13fa1cb35631feed6213b3
var emails = [];
// Magento 1.7 -- Customer Management Screen
// Make sure to list out all/most of your customers -- or this loses its effectiveness as pagination is now in play.
jQuery('.data tr td:nth-child(4)').each(function() { // Email is in the forth column.
var email = $(this).text().trim();
if(jQuery.inArray(email, emails) === -1) {
} else {
$(this).css('background-color', 'red'); // Visually find the duplicate.
grok / example.php
Created Jan 6, 2016
Example of permalink taxonomies.
View example.php
add_action( 'init', 'create_model_taxonomy' );
function create_model_taxonomy() {
'resource', // Might need to change this if the CPT has a different name.
'label' => __( 'Tanel\'s Model' ),
'rewrite' => array( 'slug' => 'model' ),
grok / functions.php
Last active Aug 29, 2015
I don't really like categories. I prefer tags. Let's hide what's not going to be used.
View functions.php
namespace ChangeMe\Theme\Modules;
class Core {
public function __construct() {
add_action('admin_init', array($this, 'disable_category_feature'));
add_filter('rewrite_rules_array', array($this, 'remove_category_rewrites'));