Skip to content

Instantly share code, notes, and snippets.

@icodus
icodus / wp-rest-api-example.py
Created November 23, 2022 23:40 — forked from jdembowski/wp-rest-api-example.py
Use cookie authentication to obtain a nonce for WP REST API calls that need authentication.
#!/usr/bin/python3
# This Python script will
#
# - Log into a WordPress installation using supplied credentials.
# - Get a single published post using the REST call /wp/v2/posts
# - Get a valid nonce from '/wp-admin/post.php?post=xxx&action=edit'
# - Use cookie+nonce to retrieve on post in draft status via REST.
#
# Getting that valid nonce must be performed prior to each WP REST call
@icodus
icodus / Dockerfile
Created November 19, 2022 14:17 — forked from hermanbanken/Dockerfile
Compiling NGINX module as dynamic module for use in docker
FROM nginx:alpine AS builder
# nginx:alpine contains NGINX_VERSION environment variable, like so:
# ENV NGINX_VERSION 1.15.0
# Our NCHAN version
ENV NCHAN_VERSION 1.1.15
# Download sources
RUN wget "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" -O nginx.tar.gz && \
@icodus
icodus / my_cpt_404_redirects.php
Created October 28, 2022 13:23 — forked from strangerstudios/my_cpt_404_redirects.php
Use template_redirect and post_type_link filters in WordPress to remove the CPT slug from the front of CPT URLs.
/*
If 404 on a post, look for a gallery or portfolio with the same slug.
Borrows from: https://wordpress.stackexchange.com/a/45081/3652
*/
function my_cpt_404_redirects($template)
{
if(is_404())
{
//see if we know the exact post ID
@icodus
icodus / systemd-prblm.service
Created October 12, 2022 10:01 — forked from nickjacob/systemd-prblm.service
execute arbitrary bash code/variable substitution in systemd units
[Unit]
Description=Demonstrate Bash
[Service]
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment MYVAR=$(( 2 + 2 ))"
ExecStart=/usr/bin/echo "2 + 2 = ${MYVAR}"
@icodus
icodus / rsa.go
Created June 23, 2022 10:20 — forked from sohamkamani/rsa.go
Example of RSA encryption, decryption, signing, and verification in Go
package main
import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"fmt"
)
@icodus
icodus / rsaencryption.go
Created June 23, 2022 09:56 — forked from hansstimer/rsaencryption.go
Go: rsa public key encryption
package main
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
"fmt"
)
@icodus
icodus / rsasign.go
Created June 22, 2022 15:37 — forked from hansstimer/rsasign.go
Go: rsa signpkcs1v15 signing
package main
import (
"bytes"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"fmt"
)
<?php
// Init
// -----------------------------------------------------------------------
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load
// -----------------------------------------------------------------------
require('wp-load.php');
@icodus
icodus / google_authenticator.go
Created May 10, 2022 14:37 — forked from tilaklodha/google_authenticator.go
Simple Google Authenticator script in go
// Checkout the readme for this here: https://github.com/tilaklodha/google-authenticator
package main
import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/base32"
"encoding/binary"
@icodus
icodus / slack_notification.php
Created May 1, 2022 13:39 — forked from alexstone/slack_notification.php
Fire a Slack Notification via CURL
<?php
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
public static function slack($message, $room = "engineering", $icon = ":longbox:") {
$room = ($room) ? $room : "engineering";
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => $message,