Skip to content

Instantly share code, notes, and snippets.

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

kioba kioba

🏠
Working from home
View GitHub Profile
@kioba
kioba / MinStack.kt
Last active October 6, 2020 22:22
MinStack.kt
package dev.kioba.minstack
sealed class MinStack<out A> {
companion object
}
object Nil : MinStack<Nothing>()
class Cons<A>(val head: A, val min: A, val tail: MinStack<A> = Nil) : MinStack<A>()
operator fun <A> MinStack.Companion.invoke(): MinStack<A> = Nil
@kioba
kioba / .zshrc
Last active July 9, 2023 11:32
zshrc config
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
export ZSH=$HOME/.oh-my-zsh
# ZSH_THEME="powerlevel10k/powerlevel10k"
package kioba.dev
sealed class Tree<T>
data class Leaf<T>(val value: T) : Tree<T>()
data class Node<T>(val left: Tree<T>, val right: Tree<T>) : Tree<T>()
fun <T> numberOfLeafs(tree: Tree<T>): Int = when (tree) {
is Leaf -> 1
is Node -> numberOfLeafs(tree.left) + numberOfLeafs(tree.right)
}
@kioba
kioba / List.kt
Created September 1, 2019 13:06
Recursive ADT
package dev.kioba.ilist
sealed class IList<A>
class INil<A> : IList<A>()
class ICons<A>(val head: A, val tail: IList<A>) : IList<A>()
fun <A> iListOf(vararg arg: A): IList<A> =
arg.foldRight<A, IList<A>>(INil()) { element, acc -> ICons(element, acc) }
fun <A> IList<A>.forEach(f: (A) -> Unit): Unit =
@kioba
kioba / main.kt
Created September 21, 2018 15:18
Sample code for architecture challenge
fun main(args: Array<String>) {
println("what is your name?")
val name = readLine()
println("Hello $name welcome to the ArrowGame!")
var exec = true
#include <stdio.h>
#include <memory>
class Base
{
public:
virtual void print() {
printf("Base");
}
};
@kioba
kioba / main.cpp
Created January 28, 2016 12:09
infinite loop?
int main() {
int x = 0;
while (x < 5) {
x = x++;
}
return 0;
}
@kioba
kioba / shared_ptr_bool.cpp
Created November 30, 2015 16:23
Is it true or false?
#include <iostream>
#include <memory>
int main()
{
std::shared_ptr<bool> boolean(new bool(false));
if (boolean) {
std::cout << "True" << std::endl;
} else {
@kioba
kioba / glmvec4.cpp
Created November 17, 2015 23:02
GLM::vec4 union names
# if(GLM_COMPONENT == GLM_COMPONENT_ONLY_XYZW)
value_type x, y, z, w;
# elif(GLM_COMPONENT == GLM_COMPONENT_MS_EXT)
union
{
struct{value_type x, y, z, w;};
struct{value_type r, g, b, a;};
struct{value_type s, t, p, q;};
};
# else//(GLM_COMPONENT == GLM_COMPONENT_GLSL_NAMES)
@kioba
kioba / rect.cpp
Created November 17, 2015 20:17
drawing a rectangle creat and draw function
void Rect::create()
{
static float a = 0;
a += 0.01f;
std::vector<float> vertex_buffer_data = {
0.0f + a, 0.0f + a, a,
0.3f + a, 0.0f + a, a,
0.3f + a, 0.3f + a, a,
0.0f + a, 0.0f + a, a,
0.3f + a, 0.3f + a, a,