Skip to content

Instantly share code, notes, and snippets.

View MartinKavik's full-sized avatar

Martin Kavík MartinKavik

View GitHub Profile
@MartinKavik
MartinKavik / boon_counter.bn
Created November 5, 2024 16:24
Boon-lang counter
elements: [
decrement_button: LINK
increment_button: LINK
]
counter:
LATEST {
0
elements.decrement_button.event.press |> THEN { -1 }
elements.increment_button.event.press |> THEN { 1 }
@MartinKavik
MartinKavik / moonzoon_error_box__main.rs
Created January 24, 2024 21:46
MoonZoon error box
use std::any::Any;
use zoon::{once_cell::sync::Lazy, *, named_color::*};
fn main() {
start_app("app", root);
}
#[derive(Clone, Copy)]
struct DecreaseButtonPressed;
#[derive(Clone, Copy)]
@MartinKavik
MartinKavik / sortable.rs
Created May 12, 2023 15:05
MoonZoon Sortable wrapper v1
use std::{cell::Cell, iter, rc::Rc};
use zoon::*;
#[static_ref]
fn load_assets_once() -> &'static Mutable<bool> {
Task::start(async {
load_script(public_url("sortable/sortable_1.15.0.min.js")).await;
load_assets_once().set(true);
});
Mutable::default()
@MartinKavik
MartinKavik / MoonZoon Dockerfile
Last active February 25, 2023 21:20
MoonZoon Dockerfile
# Inspiration:
# - https://github.com/LukeMathWalker/cargo-chef
# - https://dev.to/rogertorres/first-steps-with-docker-rust-30oi
# - https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/
# - https://stackoverflow.com/a/54245466
FROM lukemathwalker/cargo-chef:0.1.51-rust-latest AS chef
RUN rustup target add wasm32-unknown-unknown
# `libclang` is required because of `argonautica`
RUN apt-get update && apt-get install -y \
@MartinKavik
MartinKavik / moonzoon_calc_main.rs
Last active January 13, 2023 00:22
"Calculator" written in MoonZoon
use zoon::{println, *};
fn root() -> impl Element {
let addend_a = Mutable::new(1);
let addend_b = Mutable::new(1);
let sum = map_ref! {
let addend_a = addend_a.signal(),
let addend_b = addend_b.signal() => {
println!("A: {addend_a}, B: {addend_b}");
addend_a + addend_b
@MartinKavik
MartinKavik / exercism_rust_forth_lib.rs
Created October 20, 2022 01:23
Exercism - Rust - Forth v.1 (too memory hungry)
use std::{collections::{HashMap, VecDeque}, rc::Rc};
pub type Value = i32;
pub type Result<T> = std::result::Result<T, Error>;
// ------ Error ------
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
DivisionByZero,
@MartinKavik
MartinKavik / zoon-draft-todos-app-els.rs
Last active December 4, 2020 18:49
zoon - draft - todos
use zoon::*;
use std::ops::Not;
blocks!{
#[el]
pub fn root() -> View {
view![
font::size(14),
font::family!("Helvetica Neue", "Helvetica", "Arial", font::sans_serif()),
@MartinKavik
MartinKavik / zoon-draft-counter-main.rs
Last active January 3, 2021 17:52
zoon - draft - counter
use zoon::*;
blocks!{
#[s_var]
fn counter() -> i32 {
0
}
#[update]
@MartinKavik
MartinKavik / view_optimization.rs
Created August 12, 2020 12:29
Seed `view` optimization by tracking data changes in `view` functions arguments
#![allow(dead_code)]
use std::collections::BTreeMap;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
struct Model {
todos: BTreeMap<String, Todo>,
new_todo_title: String,
selected_todo: Option<SelectedTodo>,
@MartinKavik
MartinKavik / breakpoints.rs
Created June 24, 2020 19:09
breakpoints!
// ------Seed code ------
#[derive(Debug)]
struct BreakpointInterval<B> {
id: B,
start: u32,
end: Option<u32>,
}
#[derive(Debug)]