This file contains 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
#[repr(C)] | |
struct Foo(f32, f32, f32); | |
fn main() { | |
let a = [Foo(1.0,2.0,3.0), Foo(4.0,5.0,6.0)]; | |
let b = [1.0f32,2.0,3.0,4.0,5.0,6.0]; | |
let c = [(1.0f32,2.0f32,3.0f32), (4.0f32,5.0f32,6.0f32)]; | |
let amem = unsafe { std::slice::from_raw_parts((&a as *const _) as *const u8, std::mem::size_of_val(&a) )}; | |
let bmem = unsafe { std::slice::from_raw_parts((&b as *const _) as *const u8, std::mem::size_of_val(&b) )}; | |
let cmem = unsafe { std::slice::from_raw_parts((&c as *const _) as *const u8, std::mem::size_of_val(&c) )}; |
This file contains 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 std::io::Write; | |
use std::{env, path::Path}; | |
use std::{fs::OpenOptions, path::PathBuf}; | |
use regex::Regex; | |
fn main() { | |
let dir = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("lib"); | |
println!("cargo:rustc-link-search=native={}", dir.display()); |
This file contains 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
//! Convenience wrappers for Direct2D objects. | |
//! | |
//! These also function as safety boundaries (though determining the | |
//! exact safety guarantees is work in progress). | |
// TODO: get rid of this when we actually do use everything | |
#![allow(unused)] | |
use std::ffi::c_void; | |
use std::fmt::{Debug, Display, Formatter}; |
This file contains 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 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 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 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 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 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 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; }; | |
} |