Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / deno-example.ts
Created April 14, 2024 21:43
Deno example of mmomtchev/sqlite-wasm-http
import { createSQLiteThread, createHttpBackend } from "npm:sqlite-wasm-http";
// This is required hack:
const OldWorker = globalThis.Worker;
// @ts-ignore: Default to module workers
globalThis.Worker = class {
constructor(url: URL, opts: any = {}) {
return new OldWorker(url, { type: "module", ...opts });
}
};
@Ciantic
Ciantic / nodejs-postgresql-timestamp.js
Created October 12, 2023 10:28
nodejs-postgresql-timestamp.js
const pool = new Pool({
max: 300,
connectionTimeoutMillis: 20000,
host: "127.0.0.1",
port: 5432,
user: 'citus',
password: () => "password",
database: 'citus',
ssl: false,
@Ciantic
Ciantic / sqlite3.html
Last active July 1, 2023 22:37
Example how to use official SQLite3 WASM with ESM modules
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
LOOK AT THE CONSOLE
// @deno-types="npm:@types/sql.js"
import { default as initSqlJs } from "npm:sql.js";
import { IDatabase, QueryResult } from "./Database.ts";
export class Database implements IDatabase {
private path: string;
private sqliteJs?: initSqlJs.SqlJsStatic;
private db?: initSqlJs.Database;
private inited = false;
@Ciantic
Ciantic / shortcode2.php
Last active October 10, 2023 10:52
Temporary shortcode block, when WordPress had a bug
<?php
add_action("init", function () {
// Ob_start twice, intentionally
ob_start();
?>
<script type="module">
<?php ob_start(); ?>
wp.blocks.registerBlockType("temp/shortcode", {
@Ciantic
Ciantic / hhook.rs
Created March 23, 2023 22:57
Just code I haven't used yet
use std::sync::mpsc::Sender;
use windows::{
core::Result,
s,
Win32::{
Foundation::{HANDLE, HWND, LPARAM, LRESULT, WPARAM},
System::{
LibraryLoader::GetModuleHandleA,
Power::{
@Ciantic
Ciantic / this-panics.rs
Last active February 23, 2023 21:13
Why this panics? "fatal runtime error: thread local panicked on drop"
struct MyThreadWrapper {
thread: Option<std::thread::JoinHandle<()>>,
}
impl Drop for MyThreadWrapper {
fn drop(&mut self) {
if let Some(thread) = self.thread.take() {
let _ = thread.join();
}
}
}
@Ciantic
Ciantic / windows_thread.rs
Created February 18, 2023 00:01
Just simple CreateThread example with proper way to QUIT.
use windows::{
core::{GUID, HSTRING},
Win32::{
Foundation::HWND,
System::{
Com::{CoInitializeEx, COINIT_APARTMENTTHREADED},
Threading::{
CreateThread, GetCurrentThreadId, WaitForSingleObject, THREAD_CREATION_FLAGS,
},
},
@Ciantic
Ciantic / hstring.rs
Created February 17, 2023 23:47
Dependency free HSTRING implementation for Rust
// Dependency free HSTRING implementation
use std::ffi::OsStr;
use std::ffi::{c_void, OsString};
use std::os::windows::ffi::OsStrExt;
use std::os::windows::ffi::OsStringExt;
type LPCWSTR = *const u16;
type HRESULT = i32;
@Ciantic
Ciantic / python-like-decorators-currying-in-rust.rs
Created February 11, 2023 17:05
Two examples: How to decorate (curry) a function and how to curry a method in Rust
// Cargo.toml
//
// [dependencies]
// macro_rules_attribute = "0.1"
#[macro_use]
extern crate macro_rules_attribute;
// How to decorate a function