Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / parse-postgresql-to-typescript.ts
Last active July 6, 2025 10:04
Parse PostgreSQL schema, and output types
import { deparse, parse } from "npm:pgsql-parser";
import type { Node, ParseResult } from "npm:@pgsql/types";
const schemaSql = `
-- PostgreSQL schema
CREATE TYPE my_enum_example AS ENUM ('good', 'bad', 'ugly', 'dont know');
CREATE TABLE
"various_types" (
"bigserial" bigserial primary key,
@Ciantic
Ciantic / stop-asus.ps1
Last active June 24, 2025 10:00
Stop ASUS services automatically
# EDIT: There is more comprehensive debloat instructions here: https://github.com/sammilucia/ASUS-G14-Debloating/blob/main/README.md
# Get services starting with "Asus*" to a variable
$services = Get-Service -Name "Asus*"
# Stop services
foreach ($service in $services) {
# Print service
Write-Host "STOP" $service.Name
Stop-Service -Name $service.Name
@Ciantic
Ciantic / pglite-kysely-driver-simple.ts
Last active March 1, 2025 19:31
Simple PGLite kysely driver
import * as k from "npm:kysely";
import { PGlite } from "npm:@electric-sql/pglite";
function createPgLiteDialect(db: PGlite) {
return {
createDriver: () =>
({
acquireConnection: () => {
return Promise.resolve({
executeQuery: async (compiledQuery) => {
@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 November 11, 2024 17:02
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();
}
}
}