Skip to content

Instantly share code, notes, and snippets.

View boki1's full-sized avatar
🧐

Kristiyan Stoimenov boki1

🧐
View GitHub Profile
@boki1
boki1 / container_of.c
Created August 27, 2021 10:18
Trying out container_of macro
#include <stdio.h>
struct inner { };
struct outer {
int a;
char b;
float c;
struct inner obj;
char asdf[];
@boki1
boki1 / concepts_try_out.cpp
Created July 8, 2021 09:28
Concepts require iterator/range inside
#include <type_traits>
#include <thread>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <concepts>
#include <variant>
#include <iostream>
#include <iterator>
@boki1
boki1 / avl.c
Created July 6, 2021 16:41
AVL
#include<stdio.h>
#include<stdlib.h>
struct node {
int key;
struct node *left;
struct node *right;
int height;
};
@boki1
boki1 / int_mutability.rs
Created December 28, 2020 21:41
Interior Mutability Design Pattern - Rust
use std::rc::Rc;
use std::cell::RefCell;
trait Component {
fn attach_to(&mut self, container: Rc<RefCell<Outer>>);
}
#[derive(Debug)]
struct Inner {
@boki1
boki1 / merge_sort.py
Created September 30, 2020 13:41
Python HW - Merge sort
from random import randint
def string_compare(s1, s2):
rv = len(s1) - len(s2)
# print(f'values: ({s1}, {s2}); {s1} > {s2} ? {rv}')
if rv > 0:
return 1
elif rv < 0:
return -1
else:
@boki1
boki1 / dynamic-linkage_Class.h
Last active August 31, 2020 15:53
OOP w/ ANSI C: Chapter 2 - Dynamic Linkage
//
// Created by boki on 8/31/20.
//
#ifndef _CLASS_H_
#define _CLASS_H_
#include <stdlib.h>
struct Class
@boki1
boki1 / fraction.c
Created June 18, 2019 18:47
Fraction class
#include <iostream>
#include "fraction.h"
namespace num
{
fraction::fraction(int n, int d) : nom(n), denom(d) { (*this).shorten(); }
fraction::fraction(const fraction &f) : denom(f.denom), nom(f.nom) {}
#include <iostream>
#include <fstream>
using std::string;
#define MARKS_COUNT 5
struct student
{
student(unsigned, string, int *);
@boki1
boki1 / date.cpp
Last active June 1, 2019 14:56
Implementation of struct date
#include <iostream>
using std::ostream, std::cout;
#include "date.h"
namespace ttime
{
date::date() : day(1), month(jan), year(1970)
{
@boki1
boki1 / str.cpp
Last active June 21, 2019 12:03
Implement string class
#include <iostream>
#include <cstring>
#include "str.h"
namespace str {
str::str() : buffer(0) {}
str::~str() { delete[] this->buffer; }