Skip to content

Instantly share code, notes, and snippets.

View grok's full-sized avatar
🚀
About to start a new position!

Sterling Hamilton grok

🚀
About to start a new position!
View GitHub Profile
@grok
grok / README.md
Last active August 27, 2022 10:25
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
grok / simple-sitemap.xml
Created September 23, 2019 21:00
Very simple sitemap -- totally valid, but not very useful.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/foo.html</loc>
</url>
</urlset>
@grok
grok / houroftheyear.js
Created August 21, 2016 20:44
This is the current hour of the year... but rolled back to the beginning of the day.
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
grok / example.php
Created August 3, 2016 01:41
This is an example implementation of the patch for https://core.trac.wordpress.org/ticket/37549
<?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
grok / commitstrip.html
Last active July 20, 2016 22:02
Maximum-scale Maximum-scale define maximum zoom. When you access website top priority is maximum-scale=1 won’t allow the user to zoom.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--[if IE 6]>
<html id="ie6" lang="en-US">
<![endif]-->
<!--[if IE 7]>
<html id="ie7" lang="en-US">
<![endif]-->
<!--[if IE 8]>
<html id="ie8" lang="en-US">
@grok
grok / pre-commit
Last active July 6, 2016 20:02
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.
#!/bin/sh
disallowed="@debug"
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
git diff --cached --name-status | while read x file; do
if [ "$x" == 'D' ]; then continue; fi
@grok
grok / duplicate-emails.js
Created June 16, 2016 15:02
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.
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) {
emails.push(email);
@grok
grok / gist:cce113792c13fa1cb35631feed6213b3
Created June 16, 2016 14:58
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.
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) {
emails.push(email);
} else {
$(this).css('background-color', 'red'); // Visually find the duplicate.
@grok
grok / example.php
Created January 6, 2016 17:16
Example of permalink taxonomies.
<?php
add_action( 'init', 'create_model_taxonomy' );
function create_model_taxonomy() {
register_taxonomy(
'model',
'resource', // Might need to change this if the CPT has a different name.
array(
'label' => __( 'Tanel\'s Model' ),
'rewrite' => array( 'slug' => 'model' ),
@grok
grok / functions.php
Last active August 29, 2015 14:20
I don't really like categories. I prefer tags. Let's hide what's not going to be used.
<?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'));
}