Skip to content

Instantly share code, notes, and snippets.

Avatar

Jari Pennanen Ciantic

  • Finland, Jyväskylä
View GitHub Profile
@Ciantic
Ciantic / parse-url-search-params-to-object.js
Last active Sep 30, 2020
Parse url search parameters to object
View parse-url-search-params-to-object.js
Array.from(new URLSearchParams("foo=1&foo=2&foo=3&blah=a&blah=b").entries()).reduce((a,[k,v]) => ({ ...a, [k]: [...a[k] ?? [], v] }), {});
// {foo: ["1","2","3"], blah: ["a","b"]}
// Or directly to string
Array.from(new URLSearchParams("foo=1&foo=2&foo=3&blah=a&blah=b").entries()).reduce((a,[k,v]) => a.has(k) && (a.set(k, a.get(k) + "," + v) ?? a) || (a.set(k, v) ?? a), new URLSearchParams()).toString();
// "foo=1%2C2%2C3&blah=a%2Cb"
@Ciantic
Ciantic / sql-safe-field-names-with-typescript.ts
Last active Sep 15, 2020
Safeish SQL field names with typescript
View sql-safe-field-names-with-typescript.ts
function fields<T>() {
return new Proxy(
{},
{
get: function (_target, prop, _receiver) {
return prop;
},
}
) as {
[P in keyof T]: P;
View comhelpers.rs
use com::{
runtime::{init_apartment, ApartmentType},
sys::CoCreateInstance,
ComInterface, ComPtr, ComRc, CLSID, IID,
};
fn errorhandler<T, F>(f: F, error: HRESULT, retry: u32) -> Result<T, HRESULT>
where
F: Fn() -> Result<T, HRESULT>,
{
@Ciantic
Ciantic / postcsstest.js
Created Jun 20, 2020
Use postcss from deno
View postcsstest.js
import autoprefixer from "https://jspm.dev/autoprefixer";
import postcss from "https://jspm.dev/postcss";
postcss().use(autoprefixer).process(".something { appearance: none; }", {
from: undefined
}).then(f => {
console.log(f.css);
})
@Ciantic
Ciantic / wp-allow-svg.php
Last active Jun 16, 2020
WordPress allow uploading SVG, even without the XML declaration
View wp-allow-svg.php
<?php
// Mind you, this does not make SVG files safe. This script is meant for sites where only trusted people can upload.
add_action("init", function() {
// First line of defence defused
add_filter('upload_mimes', function ($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
});
@Ciantic
Ciantic / preact-custom-element.ts
Last active Jun 14, 2020
This is preact custom element example (incomplete)
View preact-custom-element.ts
import { h, render } from 'preact';
import type { FunctionComponent } from 'preact';
// This makes it recgonized by the JSX parts:
declare global {
namespace preact.createElement.JSX {
interface IntrinsicElements {
'oksidi-sharer': { 'share-url': string; };
}
View tax_query_switch_blog.php
<?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;
View dump-acf-fields-as-json.php
<?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 Apr 9, 2020
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
View Cargo.toml
[package]
name = "yourpackage"
version = "0.1.0"
authors = ["John Doe"]
edition = "2018"
[[bin]]
name = "example"
path = "stream-a-file-using-rust-hyper.rs"
View z-layout.bat
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"
You can’t perform that action at this time.