Skip to content

Instantly share code, notes, and snippets.

@ethanpil
ethanpil / jwt_request.php
Created July 28, 2023 15:03
PHP JWT OAuth2 Request Boilerplate
<?php
//https://stackoverflow.com/a/48896992/933782
function jwt_request($token, $post) {
header('Content-Type: application/json'); // Specify the type of data
$ch = curl_init('https://APPURL.com/api/json.php'); // Initialise cURL
$post = json_encode($post); // Encode the data array into a JSON string
$authorization = "Authorization: Bearer ".$token; // Prepare the authorisation token
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization )); // Inject the token into the header
@ethanpil
ethanpil / wc_make_processing_orders_editable.php
Created March 21, 2023 01:13
Make WooCommerce order status Processing editable
<?php
//https://nicolamustone.blog/2015/05/14/how-to-edit-processing-orders/
add_filter( 'wc_order_is_editable', 'wc_make_processing_orders_editable', 10, 2 );
function wc_make_processing_orders_editable( $is_editable, $order ) {
if ( $order->get_status() == 'processing' ) {
$is_editable = true;
}
return $is_editable;
@ethanpil
ethanpil / mark.sh
Created March 12, 2023 18:10
Shell Bookmark Directories
# https://news.ycombinator.com/item?id=35122780#35123388
# http://karolis.koncevicius.lt/posts/fast_navigation_in_the_command_line/
<<USAGE
mark @name # add bookmark called @name for the current directory
cd @name # jump to the bookmarked location
cd @<tab> # list all available bookmarks
USAGE
export CDPATH=.:~/.marks/
function mark {
<?php
/**
* Reference/source: http://stackoverflow.com/a/1464155/933782
*
* I want a short alphanumeric hash that’s unique and who’s sequence is difficult to deduce.
* I could run it out to md5 and trim the first n chars but that’s not going to be very unique.
* Storing a truncated checksum in a unique field means that the frequency of collisions will increase
* geometrically as the number of unique keys for a base 62 encoded integer approaches 62^n.
* I’d rather do it right than code myself a timebomb. So I came up with this.
*
@ethanpil
ethanpil / wordpress-custom-admin-menu.php
Created December 26, 2022 20:50
Re-Order and Hide Wordpress Admin Menu Items
<?php
/* How to Rearrange/Hide WordPress Admin Menu Links
Source: https://www.digital.ink/blog/wordpress-rearrange-admin-menu/
1) Find the URL slug of relevant menu items (everything past the /wp-admin/)
2) Re-order as in the first function.
3) Add separators as necessary.
NOTE: If you don’t add an item to your custom menu order, and don’t remove it completely,
it will fall in line below your custom order. So if you only want to re-order the first few
@ethanpil
ethanpil / index.html
Created April 27, 2020 06:20
Flexbox Dead Center
<html>
<head>
<title>Flexbox Dead Center</title>
<style>
.deadcenter {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100%;
$gnuplotcommands = '
set terminal png size 640x480
set grid
set autoscale
unset log
unset label
set xtics 0,1,23
set ytic auto
set title "Sample Chart Data"
set xlabel "Date"
#install wkhmltopdf on alpine linux 3.15
apk add --update --no-cache --wait 10 libstdc++ libx11 libxrender libxext libssl1.1 ca-certificates fontconfig freetype ttf-dejavu ttf-droid ttf-freefont ttf-liberation && \
apk add --update --no-cache --virtual .build-deps msttcorefonts-installer
update-ms-fonts && fc-cache -f
rm -rf /tmp/* && apk del .build-deps
cd /usr/bin
curl -LJO https://github.com/khalilgharbaoui/wkhtmltopdf-binary-edge-alpine/raw/master/libexec/wkhtmltopdf-alpine-linux-amd64
mv wkhtmltopdf-alpine-linux-amd64 wkhtmltopdf
#https://codingwithmanny.medium.com/configure-self-signed-ssl-for-nginx-docker-from-a-scratch-7c2bcd5478c6
apk add nginx
mkdir /etc/ssl/private
openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=Company, Inc./CN=mydomain.com" -addext "subjectAltName=DNS:mydomain.com" -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt;
mkdir /srv/www
chown -R nginx:nginx /srv/www
#Configuring nginx
@ethanpil
ethanpil / alpine-dropbear-ssh.sh
Last active November 4, 2022 18:41
Install Drop Bear SSH Deamon on Alpine Linux
#Install Dropbear
apk add dropbear
#Start the service
rc-service dropbear start
#Add it to the default runlevel
rc-update add dropbear
#Settings in /etc/conf.d/dropbear