Skip to content

Instantly share code, notes, and snippets.

View ArthurSonzogni's full-sized avatar
🎯
Focusing

Arthur Sonzogni ArthurSonzogni

🎯
Focusing
View GitHub Profile
@ArthurSonzogni
ArthurSonzogni / concurrencyLimiter.js
Created February 21, 2021 17:46
concurrencyLimiter
// Return a promise, limiting the number of concurrent accesses to a shared
// resources to |max_concurrent_access|.
const concurrencyLimiter = (max_concurrency) => {
let pending = 0;
let waiting = [];
return async (task) => {
pending++;
// Wait our turn, if needed.
if (pending > max_concurrency)
await new Promise(resolve => waiting.push(resolve));
@ArthurSonzogni
ArthurSonzogni / lock.js
Created February 21, 2021 11:26
lock.js
let locked = [];
const lock = async (promise) => {
if (locked.length == 0) {
locked.push(undefined)
} else {
await new Promise(resolve => {
locked.push(resolve);
});
}
@ArthurSonzogni
ArthurSonzogni / capture_stdout.hpp
Created October 15, 2020 20:07
C++ > Capture stdout
class CaptureStdout {
public:
CaptureStdout() { old = std::cout.rdbuf(ss.rdbuf()); }
~CaptureStdout() { std::cout.rdbuf(old); }
std::string Value() { return ss.str(); }
private:
std::stringstream ss;
std::streambuf* old;
};
#!/bin/bash
# bindsym $mod+l exec ~/lock.sh
lock_image=/tmp/screen.png
RES=$(xrandr | grep 'current' | sed -E 's/.*current\s([0-9]+)\sx\s([0-9]+).*/\1x\2/')
ffmpeg \
-f x11grab \
-video_size $RES \
-y \
-i $DISPLAY \
@ArthurSonzogni
ArthurSonzogni / finally_delete.hpp
Created July 14, 2017 17:16
finally_delete -- Adapt old C object to RAII.
// adapt old C object to RAII
// Example:
// ```
// Object* object_pointer = nullptr;
// finally_delete(object_pointer, delete_function)
// auto* object_pointer = allocate_some_object();
// throw exception/return;
// ```
template <typename objectPointer, typename delete_function>
@ArthurSonzogni
ArthurSonzogni / CP1252_to_UTF8.hpp
Last active April 28, 2022 07:44
Convert Windows-1252 (aka CP1252) to UTF8
/*
MIT License
Copyright (c) 2017 Arthur Sonzogni
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
#!/bin/bash
# +---------------------------------------+
# | Open commit's files as buffers in vim |
# +---------------------------------------+
if [ -z $1 ]
then
# No argument provided => use the latest commit's files.
commit=HEAD
/// ----------------------------------------------------------
/// Author : ArthurSonzogni
/// License : MIT
/// Description : wrap a QVboxLayout into a QScrollArea
/// if the QVBoxLayout is to big, a scroll bar
/// appear and let the user scroll
/// ----------------------------------------------------------
#ifndef BUILDSCROLLABLEWIDGETLIST_H
#define BUILDSCROLLABLEWIDGETLIST_H
@ArthurSonzogni
ArthurSonzogni / todo.cpp
Created March 14, 2016 13:43
TODO written in TODO
// TODO TODO TODO TODO TODO TODO TODO
// TODO TODO TODO TODO TODO TODO TODO
// TODO TODO TODO TODO TODO TODO TODO
// TODO TODO TODO TODO TODO TODO TODO
// TODO TODO TODO TODO TODO TODO TODO
// TODO TODO TODO TODO TODO
@ArthurSonzogni
ArthurSonzogni / date.sh
Created March 9, 2016 09:23
bash date command to display date in a compatible format for filename (in french)
date +"%y_%m_%d_%Hh%Mmin%Ssec"