This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Yaml to JSON with Rust | |
| // Dependencies serde_yaml and serde_json | |
| // https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3ddd4d9a65f03b717eeb1258299e9503 | |
| fn main() { | |
| let json_value: serde_json::Value = serde_yaml::from_str(&" | |
| --- | |
| test: some value here | |
| another: value here | |
| third: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fields<T>() { | |
| return new Proxy( | |
| {}, | |
| { | |
| get: function (_target, prop, _receiver) { | |
| return prop; | |
| }, | |
| } | |
| ) as { | |
| [P in keyof T]: P; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [package] | |
| name = "yourpackage" | |
| version = "0.1.0" | |
| authors = ["John Doe"] | |
| edition = "2018" | |
| [[bin]] | |
| name = "example" | |
| path = "stream-a-file-using-rust-hyper.rs" |