Skip to content

Instantly share code, notes, and snippets.

View gabesullice's full-sized avatar

Gabe Sullice gabesullice

View GitHub Profile
@gabesullice
gabesullice / shell_scripting.md
Last active August 24, 2023 07:05
Shell Scripting for Fun and Profit

A few days ago, I mentioned to Rob Ballou, that there's just something very satisfying about shell scripting. Once you've groked all its little idiosyncracies, it's really quite addictive. As developers, I think we all get some gratification from getting things done, but also from building elegant, complete systems. For me, shell scripting really scratches all those itches. I get to build a system from start to finish, completely self-contained and solve a real problem.

Elegant, complete systems might at first seem antithetical to what most people think of shell scripting. Shell scripting is plagued by weird quoting, strange unfamiliar constructions, and a lack useful data types. However, once you embrace the things that shell scripting is good at and learn a few strategies for writing scripts tidily, it can become a fantastic tool for solving real, every day problems.

So, what are those strategies and what are things that the shell does well?

The Last Template You'll Ever Need

#!/bin/bash
@gabesullice
gabesullice / example.php
Last active June 26, 2023 09:57
self vs static vs $this
<?php
class ParentClass {
public static string $foo = 'ooh';
public string $bar = 'lala';
public function __construct($arg) {
$this->bar = $arg;
@gabesullice
gabesullice / notes.md
Last active January 10, 2023 16:04
FrankenPHP w/ Drupal notes
  • Overrides
    • Changed the root directive in the Caddyfile to web instead of public
    • Used -v $PWD:/app instead of /app/public
    • Added error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT to php.ini and used -v $PWD/php.ini:/usr/local/lib/php.ini to suppress warnings. Deprecations were still being printed out.
  • Observations
    • Many warnings like this one: **Warning**: ini_set(): Session ini settings cannot be changed after headers have already been sent in **/app/web/core/lib/Drupal/Core/DrupalKernel.php** on line **1000**
    • Many deprecations were printed out, such as: __Deprecated function__: Creation of dynamic property Drupal\Core\Installer\InstallerKernel::$_serviceId is deprecated in __Drupal\Core\DependencyInjection\ContainerBuilder->set()__ (line __83__ of __/app/web/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php__).
    • Drupal is still not compatible with PHP 8.2: https://www.drupal.org/project/drupal/issues/3283358
  • FrankenPHP compiles PHP
@gabesullice
gabesullice / meminfo.go
Created January 6, 2023 11:16
Graph /proc/meminfo with Go and Graphite
package main
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
"strconv"
"time"
@gabesullice
gabesullice / ResponseSubscriber.php
Last active May 5, 2022 22:56
Dynamically Redirecting Drupal 8 Node Pages
<?php
/**
* This file should live at my_module/src/EventSubscriber/ResponseSubscriber.php
*/
namespace Drupal\my_module\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;

Status

This extension was developed as part of the jsonapi module for Drupal.

Introduction

The JSON API specification is agnostic about how a server implements filtering strategies. In fact, the spec says:

Note: JSON API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

@gabesullice
gabesullice / fetcher.js
Last active February 5, 2021 19:34
Tiny Go server to test browser implementations of the vary: accept header
"use strict"
// Fetches the browser window's URL with an accept header set to the mediaType.
async function doFetch(mediaType, host) {
const loc = window.location
const url = `${loc.protocol}//${host || loc.host}${loc.pathname}`;
const options = {
headers: {
accept: mediaType,
},
let count = undefined;
let startTime = undefined;
export class ErrorNotStarted extends Error {
constructor() {
super("The counter has not been started.");
}
}
export class ErrorAlreadyStarted extends Error {
@gabesullice
gabesullice / jsonapi_operations.experiment.patch
Created May 16, 2019 18:50
Experiment (ignore everything about the "registry")
diff --git a/jsonapi_operations.services.yml b/jsonapi_operations.services.yml
index bbb3da6..d6fd805 100644
--- a/jsonapi_operations.services.yml
+++ b/jsonapi_operations.services.yml
@@ -6,3 +6,8 @@ services:
- '@jsonapi.resource_type.repository'
- '@database'
- '@http_kernel'
+
+ jsonapi_operations.local_id_registry:
@gabesullice
gabesullice / error.sh
Created September 5, 2017 16:12
Make output
[0] gabe EW7833UAC_linux_v4.3.21_17997.20160531 $ sudo make
make ARCH=x86_64 CROSS_COMPILE= -C /lib/modules/4.12.4-1-ARCH/build M=/home/gabe/Downloads/edimax/EW7833UAC_linux_4.3.21_kernel_3.16-4.4/EW7833UAC_linux_v4.3.21_17997.20160531 modules
make[1]: Entering directory '/usr/lib/modules/4.12.4-1-ARCH/build'
CC [M] /home/gabe/Downloads/edimax/EW7833UAC_linux_4.3.21_kernel_3.16-4.4/EW7833UAC_linux_v4.3.21_17997.20160531/os_dep/linux/ioctl_linux.o
/home/gabe/Downloads/edimax/EW7833UAC_linux_4.3.21_kernel_3.16-4.4/EW7833UAC_linux_v4.3.21_17997.20160531/os_dep/linux/ioctl_linux.c: In function ‘rtw_ioctl_wext_private’:
/home/gabe/Downloads/edimax/EW7833UAC_linux_4.3.21_kernel_3.16-4.4/EW7833UAC_linux_v4.3.21_17997.20160531/os_dep/linux/ioctl_linux.c:14004:5: error: implicit declaration of function ‘is_compat_task’; did you mean ‘is_idle_task’? [-Werror=implicit-function-declaration]
if(is_compat_task())
^~~~~~~~~~~~~~
is_idle_task