Skip to content

Instantly share code, notes, and snippets.

View mikeschinkel's full-sized avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / gcaptcha-test.php
Last active April 8, 2024 07:44
Sample code showing how to verify Goggle's reCAPTCHA V2 using WordPress wp_remote_post().
<?php
/**
* @see https://developers.google.com/recaptcha/docs/verify
*/
if ( is_dir( __DIR__ . '/wp' ) ) {
require( __DIR__ . '/wp/wp-load.php' );
} else {
require( __DIR__ . '/wp-load.php' );
}
@mikeschinkel
mikeschinkel / .README.md
Last active March 12, 2024 02:48
Go json.Unmarshal() vs. PHP json_decode() performance a large JSON file

GoLang json.Unmarshal() vs. PHP json_decode()

To evaluate if Go json.Unmarshal() is faster or slower than PHP json_decode() for arbitrary JSON I decided to run a quick benchmark on my 2015 MacBook Pro (Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz).

I used this ~25Mb JSON file and ran the attached two program under Go 1.22 and PHP 8.3.2, respectively.

My benchmarks were very unscientific but I was just looking for orders of magnitude.

Here are the results from three different runs, each:

Go (avg 30.82)

@mikeschinkel
mikeschinkel / _readme.md
Last active February 16, 2024 01:10
How to transpose a table in Sqlite
@mikeschinkel
mikeschinkel / .readme.md
Last active February 5, 2024 17:01
Script to create and remove a RAM disk on macOS

How to Create a RAM Disk on macOS

This script creates a RAM disk either in a ./data subdirectory off the root of the current Git repo, or a ./data subdirectory of the current directory if not in a Git repo.

To Attach a RAM Disk

./ramdisk-macos.sh 

To Detatch the RAM disk

package vermock
import (
"testing"
)
//goland:noinspection GoSnakeCaseUsage
type MockGetter interface {
Get_Vermock() *Mock
}
<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/
if (isset($_GET['instrument']) && $_GET['instrument']=='hooks') {
@mikeschinkel
mikeschinkel / test-get-comment-replies.php
Created September 23, 2010 20:58
get_comment_replies() function for WordPress with a working example that returns a WordPress comment object for a given comment ID annotated with "reply_count" and "replies" properties.
<?php
/*
* test-get-comment-replies.php
*
* Returns a comment object for a given comment ID annotated with "reply_count" and "replies" properties:
*
* reply_count: count of all replies including sum of child replies.
* replies: array of child comment objects also annotated with "reply_count" and "replies" properties, recursively.
*
* Examples:
@mikeschinkel
mikeschinkel / root-based-category-urls.php
Created December 2, 2011 01:28
Enabled Root-based Category URLs in WordPress (Any bugs? Post comments below.)
<?php
/*
* Plugin Name: Root-based Category URLs
* Description: Enables root-based Category URLs, i.e. Makes /category/my-category/ URLs route as /my-category/
* Author: Mike Schinkel
* Author URI: http://about.me/mikeschinkel
* Plugin URI: https://gist.github.com/1421235
* Version: 0.1.1
* License: GPL 2+
*/
@mikeschinkel
mikeschinkel / _readme.md
Last active January 24, 2023 05:47
Examples for how a __toArray() magic method could be useful in PHP.

Examples for how a __toArray() magic method could be useful in PHP.

In a nutshell, __toArray() would not be as useful when you have full control over the entire codebase.

But where __toArray() would be extremely useful is in interfacing with existing code that expects arrays and wants those arrays to be a specific format. Using classes and type-hinted methods allow to encapsulate the intelligence into the class, and using __toArray() makes for a nature use-case.

@mikeschinkel
mikeschinkel / chat.md
Last active December 23, 2022 10:26
My question of ChatGPT asking to help me choose PC component for a home router

Me

What is the lowest power combination of server motherboard, CPU, reliable drives, ECC memory, fans and case that would make for a good powerful home router for one person with a lot of computer equipment?

ChatGPT

When choosing a motherboard, CPU, and other components for a home router, it's important to consider the level of performance and reliability you need. You should also consider the power consumption of the components, as a low-power system will be more energy-efficient and potentially save you money on your energy bills.

For a powerful home router for one person with a lot of computer equipment, you might consider using a motherboard with a low-power CPU, such as an Intel Atom or a Qualcomm processor. These CPUs are designed for low-power applications and can provide sufficient performance for routing and other basic tasks. You'll also want to choose reliable drives, such as solid-state drives (SSDs), to ensure that your router is always available.

In addition to the motherboard and CPU,