Skip to content

Instantly share code, notes, and snippets.

Avatar

Jari Pennanen Ciantic

  • Finland, Jyväskylä
View GitHub Profile
@Ciantic
Ciantic / example-typeorm-jest.test.ts
Created Apr 16, 2019
Example of testing TypeOrm with Jest and Sqlite in-memory database
View example-typeorm-jest.test.ts
import { createConnection, getConnection, Entity, getRepository } from "typeorm";
import { PrimaryGeneratedColumn, Column } from "typeorm";
@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id?: number;
@Column()
name?: string;
@Ciantic
Ciantic / dirname-filename-basename.bat
Created Apr 1, 2016
How to get filename, dirname, and basename in bat?
View dirname-filename-basename.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 May 1, 2022
This example shows how to stream a file or shell execution stdout using Hyper and Futures (Rust)
View Cargo.toml
[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 / run-powershell-command-once-scheduled.ps1
Last active Apr 5, 2022
Run powershell command only once, scheduled
View run-powershell-command-once-scheduled.ps1
$t = New-ScheduledTaskTrigger -Once -At (get-date).AddSeconds(10); $t.EndBoundary = (get-date).AddSeconds(60).ToString('s'); Register-ScheduledTask -Force -TaskName JustTrying -Action (New-ScheduledTaskAction -Execute "powershell.exe" -Argument '-NoProfile -WindowStyle Hidden -command "& {dir}"') -Trigger $t -Settings (New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter 00:00:01)
View paytrail-example-without-nonsense.php
<?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;
@Ciantic
Ciantic / sqlite3_update_hook.cs
Created Feb 11, 2022
This is test code I threw away, it looks like SQLite3 update hook is *per* connection, making it useless for subscribing for events between processes (even if they use same database).
View sqlite3_update_hook.cs
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());
@Ciantic
Ciantic / cloudflare-dyndns-a-aaaa-record-update.sh
Last active Feb 7, 2022
cloudflare dyndns script / update a A and AAAA record using bash script
View cloudflare-dyndns-a-aaaa-record-update.sh
#!/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
View seo-framework-disable-content-image.php
<?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 keyboardlistener.cs
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
{
View YAML-to-JSON-with-Rust.rs
// 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: