Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / fetc.sh
Created December 22, 2022 20:54
fetch replies
#!/bin/bash
HEADERS='Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
curl -H "$HEADERS" "https://mastodon.social/users/Gargron/statuses/109543381373981313/replies?only_other_accounts=true&page=true" | jq
@Ciantic
Ciantic / register-reusable-blocks-as-patterns.php
Created September 27, 2022 16:16
Register reusable blocks as patterns
<?php
// Show menu item for reusable blocks
add_action('admin_menu', function () {
add_menu_page(_x('Reusable blocks', 'post type general name'), _x('Reusable blocks', 'post type general name'), 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22);
});
add_action("should_load_remote_block_patterns", function () {
// I chose `should_load_remote_block_patterns` action because it's triggered
@Ciantic
Ciantic / sqlite-worker-query.ts
Created June 26, 2022 22:44
SQLite worker snippet
const worker = new Worker("https://cdn.jsdelivr.net/npm/sql.js@1.7.0/dist/worker.sql-wasm.js");
let rpcid = 0;
async function query(sql: string, params: any, action = "exec") {
const id = rpcid++;
return new Promise<any>((res, rej) => {
const listener = (e: MessageEvent<any>) => {
if (e.data && e.data.id === id) {
worker.removeEventListener("message", listener);
res(e.data);
}
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
use Paytrail\SDK\Client;
use Paytrail\SDK\Exception\HmacException;
use Paytrail\SDK\Exception\ValidationException;
use Paytrail\SDK\Model\Address;
use Paytrail\SDK\Model\CallbackUrl;
use Paytrail\SDK\Model\Customer;
@Ciantic
Ciantic / sqlite3_update_hook.cs
Created February 11, 2022 22:36
This is test code I threw away, it looks like SQLite3 update hook is *per* connection, making it useless for subscribing for events between processes (even if they use same database).
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using SQLitePCL;
static public class Thing {
public static void ListenSqlite(DbContext context)
{
context.Database.OpenConnection();
var c = context.Database.GetDbConnection() as SqliteConnection;
SQLitePCL.raw.sqlite3_update_hook(c.Handle, test_func, new object());
<?php
// Disable article images that come from the content e.g. first <img /> tag
add_filter('the_seo_framework_image_generation_params', function( $params, $args, $context ) {
if (isset( $params['cbs']['content'])) {
unset($params["cbs"]["content"]);
}
return $params;
}, 11, 3);
@Ciantic
Ciantic / intersectionObserverSteps.js
Last active October 30, 2021 14:44
Intersection observer steps
// steps(10) == [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] == length = 11
const steps = (r) => Array(r + 1).fill().map((_, i) => i / r); // with fill
const steps = (r) => ([...Array(r + 1)]).map((_, i) => i / r); // with splat
const steps = (r) => Array.apply(null, Array(r + 1)).map((_, i) => i / r); // If no splat
// Benchmark notes: third implementation fails with maximum stack size, first one is the fastest (with fill)
@Ciantic
Ciantic / offsetRelativeTo.js
Created October 22, 2021 11:15
Get offset relative to selector or window
/**
* Get offset relative to selector (or window)
*
* @param {HTMLElement} el
* @param {string|undefined} selector if not give, assumes root most (window)
*/
function offsetRelativeTo(el, selector) {
let offsetTop = el.offsetTop;
let offsetLeft = el.offsetLeft;
let offsetParent = el.offsetParent;
@Ciantic
Ciantic / createObservableMap.ts
Last active September 19, 2021 18:59
ObservableMap (from MobX) to solidjs (not sure if this is a good idea)
// LICENSE MIT, Jari Pennanen
// For all purposes, I also consider this public domain work.
import { untrack } from "solid-js";
import { createStore } from "solid-js/store";
/**
* Solid JS
*
* @returns Map like observable
@Ciantic
Ciantic / makeObservable.ts
Last active September 18, 2021 10:14
makeObservable (from MobX) to solidjs (not sure if this is a good idea)
import { createSignal, createComputed } from "solid-js";
function createProperty<T, O>(o: O, n: keyof O, def: T) {
const [get, set] = createSignal(def);
Object.defineProperty(o, n, {
get,
set,
});
return def;
}