Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
<?php
// tax_query is not usable in switched blog context:
// https://core.trac.wordpress.org/ticket/32526
switch_to_blog(123);
$taxonomy = "category";
$operator = "in";
$terms = ["news", "blog"];
$tax_query_where = function ($where, $query) use ($terms, $operator, $taxonomy) {
global $wpdb;
<?php
$groups = acf_get_local_field_groups();
$json = [];
foreach ($groups as $group) {
$fields = acf_get_fields($group['key']);
unset($group['ID']);
$group['fields'] = $fields;
$json[] = $group;
}
@Ciantic
Ciantic / Cargo.toml
Last active March 6, 2024 20:05
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
[package]
name = "yourpackage"
version = "0.1.0"
authors = ["John Doe"]
edition = "2018"
[[bin]]
name = "example"
path = "stream-a-file-using-rust-hyper.rs"
rem Run this file as admin on startup using Task Scheduler
imdisk -a -o awe -s 1024M -m Z: -p "/fs:ntfs /q /y"
mkdir "z:\chrome\"
mkdir "z:\chrome\Application Cache\"
mkdir "z:\chrome\blob_storage"
mkdir "z:\chrome\Cache"
mkdir "z:\chrome\GPUCache"
mkdir "z:\chrome\Session Storage"
newtype Maybe' a = Maybe' {getMaybe' :: Maybe a}
deriving Show
-- $setup
-- >>> :set -XScopedTypeVariables
-- >>> :set -XFlexibleContexts
-- >>> import Test.QuickCheck
-- $
-- | Maybe
@Ciantic
Ciantic / job-service-home-wifi.kt
Last active July 13, 2019 17:14
Listen for a home wifi (Android Q)
// Android Q specific way to listen for home wifi
fun jobListenWifiHome(ctx: Context) {
val jobScheduler = getSystemService(ctx, JobScheduler::class.java) ?: return
if (jobScheduler.getPendingJob(6) != null) {
return
}
var netspec = WifiNetworkSpecifier.Builder() // This requires Android Q
.setSsid("your home wifi SSID")
.build()
var req = NetworkRequest.Builder()
@Ciantic
Ciantic / svg-grid.php
Created May 29, 2019 11:52
Just some grid ball animation thing I threw away
<?php
$w = 20;
$h = 3;
$spacing = 7;
$padding = 2;
?>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="<?php echo -$padding; ?> <?php echo -$padding; ?> <?php echo $w * $spacing + $padding * 2; ?> <?php echo $h * $spacing + $padding * 2; ?>"
version="1.1">
@Ciantic
Ciantic / sqlite.rowvalues.tests.ts
Created May 9, 2019 07:48
SQLite Row values does not seem to work, my test case
import sqlite3 from "sqlite3";
let db: any;
beforeEach(done => {
db = new sqlite3.Database(":memory:", () => {
db.run("CREATE TABLE foo (a INT, b INT)", done);
});
});
@Ciantic
Ciantic / sqlite-uses-gettime.test.ts
Created April 24, 2019 09:12
node sqlite3 uses getTime (unixepoch as milliseconds) for default date to integer conversion
import sqlite3 from "sqlite3";
let db: any;
beforeEach(done => {
db = new sqlite3.Database(":memory:", () => {
db.run("CREATE TABLE foo (num INT)", done);
});
});
@Ciantic
Ciantic / example-typeorm-jest.test.ts
Created April 16, 2019 17:50
Example of testing TypeOrm with Jest and Sqlite in-memory database
import { createConnection, getConnection, Entity, getRepository } from "typeorm";
import { PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id?: number;
@Column()
name?: string;