Skip to content

Instantly share code, notes, and snippets.

View pyrsmk's full-sized avatar
🤖
boop. boop. boop beep boop.

Aurélien Delogu pyrsmk

🤖
boop. boop. boop beep boop.
View GitHub Profile
<?php
return new class extends Sophie
{
function mount()
{
$this->author = fn() => new Author;
$this->date = fn() => new DateTime;
$this->body = fn() => random_text();
$this->tags = fn() => [random_string(), random_string()];
LIST = "⠹⠼⠶⠧⠏⠛"
LIGHT = "⢕⡪"
SPEED = 1
def loader(speed=SPEED, list=LIST)
list[(Time.now.to_f * 10 ** speed).to_i % list.length]
end
# Add this line to your loop
print "Loading... #{ loader(1, LIST) }\r"
LIST = "⠹⠼⠶⠧⠏⠛"
LIGHT = "⢕⡪"
SPEED = 1
trap "SIGINT" do
exit!
end
def loader(speed=SPEED, list=LIST)
list[(Time.now.to_f * 10 ** speed).to_i % list.length]
@pyrsmk
pyrsmk / fancy_loader.rb
Created July 2, 2020 08:36
A fancy dots loader
def fancy_loader(current, total)
glyph = "⠹⠼⠶⠧⠏⠛"[(Time.now.to_f * 10).to_i % 6]
print "\r#{glyph} #{current}/#{total}"
end
@pyrsmk
pyrsmk / service.rb
Last active July 2, 2020 20:01
Example of a pipe implementation in a service, from the functional programming world 🤖
class SomeService
def call(some_value, bypass_some_method4 = false)
pipe(
some_value,
:some_method1,
:some_method2,
-> (value) { value * 2 },
bypass_some_method4 ? :noop : :some_method4,
:some_method5
)
@pyrsmk
pyrsmk / Makefile
Created November 26, 2020 16:30
Current directory example in Makefile
current_dir := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
.PHONY=install
install:
ln -sf $(current_dir)config ~/.test/config
// Currently, the ESLint plugin used by Svelte is buggy and choke on files with Sass.
// This little implementation takes care of removing styling from Svelte components as
// as well as handle any type of files other than Svelte, with complete respect of rules
// from the base ESLint plugin (that is, `.eslintrc.cjs` rules are used). It has been
// thought to be simple to use and integrate.
//
// https://github.com/sveltejs/eslint-plugin-svelte3/issues/10
//
// Usage example:
//
@pyrsmk
pyrsmk / xml2obj.js
Created January 19, 2022 17:38
Convert XML files to JS objects.
// It converts simple XML structures to JS objects. The default value of a node is an
// empty string, as it should be (contrary to several libraries I tested).
const { DOMParser } = require('@xmldom/xmldom')
const loadChildNodesRecursive = node => {
const nodes = {}
Array.from(node.childNodes)
.filter(element => element.nodeType === element.ELEMENT_NODE)
.forEach(element => {
@pyrsmk
pyrsmk / event_testing.html
Last active March 15, 2022 10:33
Because sometimes we don't understand what's going on with DOM events (even more on mobiles), here's an HTML page to test and understand things 🦄
<!doctype html>
<html>
<head>
<title>Event testing.</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w==" crossorigin="anonymous" />
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
<style>
* {
@pyrsmk
pyrsmk / busy.ts
Created July 1, 2022 14:06
A simple function that marks a callback as busy to avoid calling it multiple times before it has finished its task.
const busyCallbacks = new Set()
export async function busy(callback : () => any) : Promise<any> {
if (busyCallbacks.has(callback)) {
return
}
busyCallbacks.add(callback)
const value = await callback()
busyCallbacks.delete(callback)
return value