Skip to content

Instantly share code, notes, and snippets.

@cacharle
cacharle / split.c
Created December 22, 2023 18:04
Split function in C
static size_t count_segment(char const *s, char c)
{
size_t counter = 0;
int i = 0;
while (s[i])
{
if (s[i] == c)
{
i++;
continue;
// Estimating CPU frequency...
// CPU frequency: 4.52 GHz
// sum1: value = 15182118497126522709, 0.31 secs, 5.14 cycles/elem
// sum2: value = 15182118497126522709, 0.17 secs, 2.93 cycles/elem
#define RW(x) asm("" : "+r"(x))
typedef struct Node {
u64 value;
struct Node *next;
@Kinadim
Kinadim / Vote.csv
Created May 28, 2021 17:28
programme élection
votant Milie Oscar Marine Max Albert
2182 1 4 3 2 5
1818 2 1 4 3 5
1636 4 2 1 3 5
727 2 4 3 1 5
364 4 2 3 1 5
3273 5 4 2 3 1

ZSH CheatSheet

This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.

Strings

Description Syntax
Get the length of a string ${#VARNAME}
Get a single character ${VARNAME[index]}
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active November 5, 2025 16:15
set -e, -u, -o, -x pipefail explanation
@kowalcj0
kowalcj0 / .bashrc
Last active August 29, 2024 23:43
Extract all subtitles from a movie using ffprobe & ffmpeg
alias subs=subs
function subs() {
movie="${1}"
filename="${1%.*}"
mappings=`ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "${movie}"`
OLDIFS=$IFS
IFS=,
( while read idx lang
do
@treyhunner
treyhunner / time_dict_merge.py
Last active November 3, 2023 08:13
Test performance of different dictionary merging functions in Python
"""
Results:
multiple_update: 33 ms
copy_and_update: 27 ms
dict_constructor: 29 ms
kwargs_hack: 33 ms
dict_comprehension: 33 ms
concatenate_items: 81 ms
union_items: 81 ms
@msabramo
msabramo / mock_patch_multiple_targets.py
Created September 11, 2015 19:42
Mock patch multiple targets in Python
@contextlib.contextmanager
def multiple_targets(mock_patches):
"""
`mock_patches` is a list (or iterable) of mock.patch objects
Example usage:
with mock.patch.multiple_targets([
mock.patch('os.path.exists', side_effect=mock_path_exists),
mock.patch('subprocess.Popen'),
@XVilka
XVilka / TrueColour.md
Last active October 9, 2025 17:55
True Colour (16 million colours) support in various terminal applications and terminals

THIS GIST WAS MOVED TO TERMSTANDARD/COLORS REPOSITORY.

PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!