Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / keyboardlistener.cs
Created July 11, 2010 17:33
C# Keyboard listener
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Threading;
using System.Collections.Generic;
namespace Ownskit.Utils
{
@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 / ModelStateValidationFilter.cs
Created April 21, 2016 06:19
Model state validation filter ASP.NET Core
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Example
{
public class ModelStateValidationFilter : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
@Ciantic
Ciantic / dirname-filename-basename.bat
Created April 1, 2016 15:11
How to get filename, dirname, and basename in bat?
set filepath="C:\some path\having spaces.txt"
for /F "delims=" %%i in (%filepath%) do set dirname="%%~dpi"
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"
echo %dirname%
echo %filename%
echo %basename%
@Ciantic
Ciantic / Cargo.toml
Last active March 6, 2024 20:05
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
[package]
name = "yourpackage"
version = "0.1.0"
authors = ["John Doe"]
edition = "2018"
[[bin]]
name = "example"
path = "stream-a-file-using-rust-hyper.rs"
@Ciantic
Ciantic / cloudflare-dyndns-a-aaaa-record-update.sh
Last active January 2, 2024 22:00
cloudflare dyndns script / update a A and AAAA record using bash script
#!/bin/bash
# Author: Jari Pennanen
# Url: https://gist.github.com/Ciantic/4e543f2d878a87a38c25032d5c727bf2
AUTH_EMAIL="john.doe@example.com" # Your Cloudflare email
AUTH_KEY="" # Get this from My profile -> API Keys -> View
DOMAIN="example.com" # main domain
SUBDOMAIN="home.example.com" # set A and AAAA-record of this subdomain
@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 / 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 / example-typeorm-jest.test.ts
Created April 16, 2019 17:50
Example of testing TypeOrm with Jest and Sqlite in-memory database
import { createConnection, getConnection, Entity, getRepository } from "typeorm";
import { PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id?: number;
@Column()
name?: string;
@Ciantic
Ciantic / build.rs
Created February 25, 2021 17:50
Some in-memory stuff I threw away
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());