View sqlite-worker-query.ts
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
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); | |
} |
View paytrail-example-without-nonsense.php
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 | |
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; |
View sqlite3_update_hook.cs
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
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()); |
View seo-framework-disable-content-image.php
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 | |
// 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); |
View intersectionObserverSteps.js
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
// 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) |
View offsetRelativeTo.js
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
/** | |
* 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; |
View createObservableMap.ts
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
// 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 |
View makeObservable.ts
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 { 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; | |
} |
View tuple_layout.rs
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) )}; |
View build.rs
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()); |
NewerOlder