Skip to content

Instantly share code, notes, and snippets.

View ealmloff's full-sized avatar

Evan Almloff ealmloff

View GitHub Profile
use dioxus::prelude::*;
use dioxus_primitives::select::{
Select, SelectGroup, SelectGroupLabel, SelectItemIndicator, SelectList, SelectOption,
SelectTrigger, SelectValue,
};
use strum::{EnumCount, IntoEnumIterator};
#[derive(Debug, Clone, Copy, PartialEq, strum::EnumCount, strum::EnumIter, strum::Display)]
enum Fruit {
Apple,
{"identity":{"device_triple":"aarch64-apple-darwin","is_ci":false,"cli_version":"0.7.0-alpha.3 (ba856ac)","session_id":218853676744316928865703503826531902998},"name":"cli_command","module":null,"message":"serve","stage":"start","time":"2025-07-24T14:34:07.684804Z","values":{"args":{"address":{"addr":null,"port":null},"always_on_top":null,"cross_origin_policy":false,"exit_on_error":false,"force_sequential":false,"hot_patch":false,"hot_reload":null,"interactive":null,"open":null,"platform_args":{"client":null,"server":null,"shared":{"args":false,"targets":{"build_arguments":{"all_features":false,"base_path":false,"bin":null,"bundle":null,"cargo_args":false,"debug_symbols":true,"device":false,"example":false,"features":false,"inject_loading_scripts":true,"no_default_features":false,"package":null,"platform":null,"profile":false,"release":false,"renderer":{"renderer":null},"rustc_args":false,"skip_assets":false,"target":null,"target_alias":"Unknown","wasm_split":false},"fullstack":null,"ssg":false}}},"watch":nul
// candle-core = "0.8.4"
use candle_core::Module;
fn main() {
let mut q_data = [[0f32; 256]; 256];
q_data[0][0] = 1.;
q_data[0][1] = 2.;
q_data[0][2] = 3.;
q_data[1][0] = 3.;

Here is an overview of the state management system in dioxus. This doesn't cover all the internals, but it should serve as a pretty good reference:

State

Signal is like a fancy version of RefCell for UIs. Just like RefCell, it checks borrows at runtime. It has a bunch of helper methods to make it easier to use. Calling it like a function will clone the inner value. You can also call a few traits like AddAssign on it directly without writing to it manually.

// create a signal
let signal = use_signal(|| 0);
use criterion::*;
criterion_group!(benches, leptos_ssr_bench, dioxus_ssr_bench);
criterion_main!(benches);
fn leptos_ssr_bench(c: &mut Criterion) {
use leptos::*;
let r = create_runtime();
c.bench_function("leptos ssr", |b| {
b.iter(|| {
use kalosm::language::*;
#[tokio::main]
async fn main() {
let local_source = LlamaSource::new(
FileSource::Local("path/to/llama/model".into()),
FileSource::Local("path/to/llama/tokenizer.json".into()),
)
.with_group_query_attention(
// 1 for llama, 8 for mistral
@ealmloff
ealmloff / test.md
Last active December 28, 2023 00:09
Screenshot 2023-12-27 at 6 08 51 PM
#![allow(non_snake_case)]
use dioxus_signals::use_signal;
use dioxus::prelude::*;
use dioxus_fullstack::prelude::*;
fn main() {
LaunchBuilder::new(App).launch();
}
fn App(cx: Scope) -> Element {
window.addEventListener('scroll', () => {
let scrollTop = window.scrollY;
let winHeight = window.document.documentElement.scrollHeight - window.document.documentElement.clientHeight;
let new_scroll = Math.min(Math.max(scrollTop, 0) / Math.max(winHeight, 1), 1);
document.body.style.setProperty('--scroll', new_scroll);
}, false);