Skip to content

Instantly share code, notes, and snippets.

View Caellian's full-sized avatar

Tin Švagelj Caellian

View GitHub Profile
@Caellian
Caellian / IncludeSubmodules.cmake
Created April 26, 2024 22:42
A CMake script that automatically fetches git submodules if they're not initalized
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
option(INIT_SUBMODULES "Check submodules during build" ON)
if(INIT_SUBMODULES)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(GIT_SUBMOD_RESULT EQUAL "0")
message(STATUS "Submodules initialized")
else()
@Caellian
Caellian / A - preview.md
Last active March 3, 2024 09:58
Animated grid background with houdini / 2D canvas API.

preview

@Caellian
Caellian / tones.sass
Created December 30, 2023 23:38
Pure CSS tone indicators.
$tones: "joke" "/j" "joking", "half-joke" "/hj" "half-joking", "sarcasm" "/s" "sarcastic", "genuine" "/g" "genuine", "serious" "/srs" "serious", "non-serious" "/nsrs" "non-serious", "positive" "/pos" "positive connotation", "neutral" "/neu" "neutral connotation", "negative" "/neg" "negative connotation", "copypasta" "/c" "copypasta", "lyrics" "/ly" "lyrics", "light-hearted" "/lh" "light-hearted", "not-mad" "/nm" "not mad", "nobody-here" "/nbh" "nobody here", "rhetorical" "/rh" "rhetorical question", "teasing" "/t" "teasing", "metaphore" "/m" "metaphorically", "literal" "/li" "literally", "hyperbole" "/hyp" "hyperbole", "fake" "/f" "fake"
span[data-tone]
display: inline
position: relative
&:before
display: inline-block
width: min-content
padding: 0 1ch
background: hsl(0,0%,15%)
@Caellian
Caellian / apply.rs
Last active September 23, 2023 01:30
Apply mutates a value using a closure and then instantly returns it. This is useful for handling Ok/Some case in scenarios where type can be either Result/Option<T> or T directly, based on another type generic, but that requires `specializatation` feature.
pub trait Apply {
type ValidValue;
fn apply(self, consumer: impl Fn(&mut Self::ValidValue)) -> Self
where
Self: Sized;
fn apply_ref(&mut self, consumer: impl Fn(&mut Self::ValidValue)) -> &mut Self;
}
default impl<T> Apply for T {
@Caellian
Caellian / expanded.rs
Created September 7, 2023 09:06
Ping pong expanded
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use litesim::prelude::*;
pub struct Player;
#[cfg(feature = "rewind")]
impl<'s> RewindModel<'s> for Player {
type RewindBackup = Self;
@Caellian
Caellian / line-clamp.scss
Last active August 7, 2023 17:03
Text ellipsis and line clamping
p {
display: inline-block; // fallback for CSS4
display: -webkit-inline-box; // specialized renderer supported by all major browsers
-webkit-box-orient: vertical; // Required by FF for -webkit-line-clamp
-webkit-line-clamp: 1;
line-clamp: 1; // Forward CSS4 support
font-size: var(--size);
line-height: calc(var(--size) * 1.2); // leave wiggle room for descending characters (e.g. jy...)
overflow: hidden; // required for ellipsis
@Caellian
Caellian / useEffectEach.js
Last active July 24, 2023 01:46
React useEffect that works on iterables.
/**
* Behaves like useEffect, but the hook function recieves changed iterable values as an argument.
*
* @param {(changed: any) => ((changed: any) => void)} call
* @param {Iterable} iter Primary dependency and iterable that's operated on
* @param {any[]} dependencies Additional dependencies
* @param {(a: any, b: any) => boolean} matcher Equality comparator used for comparing previous and new values, dequal (deep-equal) by default
*/
export function useEffectEach(call, iter, dependencies = [], matcher = dequal) {
@Caellian
Caellian / Svelte Tabs Component.md
Last active July 18, 2023 16:49
A rounded tab picker component in Svelte

preview

@Caellian
Caellian / view.css
Created May 22, 2023 13:44
Obsidian dictionary view
.dictionary-view {
display: contents;
}
.dictionary-view * {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.dictionary-view .search-bar {
@Caellian
Caellian / list_project_times.py
Last active April 27, 2023 21:34
ActivityWatch client script that queries VSCode events and shows time spent on projects
#!/usr/bin/env python3
from time import sleep
from datetime import datetime, timedelta, timezone
from dateutil.parser import isoparse
from aw_core.models import Event
from aw_client import ActivityWatchClient
# Server settings