Skip to content

Instantly share code, notes, and snippets.

View MartinKavik's full-sized avatar

Martin Kavík MartinKavik

View GitHub Profile
defmodule Schizo do
@moduledoc """
A module that lets you **uppercase** and **unvowel** every other word in a sentence.
"""
@doc """
Uppercases every other word in a sentence.
@MartinKavik
MartinKavik / LTree.elm
Last active June 27, 2018 19:48
LTree.elm & LTreeTest.elm - multiway tree in Elm (not refactored, not complete), written for desktop app FusionD (pre-alpha screenshot: https://prnt.sc/k03m71). Little bit inspired by http://patshaughnessy.net/2017/12/13/saving-a-tree-in-postgres-using-ltree.
module Utils.LTree
exposing
( Forest
, Label
, Node
, createEmptyForest
, createForest
, createNode
, deleteNode
, filterNodes
@MartinKavik
MartinKavik / lib.rs
Created August 16, 2019 09:58
Toy seed app refactored
// Replace *lib.rs* in the seed-quickstart project with this file,
// then run `cargo make build && cargo make serve`.
#[macro_use]
extern crate seed;
use seed::prelude::*;
// Model
@MartinKavik
MartinKavik / canvas.rs
Last active November 21, 2019 11:02
Canvas example with ElRef
//! [Web-sys docs](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.CanvasRenderingContext2d.html)
//! [Web-sys example](https://rustwasm.github.io/wasm-bindgen/examples/2d-canvas.html)
//! [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawWindow)
#[macro_use]
extern crate seed;
use seed::prelude::*;
use web_sys::HtmlCanvasElement;
type Color = &'static str;
@MartinKavik
MartinKavik / code-block.js
Created February 22, 2020 21:20
code-block custom element - highlightJS + lit-element
import { LitElement, html, css } from 'https://unpkg.com/lit-element/lit-element.js?module';
import { unsafeHTML } from 'https://unpkg.com/lit-html/directives/unsafe-html.js?module';
class CodeBlockElement extends LitElement {
static get properties() { return {
lang: "",
code: "",
};}
render() {
@MartinKavik
MartinKavik / markdown_editor_lib.rs
Created February 26, 2020 07:58
Step 5 - final code
#![feature(track_caller)]
use comp_state::*;
use comp_state_seed_extras::*;
use seed::{prelude::*, *};
use web_sys::{HtmlElement, HtmlTextAreaElement};
#[derive(Default)]
struct Model {}
@MartinKavik
MartinKavik / handler_msg_or_unit_panics.rs
Last active March 15, 2020 17:29
Return `Msg` or `()` in handlers. | Runtime panics | Stable Rust
use std::any::{Any, TypeId};
#[derive(Debug)]
enum Msg {
Increment,
}
fn main() {
let handlers: Vec<Handler<Msg>> = vec![
Handler::new(|| Msg::Increment),
@MartinKavik
MartinKavik / static_handler_return.rs
Created March 15, 2020 11:46
Return `Msg` or `()` in handlers. - compile check
#[derive(Debug)]
enum Msg {
Increment,
}
// can write procedural macro for derviing
impl MsgMarker for Msg {}
fn main() {
let handlers: Vec<Handler<Msg>> = vec![
@MartinKavik
MartinKavik / assert_type_eq_all_problem.rs
Last active March 15, 2020 14:26
uncomment line 53 and run in Rust playground
use std::any::{Any, TypeId};
#[derive(Debug)]
enum Msg {
Increment,
}
// copy-paste from static_assertions crate
#[macro_export]
macro_rules! assert_type_eq_all {
@MartinKavik
MartinKavik / handler_msg_or_unit_compile_validation.rs
Last active March 23, 2020 20:20
Return `Msg`, `Option<Msg>` or `()` in handlers. | Compile-time validation | Nightly Rust
#![feature(optin_builtin_traits)]
//#![feature(negative_impls)]
#[derive(Debug)]
enum Msg {
Increment,
Decrement
}
fn main() {