Skip to content

Instantly share code, notes, and snippets.

View rheinardkorf's full-sized avatar

Rheinard Korf rheinardkorf

View GitHub Profile
@rheinardkorf
rheinardkorf / neovim_install_amazonlinux2.sh
Last active June 27, 2024 07:25
Install neovim on Amazon Linux 2.
#!/usr/bin/env bash
# Same as https://github.com/neovim/neovim/wiki/Installing-Neovim#centos-8--rhel-8
# but requires EPEL 7, not 8.
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y neovim python3-neovim
@rheinardkorf
rheinardkorf / KSUID.gs
Created April 12, 2024 04:24
KSUID implemented in Google Apps Script
// Pseudorandom number generator function
function getRandomBytes(length) {
var result = [];
for (var i = 0; i < length; i++) {
result.push(Math.floor(Math.random() * 256));
}
return result;
}
// Convert bytes to base62 string
@rheinardkorf
rheinardkorf / Hooks.js
Last active April 2, 2024 09:49
Simple WordPress like hooks system for JavaScript.
/**
* @file A WordPress-like hook system for JavaScript.
*
* This file demonstrates a simple hook system for JavaScript based on the hook
* system in WordPress. The purpose of this is to make your code extensible and
* allowing other developers to hook into your code with their own callbacks.
*
* There are other ways to do this, but this will feel right at home for
* WordPress developers.
*
@rheinardkorf
rheinardkorf / gist:0daa5531c60a6c8733b805f29f4d20c1
Last active April 2, 2024 03:44
Example WordPress Proxy Layer
<?php
/**
* Init Proxy endpoints.
*
* @return void
*/
public function rest_api_init() {
/**
@rheinardkorf
rheinardkorf / llama2-mac-gpu.sh
Created July 19, 2023 13:09 — forked from adrienbrault/llama2-mac-gpu.sh
Run Llama-2-13B-chat locally on your M1/M2 Mac with GPU inference. Uses 10GB RAM
# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# Build it
LLAMA_METAL=1 make
# Download model
export MODEL=llama-2-13b-chat.ggmlv3.q4_0.bin
wget "https://huggingface.co/TheBloke/Llama-2-13B-chat-GGML/resolve/main/${MODEL}"
@rheinardkorf
rheinardkorf / add-js-editor.js
Last active June 2, 2023 05:14
Example usage of JS editor API WordPress 4.8+
// Remember to wp_enqueue_editor(); inside PHP.
// Add editor
wp.editor.initialize(
'test-editor',
{
tinymce: {
wpautop:true,
plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
toolbar1: 'formatselect bold italic | bullist numlist | blockquote | alignleft aligncenter alignright | link unlink | wp_more | spellchecker'
@rheinardkorf
rheinardkorf / theme.css
Last active March 15, 2023 02:57
Test Marp Markdown theme.
/* @theme rk */
@import 'default';
h1, h2, h3 {
color: #ffffff;
}
section {
background-image: linear-gradient(to bottom, #67b8e3, #0288d1);
@rheinardkorf
rheinardkorf / Wordpress Nginx Config
Created March 14, 2017 06:41 — forked from kjprince/Wordpress Nginx Config
/etc/nginx/wordpress.conf
##################################
# WORDPRESS NGINX CONFIGURATIONS
##################################
# /etc/nginx/wordpress.conf
#
# Contains a common configuration for use by nginx on a WordPress
# installation. This file should be included in any WordPress site
# nginx virtual host config located in sites-available with the following line:
#
# include /etc/nginx/wordpress.config;
@rheinardkorf
rheinardkorf / quick_image_to_base64.php
Last active February 2, 2022 01:17
Quick and dirty GDImage to Base64 URL.
<?php
function image_to_base64( $image, $type = 'image/jpeg' ) {
// Use new buffer to grab the output.
ob_start();
switch ( $type ) {
case 'image/jpeg':
imagejpeg( $image );
break;
@rheinardkorf
rheinardkorf / acf-hooks.php
Last active October 1, 2021 16:02
Out of the box ACF is taxing on your site performance, but also CPU load if you have large sites (think 10k+ posts). There are ways to improve ACF by doing things like batch writes or pre-fetching values into the ACF Store. As I create some of these techniques I will add them to this Gist. This will work okay'ish without an object cache, but its…
<?php
/**
* This file contains some hooks to improve ACF performance.
*
* @package rheinardkorf
*/
add_filter(
'acf/pre_load_value',
function( $meta, $post_id, $field ) {