Skip to content

Instantly share code, notes, and snippets.

View malobre's full-sized avatar

Maël Obréjan malobre

  • EI Maël Obréjan
  • France
  • 13:18 (UTC +02:00)
View GitHub Profile
@malobre
malobre / joinls.rs
Created February 19, 2024 09:36
A macro to join strings with newlines
/// Flattens literals into a single static string slice, placing a newline between each element.
macro_rules! joinln {
($head:expr, $($e:expr),* $(,)?) => {
concat!($head, $('\n', $e, )*)
};
}
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveMacros: AcrossComments
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
@malobre
malobre / vite-plugin-html-minifier.js
Created March 22, 2023 23:23
`html-minifier` as a vite plugin
import { minify as minifyHTML } from "html-minifier";
const vitePluginHtmlMinifier = {
name: "html-minifier",
apply: "build",
transformIndexHtml: (html) => minifyHTML(html, {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
collapseBooleanAttributes: true,
decodeEntities: true,
@malobre
malobre / dedent.js
Last active February 28, 2023 22:56
A tag function that removes leading spaces until a line reaches the left margin.
// MIT License
//
// Copyright (c) 2023 Maël Obréjan
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@malobre
malobre / web-components-preview.md
Last active February 28, 2023 22:43
Simple web components preview

When building a web application with [web components], you might want a way to preview your components outside of the app (makes rendering edge-cases and hard to reach states much easier). [Storybook] is a common option, but it can be complicated to setup and maintain.

Instead, you can create a simple HTML file for each component, e.g MyComponent.preview.html:

<!DOCTYPE html>
<title>My Component Preview</title>
@malobre
malobre / joinln.rs
Created June 29, 2022 13:51
Flattens literals into a single static string slice, placing a newline between each element.
/// Flattens literals into a single static string slice, placing a newline between each element.
macro_rules! joinln {
($head:expr, $($e:expr),* $(,)?) => {
concat!($head, $('\n', $e, )*)
};
}
@malobre
malobre / ts3-afk-bot.sh
Created September 17, 2016 22:38
Teamspeak 3 AFK bot, move clients to the specified channel when they are muted for more than the specified period of time and move them back when they unmute themself.
#!/bin/bash
#
# ts3server-bot.sh
#
# Teamspeak 3 AFK bot, move clients to the specified channel when they are muted
# for more than the specified period of time and move them back when they unmute
# themself.
#
# Copyright 2016, Malobre.
#
@malobre
malobre / NativesLoader.java
Last active July 9, 2017 15:47
Simple class that extract and load the lwjgl 3 natives from your jar.
/**
* This code is under the CC BY 4.0 license, http://creativecommons.org/licenses/by/4.0/
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;