Skip to content

Instantly share code, notes, and snippets.

View jdpedrie's full-sized avatar
🇺🇸
Doing things

John Pedrie jdpedrie

🇺🇸
Doing things
View GitHub Profile
package ctypes
import "encoding/json"
type Nilable[T any] struct {
val *T
isSet bool
}
func NewNilable[T any](v T) Nilable[T] {
{
"uuid": "7d2e2a2c-4983-4528-b883-491748f274b6",
"raw": "...",
"category_id": 1000904,
"category_path": [
1000914,
4188432,
1000849,
1000904
],
@jdpedrie
jdpedrie / kube.zsh
Last active January 28, 2022 18:24
source <(kubectl completion zsh)
alias k='kubectl'
alias kgp='k get pods'
alias kgpw='k get pods --watch'
alias ka="k config current-context"
alias kgs="k get services"
# List pod images
alias kgpi='kubectl get pods -o=jsonpath='\''{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'\'' | sort'
@jdpedrie
jdpedrie / Parser.php
Created April 20, 2017 00:06
dev/src/Snippet/Parser/Parser.php
<?php
/**
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
<?php
use Google\Cloud\Datastore\DatastoreClient;
$datastore = new DatastoreClient([
'projectId' => $projectId
]);
// I aliased $_POST, but you don't need to if you don't want to.
// This is where I'd perform all the validation and sanitation on the data that was given by the user.

Keybase proof

I hereby claim:

  • I am jdpedrie on github.
  • I am jdp (https://keybase.io/jdp) on keybase.
  • I have a public key whose fingerprint is 6FF6 430F 4653 852D 8EAC 423A 0D9F 0136 5004 6559

To claim this, I am signing this object:

* @param array $options
* @return array An array of subscription info

HTTP For Beginners

  • What is HTTP?
    • What is a Protocol & What is Hyper Text?
    • HTTP Requests and Responses
    • Components of a Request and Response
    • HTTP Methods
    • HTTP Status
      • httpstatus.es
  • Explain different groups (2xx ok, 3xx redirect, 4xx client error, 5xx server error)
@jdpedrie
jdpedrie / DI.js
Last active August 29, 2015 14:09
Angular-style Dependency Injection!
var di = function() {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var ARGUMENT_NAMES = /([^\s,]+)/g;
var deps = {};
var getParamNames = function(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
if(result === null) {
@jdpedrie
jdpedrie / gist:ea32c2f4a94c32092e52
Created May 2, 2014 15:05
Turn WP_Error into Catchable Exception.
<?php
use WP_Error;
use App\Exceptions\RemoteCallException;
function remote_get($url, $args)
{
$result = wp_remote_get($url, $args);
if ($result instanceOf WP_Error) {
$errorCode = current(array_keys($result->errors));