Skip to content

Instantly share code, notes, and snippets.

View spytheman's full-sized avatar
🏠
Working from home

Delyan Angelov spytheman

🏠
Working from home
View GitHub Profile
@spytheman
spytheman / encode_and_decode_using_mbedtls_pk.v
Created February 5, 2024 19:38
Encoding and Decoding data with RSA keys, using Vlang's net.mbedtls wrapper
import os
import net.mbedtls
const x = mbedtls.is_used // just silence a V warning, since we are using only the C functions from net.mbedtls, but not any pub V fn etc
type FnRNG = fn(p_rng voidptr, output &u8, output_len usize) int
fn C.mbedtls_pk_parse_public_keyfile(pk &C.mbedtls_pk_context, path &u8) int
fn C.mbedtls_pk_encrypt(pk &C.mbedtls_pk_context, const_input &u8, ilen usize, output &u8, olen &usize, osize usize, f_rng FnRNG, p_rng voidptr) int
fn C.mbedtls_pk_decrypt(pk &C.mbedtls_pk_context, const_input &u8, ilen usize, output &u8, olen &usize, osize usize, f_rng FnRNG, p_rng voidptr) int
@spytheman
spytheman / input_windows.v
Created March 19, 2023 16:39
Example of declaring C.INPUT that uses an anonymous union inside, by just ignoring it.
#include <windows.h>
[typedef]
struct C.MOUSEINPUT {
dx i64
dy i64
mouseData u32
dwFlags u32
time u32
dwExtraInfo &u64 = unsafe { nil }
@spytheman
spytheman / wordle.v
Created March 18, 2023 15:37
wordle in V, optimised to not use ascii_str() all the time
import json
import os
import time
import math
import runtime
fn main() {
println('Started...')
sw := time.new_stopwatch()
content := os.read_file('./wordle_min.json')!
@spytheman
spytheman / matmul_without_libnotify.c
Created December 21, 2022 07:57
matmul.c , with libnotify usages removed
// Writen by Attractive Chaos; distributed under the MIT license
// This is a modifed copy of https://raw.githubusercontent.com/kostya/benchmarks/master/matmul/matmul.c , with libnotify usages removed
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __clang__
#define COMPILER "clang"
#else
#define COMPILER "gcc"
@spytheman
spytheman / all_paths_in_graph.v
Created September 23, 2022 17:47
Find all paths in graph, given by task ids.
import os
import time
struct Seeker {
mut:
graph map[int][]int
already_found map[int][][]int
all_solutions [][]int
}
module main
#define SOKOL_IMPL
#define SOKOL_GLCORE33
#flag -I @VMODROOT
#flag -lX11 -lGL -lXcursor -lXi -lpthread
#flag -lm
#include "thirdparty/sokol_gfx.h"
@spytheman
spytheman / starfield_cpp_main.cpp
Created August 24, 2022 20:29
A small SDL start field example.
#include <iostream>
#include <stdlib.h>
#include <SDL.h>
#include <experimental/random>
#include <vector>
const int WIDTH = 1360, HEIGHT = 760;
const int H_WIDTH = WIDTH / 2;
const int H_HEIGHT = HEIGHT / 2;
const int STARS_COUNT = 5000;
@spytheman
spytheman / cjson_encode_data_with_null.v
Created July 20, 2022 18:37
How to encode a JSON result, that has null for some of the fields.
module main
import json
pub type Node = C.cJSON
struct UseJson {
x int
}
import time
type Task = fn (data voidptr)
pub fn (t Task) str() string {
return 'Task{ ${ptr_str(t)} }'
}
fn task_default(data voidptr) {
// println('task_default: $data')
module main
import gg
import gx
struct App {
mut:
gg &gg.Context = 0
radius f64 = 10.0
}