Skip to content

Instantly share code, notes, and snippets.

View JustSlavic's full-sized avatar
😪
Focusing

Slavic JustSlavic

😪
Focusing
View GitHub Profile
@JustSlavic
JustSlavic / main.cpp
Created December 19, 2019 09:09
Getting frequencies of words (ASCII)
#include <iostream>
#include <fstream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
class dictionary {
public:
using value_t = std::pair<std::string, size_t>;
#include <iostream>
#include <fstream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <map>
class Dictionary {
public:
@JustSlavic
JustSlavic / README.md
Last active December 19, 2022 09:17
How to start a C program without CRT on 32bit ARM Linux

Start your C program without CRT on 32bit ARM Linux

Preamble

I always wanted to go deeper into programming, so when my neighbour showed me theirs RaspberryPi I immediately asked them to borrow it. At that time I felt urge to program really bad, because I was left without my computer, and RaspberryPi turned really handy!

I jumped into it right away and started to learn ARM assembly. I wanted to run my program without C runtime library. While searching the Internet how to do that, I found that there are not so many resources where one could learn what such process looks like, so I want to share what I found when did that.

Data oriented UI (part 1)

Some time ago I read the @lisyarus' post about his UI library. In his blog post he compares existing UI frameworks, analyses reasons why they don't work to them, and shows how he created his own library to build in-game UI.

His blog post immediately inspired me: how would I build my UI library?

Data Oriented Design vs OOP?

Data oriented UI (part 2)

Last time (Part 1) I finished by drawing a couple of rectangles on the screen. But I missed the bug, so let's fix it. Let's have a look at the code below, can you spot it?

void draw(system *s)
{
    // ...

Data oriented input in games

Many game engines implement inputs in a more OOP style: you have an object, that represents an input device, and you can query its state. Something like this:

class input_device {};

class mouse : public input_device
{

Data oriented UI (part 3)

In the previous part (Part 2) I created hover and click behaviours, so we could make buttons or just any hover elements. But how to use them in the game? I don't want to store a pointer to the button. UI library could reorder elements or delete them as it wishes, I don't want this hard constraint, especially with no way to check is my pointer valid or not.

Accessing elements in the game code

Introducing ui::handle

@JustSlavic
JustSlavic / README.md
Last active December 28, 2023 20:39
Introduction to the geometric algebra for my 'based' library

Disclaimer: this is not a textbook, this is just a short explanation, so you can use this library

Geometric algebra in 2D

Let's say we have a 2d-vector:

$$ v = (v_1, v_2) $$

Previous part: Geometric algebra in 2D and 3D

Disclaimer: there will be NO proofs or rigorous explanations here, just some results and notes on how to use the library

Projective geometric algebra in 2D

Lines

We start with lines. As you can remember, the equation for a line in 2D looks like this:

@JustSlavic
JustSlavic / alice.c
Created January 14, 2024 18:53
Example of using shared memory for interprocess communication (a dialogue between Alice and Bob)
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <semaphore.h>
#include <unistd.h>
#include <sys/types.h>