Skip to content

Instantly share code, notes, and snippets.

View jasalt's full-sized avatar

Jarkko Saltiola jasalt

View GitHub Profile
#!/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 / odoo.phel
Created February 8, 2025 08:06
Phel Odoo XMLRPC wrapper
(ns woodoo-pos-sync\lib\odoo
(:require phel\str :as str)
(:require woodoo-pos-sync\lib\wp :as wp)
(:use \Laminas\XmlRpc\Client))
### Wrapper for Laminas XMLRPC library and Odoo XMLRPC-API
## Docs:
## - https://docs.laminas.dev/laminas-xmlrpc/client/
## - https://www.odoo.com/documentation/18.0/developer/reference/external_api.html
@jasalt
jasalt / validation-demo.phel
Last active January 12, 2025 09:01
Phel validation example
# Option map validation taking some inspiration from https://github.com/babashka/cli
# Validates opts map given in following format:
(comment
{:pdo-conn
{:require true # this should be set
:validate 'pdo/connection? # function used for validation, quoted so it's definition can be printed on failure
:default |(wp/pdo-get-connection)} # default value used by set-missing-opts-to-defaults, returns pdo connection using WPDB connection info
:excluded-barcode-prefixes
@jasalt
jasalt / utilities.phel
Created January 11, 2025 10:55
Phel numeric parsing utilities
# Attempt to fix some surprising PHP behavior inconsistent with Java (Clojure),
# for some basic use cases only.
(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 / 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 January 22, 2025 10:13
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 January 22, 2025 10: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)