Skip to content

Instantly share code, notes, and snippets.

@boyswan
boyswan / tw.rs
Created June 28, 2024 14:04
Tailwind logic macro
#[macro_export]
macro_rules! tw {
// Base case: when there are no tokens left, return an empty string.
() => (String::new());
// New case: handle static string literals
($static:literal ; $($rest:tt)*) => {{
let mut class = String::from($static);
let rest_classes = tw!($($rest)*);
if !rest_classes.is_empty() {
@boyswan
boyswan / limiter.rs
Created June 14, 2024 08:49
limiter.rs
use futures::Future;
use std::sync::Arc;
use tokio::sync::Notify;
use tokio::sync::Semaphore;
use tokio::task::spawn;
use tokio::time::{interval, Duration};
#[derive(Clone)]
pub struct Limiter {
capacity: usize,
use js_sys::{Array, Object, Reflect};
use leptos::html::Div;
use leptos::*;
use wasm_bindgen::prelude::*;
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
// Step 1: Create the WaveSurfer Binding
#[wasm_bindgen]
extern "C" {
pub type WaveSurfer;
@boyswan
boyswan / test.rs
Created February 19, 2024 22:36
leptos form experiment
use validator::{Validate, ValidationErrors};
macro_rules! form_field_vec_methods {
($field_name:ident, $field_type:ty) => {
paste::item! {
pub fn [<err_ $field_name>](&self) -> Option<String> {
self.0.get().is_valid(stringify!($field_name))
}
}
paste::item! {
@boyswan
boyswan / example.js
Created February 18, 2023 18:17
svg2canvas
// Example of svg -> b64
function svgTob64(svg_str) {
return "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svg_str)));
}
const get_image = b64 =>
new Promise((res, rej) => {
var img = new Image();
img.addEventListener("load", () => res(img));
// I set up my mesh and insert my custom attribute with an empty value
pub const ATTRIBUTE_FRAME: MeshVertexAttribute =
MeshVertexAttribute::new("frame", 988540917, VertexFormat::Float32x2);
let mut mesh = Mesh::from(shape::Quad::new(Vec2::splat(48.0)));
let empty: Vec<[f32; 2]> = vec![[0.0; 2]; 4];
mesh.insert_attribute(ATTRIBUTE_FRAME, empty);
// Add attribute with batched values in batch loop
#!/bin/sh
#
COMMAND="build"
USAGE="
Usage: bundle application [-w] [-h] \n\n
-w watch for file changes and rebuild the bundle \n
-h help \n
"
#!/bin/bash
IFS=$';'
for i in {3,5,9,17,33,65,129}
do
query=$(sqlite3 "/Users/jackboyce/Library/Application Support/Ableton/Live Database/Live-files-32.db" "SELECT _rowid_,* FROM main.files WHERE colors = $i")
copyFile () {
while read data; do