Skip to content

Instantly share code, notes, and snippets.

View jasalt's full-sized avatar
💼
Available for contract work

Jarkko Saltiola jasalt

💼
Available for contract work
View GitHub Profile

+++ title = "API" weight = 110 template = "page-api.html" aliases = [ "/api" ] +++

{{ api_listing_entry(fn_name="decode", namespace="base64", doc="```phel (decode s & [strict?])

@jasalt
jasalt / bindings.php
Created August 15, 2025 15:23
Block binding example for twig-templating block
<?php
// Example for https://github.com/jasalt/twig-templating-block (2025-08-15 714be3a)
// Example template
// <div class="favourited-videos {{ editor_classes }}">
// {% if videos %}
// {% for video in videos %}
// {{ include_template_part('cpt-video-card', video.id) }}
// {% endfor %}
@jasalt
jasalt / vendor_to_json.php
Created May 16, 2025 04:57
Convert Composer `vendor` dir to JSON object that can be preloaded with PHP-WASM
#!/usr/bin/env php
<?php
// PHP script `vendor-to-json` that is run on composer project root and traverses through folders in `./vendor/` storing each file handle into nested associative array in format required by PHP-WASM files constructor parameter (and data-files attribute). Ignores folders.
// As of 2025-05-16 requires modified PhpBase.js with support to create missing dirs (Draft PR https://github.com/seanmorris/php-wasm/pull/82)
// Usage:
// ./vendor-to-json.php [prefix]
//
// Parameters:
#!/bin/bash
input_image="full.jpg"
output_prefix="part_"
max_width=3840
max_height=2160
aspect_ratio=$(bc -l <<< "$max_width / $max_height")
# Get image dimensions
dimensions=$(identify -ping -format "%w %h" "$input_image")
@jasalt
jasalt / phel-cider-light.el
Last active February 6, 2025 08:13
"Phel Cider Light" Phel programming config preview
;; "Phel Cider Light" Phel-lang programming config
;; Stand-alone preview version separated from from personal .emacs.d
;; https://github.com/jasalt/.emacs.d/blob/007083f149cf3954a6f38328c962c6788e179705/personal/phel.el#L1
;; Written during two days during winter cold largely with Claude Sonnet 3.5 LLM
;; and gptel.el. While surprisingly good experience for a quick proof of concept,
;; may come with hidden defects that need to be smoothed out by hand during use.
;; Attempts to emulate some useful Clojure and Elisp editing functionalities
@jasalt
jasalt / wp.phel
Last active August 27, 2025 15:15
wp.phel
### Phel wrapping over WP / PHP API's
## TODO make a library some day..
(ns my-project\lib\wp
(:require phel\str :as str)
(:require phel\pdo :as pdo)
(:require phel\pdo\statement :as statement))
## Initialize WordPress plugin environment for REPL / tests
(defn resolve-wp-load-path
@jasalt
jasalt / utils.phel
Last active August 27, 2025 15:15
utils.phel
# Some Phel utility fns / macros
(ns my-project\utils)
(defn parse-float
"Converts to float without doing odd type conversions, acting more like
Float/parseFloat in Clojure."
[x]
(when-not (php/is_numeric x)
(throw (php/new \InvalidArgumentException
(str "Invalid value for parse-float (" x ")"))))
@jasalt
jasalt / blender_nrepl.py
Created November 11, 2024 08:59
Hacky blender basilisp nrepl
# by Simo / maqq
# tl;dr; don't use this but see https://github.com/ikappaki/basilisp-blender
import bpy
import uuid
import traceback
from basilisp import main as basilisp, cli
from basilisp.lang import compiler, runtime
from collections import OrderedDict
import socket
@jasalt
jasalt / link_post_translation.php
Created August 26, 2024 13:10 — forked from djoo/link_post_translation.php
WPML Custom end point link 2 existing translation
<?php
/**
* Link the FR translation and the EN translation
* Called by API https://domain.com/wp-json/link_translation/post/
*/
function custom_rest_link_translation($data) {
//Source https://wpml.org/wpml-hook/wpml_set_element_language_details/
@jasalt
jasalt / ssh_ngrok
Created January 3, 2024 13:40
SSH straight to server behind dynamic NGROK address/port using new NGROK API
#!/usr/bin/env bash
# Connect to a dynamic NGROK endpoint that changes ofter after server restart etc.
# Works with single active tunnel (per account) on free tier.
# Provides persistent or dedicated endpoint like premium experience.
# Requires environment variable $NGROK_APIKEY
NGROK_ENDPOINT=$(curl -s https://api.ngrok.com/tunnels -H "authorization: Bearer $NGROK_APIKEY" -H "ngrok-version: 2" | jq -r '.tunnels[0].public_url')
NGROK_HOST=$(echo "$NGROK_ENDPOINT" | cut -d':' -f2 | cut -d'/' -f3)