Skip to content

Instantly share code, notes, and snippets.

View Luna-Klatzer's full-sized avatar
🏳️‍⚧️
Cherish growth ~ she/her

Luna Luna-Klatzer

🏳️‍⚧️
Cherish growth ~ she/her
View GitHub Profile
@Luna-Klatzer
Luna-Klatzer / kipper-scheme-typing.ts
Created October 22, 2023 14:59
An attempt at developing a type that can infer the correct keys/value types for an interface based on a given schema.
/**
* The validation scheme for an option that is an object.
* @since 0.11.0
*/
export type KipperConfigObjectValidatorScheme = {
[key: string]: "string" | "boolean" | "array<string>" | KipperConfigObjectValidatorScheme;
}
/**
* The validation scheme for the Kipper config.
@Luna-Klatzer
Luna-Klatzer / is-prime.kip
Last active September 9, 2024 12:02
Simple Kipper program to check if a number is prime
def isPrime(n: num) -> bool {
if (n <= 1) {
return false; // Never a prime
} else if (n == 2 || n == 3) {
return true; // Base primes
} else if (n % 2 == 0 || n % 3 == 0) {
return false; // Easy base prime checks
}
for (var i: num = 5; i * i <= n; i += 6) {
@Luna-Klatzer
Luna-Klatzer / prime-factors.kip
Last active February 10, 2024 13:21
Simple Kipper program to get the prime factors of a number
def primeFactors(n: num) -> void {
while (n % 2 == 0) {
print("2");
n /= 2;
}
// For all non-even divisors
for (var i: num = 3; i * i <= n; i += 2) {
while (n % i == 0) {
print(f"{i}");
@Luna-Klatzer
Luna-Klatzer / pow.kip
Created June 26, 2023 13:59
Simple Kipper program to calculate the power-to of two numbers
def pow(base: num, powerTo: num) -> num {
return base ** powerTo;
}
var result: num = pow(2, 8); // -> 256
print(result as str);
@Luna-Klatzer
Luna-Klatzer / add.kip
Last active June 26, 2023 14:01
Simple Kipper program to add numbers
def add(firstNum: num, secondNum: num) -> num {
return firstNum + secondNum;
}
var result: num = add(1, 2);
print(result as str);
@Luna-Klatzer
Luna-Klatzer / __init__.py
Last active February 18, 2024 14:33
Anki Plugin for auto-filling data in Anki cards using the Jisho.org API
# Jisho.org Support for Anki
import os, re, json, requests, urllib.request, urllib.parse
from aqt import gui_hooks
from aqt import mw
from aqt.qt import qconnect
from aqt.editor import Editor
from aqt.utils import showInfo
from anki.utils import stripHTML
@Luna-Klatzer
Luna-Klatzer / kipper-benchmark-sample.kip
Last active November 14, 2022 00:05
Sample script for a quick benchmark of parse and compile time of the Kipper Compiler v0.10.0-alpha.5
var x: num = 5;
def incr(val: num) -> void { x += val; }
def prn(val: num) -> void { print(val as str); }
/* Increment and print */
incr(5);
prn(x);
/* Increment and print */
@Luna-Klatzer
Luna-Klatzer / runtime-types-proof-of-concept.js
Last active December 9, 2022 21:52
Runtime-types proof of concept for Kipper. This shows the possible implementation of runtime types, where you will be able to check the types against constant type identifiers and will be able to perform checks using the `match` operator.
/**
* Sample Script for showing the core functionality of how runtime types should work in Kipper.
*/
"use strict";
// @ts-ignore
var __kipperGlobalScope = typeof __kipperGlobalScope !== "undefined" ? __kipperGlobalScope : typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
// @ts-ignore
var __kipper = __kipperGlobalScope.__kipper = __kipperGlobalScope.__kipper || __kipper || {};
// The parent of all Kipper runtime types
@Luna-Klatzer
Luna-Klatzer / build-dotjs-templates.ts
Last active June 27, 2022 19:12
Simple script for buidling dot.js template files (`.jst`) and generating the js template functions.
import * as dot from 'dot';
import * as fs from "fs";
import * as rimraf from 'rimraf';
const source: string = `${__dirname }/templates`;
const destination: string = `${__dirname}/dot-build`;
// Generate destination files from source template files
(async () => {
// If the destination folder exists, remove it to ensure it does not contain old files
@Luna-Klatzer
Luna-Klatzer / kipper-modules-proof-of-concept.ts
Last active June 21, 2022 09:39
Simple proof of concept for a possible implementation modules in Kipper, which would be usable in a Web API that supports running Kipper files like in the WASM API.
// --------------------------------
// file1.ts
// --------------------------------
// Kipper Built-ins
function __print__(msg: string): void { console.log(msg); }
// Import other Kipper modules
import * as __file2__ from "./file2";