Skip to content

Instantly share code, notes, and snippets.

View mikeschinkel's full-sized avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / .README.md
Last active September 8, 2025 03:34
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 / find-in-set.php
Last active July 27, 2025 14:49
Adds FIND_IN_SET support as a comparison operator for WordPress meta_query. Include this in a plugin, in the theme's functions.php file, or as a separate file that is loaded using require() or include() before your call to WP_Query. As @Otto42 points out, you might not want to use this in a plugin that you plan to distribute given the WordPress'…
<?php
/**
* Class Add_Find_In_Set_Compare_To_Meta_Query
*/
class Add_Find_In_Set_Compare_To_Meta_Query {
/**
*
*/
function __construct() {
<?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 / mv-jetbrains-ide-project.sh
Created March 31, 2025 20:45
Bash script to rename the directory a JetBrain's IDE project is contained in (I got tired of waiting for JetBrains to add this obviously needed feature to their actual IDE!)
#!/usr/bin/env bash
set -euo pipefail
# Check if both arguments are provided
if [ $# -ne 2 ]; then
echo "Rename a Jetbrains IDE project"
echo "Usage:"
echo " $(basename "$0") <old_project_name> <new_project_name> [<projects_dir default=~/Projects>]"
exit 1
@mikeschinkel
mikeschinkel / _LOGGER_FOR_GOLANG.md
Last active March 30, 2025 06:10
Go logging package that leverages slog.Default() for creating package-level loggers (Proof-of-concept)

This solution is built on top of Go's log/slog package and leverages slog.Default(). To use it a developer should declare a package variable logger in every package that is part of their Go project that needs to perform logging (e.g. a package containing only type, var and/or const declarations would usually not need a logger.go file.)

Add a logger.go file to every packages and then add this line to the file, updating it with the package's name:

var logger = logging.NewPackageLogger("<package_name>")    

This uses a small logging package you can find below which has a Logger type simply to embed slog.Log. This allows adding extra methods beyond that provided by slog.Logger and to preprocess calls to *slog.Logger if we later find that to be needed.

@mikeschinkel
mikeschinkel / resume.json
Last active March 24, 2025 22:55
Mike Schinkel's resume — Last updated 2025-03-24 — Also see github.com/mikeschinkel/resume for more recent updates
{
"meta": {
"theme": "kendall"
},
"basics": {
"name": "Mike Schinkel",
"label": "Senior Engineer specializing in Go, OpenAPI, Kubernetes, AWS, and CI/CD",
"photo": "https://www.gravatar.com/avatar/c988a2da603a19e827a39ab4d9186909?s=200&r=pg&d=mm",
"summary": "I am looking a long-term contract role working to enhance software products where my unique set of Go development, OpenAPI, Kubernetes AWS, and CI/CD skills and experience can have a big impact. And I will be really excited if the project I get to work on is open source.",
"location": {
@mikeschinkel
mikeschinkel / membership_test.go
Last active March 19, 2025 12:09
Test for Peformance of SwitchCase vs. IfOr vs. Generic for Determining Membership in Golang
package main_test
import (
"testing"
)
type Lexer struct {
input string // the string being scanned.
pos int // current position in the input.
}
// readType reads a type from r at off of name. It adds types to the
// type cache, appends new typedef types to typedefs, and computes the
// sizes of types. Callers should pass nil for typedefs; this is used
// for internal recursion.
func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Offset]Type, fixups *typeFixer) (t Type, err error) {
var e *Entry
var ok bool
var addressSize int
var typ Type
var nextDepth int
// readType reads a type from r at off of name. It adds types to the
// type cache, appends new typedef types to typedefs, and computes the
// sizes of types. Callers should pass nil for typedefs; this is used
// for internal recursion.
func (d *Data) readType(name string, r typeReader, off Offset, typeCache map[Offset]Type, fixups *typeFixer) (t Type, err error) {
var e *Entry
var ok bool
var addressSize int
var typ Type
var nextDepth int
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"mime"
"net/http"
"net/url"