Skip to content

Instantly share code, notes, and snippets.

View rheinardkorf's full-sized avatar

Rheinard Korf rheinardkorf

View GitHub Profile
@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 / 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 / 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 / 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 / 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-basic.php
Created May 26, 2021 14:26
acf-hooks-basic.php
<?php
/**
* Hook before acf_get_value() queries the DB.
*/
add_filter(
'acf/pre_load_value',
function( $meta, $object_id, $field ) {
// Initiate the ACF 'values' store.
@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 ) {
@rheinardkorf
rheinardkorf / queries.mysql
Created December 7, 2020 12:01
Useful SQL queries for dealing with WordPress optimizations.
# Get a particular option entry.
SELECT * FROM wp_options WHERE option_name="<OPTION_NAME>" LIMIT 1000;
# Make sure an option to not autoloaded.
UPDATE wp_options SET autoload = 'no' WHERE option_name="<OPTION_NAME>";
# Get the size of total autoladed values.
SELECT SUM(LENGTH(option_value)) as autoload_size FROM wp_options WHERE autoload='yes';
# Get the top 10 most "expensive" autoloaded values.
@rheinardkorf
rheinardkorf / cache-example.php
Last active December 7, 2020 11:32
Example using WP caching.
<?php
// This example assumes an object cache is available. If its not, transients WITHOUT EXPIRATION will be used.
$cache_key = 'unique_prefix_' . md5( $variables );
$results = wp_cache_get( $cache_key );
if ( false === $results ) {
$results = $wpdb->get_var( $wpdb->prepare("SQL STATEMENT HERE", $variables['here'], $variables['etc'] ));
wp_cache_set( $cache_key, $results );
}
@rheinardkorf
rheinardkorf / .mermaidrc
Last active September 22, 2020 06:04
Alternate Remark-Mermaid Plugin
{
"sequence":{
"diagramMarginY" :10,
"diagramMarginX" :50,
"actorMargin" :50,
"width" :150,
"height" :65,
"boxMargin" :10,
"boxTextMargin" :5,
"noteMargin" :10,