Skip to content

Instantly share code, notes, and snippets.

@x-yuri
x-yuri / git: branch.autoSetupMerge.md
Last active December 15, 2024 01:29
git: branch.autoSetupMerge

git: branch.autoSetupMerge

branch.autoSetupMerge makes git branch, git switch and git checkout set upstream for branches they create:

  • false - no upstream is set

  • simple - upstream is set to <start-point> when <start-point> is a remote-tracking branch and the branch names (the one to be created and the remote one) match

    On a side note, one can't create a local branch, which name matches the name of another local branch, as such one might say that if the branch names match, <start-point> can't be a local branch, i.e. <start-point> is a remote-tracking branch.

@x-yuri
x-yuri / bats.md
Last active December 9, 2024 08:27
bats

bats

a.bats:

strict() { set -euo pipefail; shopt -s inherit_errexit; "$@"; }

setup() {
    [ "$BATS_LIB_PATH" = /usr/lib/bats ] && BATS_LIB_PATH=$HOME/.bats/lib:$BATS_LIB_PATH
    bats_load_library bats-support
@x-yuri
x-yuri / bash: arrays and set -u.md
Last active December 9, 2024 05:47
bash: arrays and set -u

bash: arrays and set -u

In bash < 4.4 "${a[@]}" fails (unbound variable) if a is unset (nothing was assigned to a) or a=(). Also "${a[@]:+${a[@]}}" and "${a[@]+${a[@]}}" produce empty arrays if a=('').

What works before, after and in 4.4 is ${a[*]+"${a[@]}"} and ${a[@]+"${a[@]}"}.

It should also be mentioned that ${#a[@]} fails if a is unset (regardless of the version). And ${a[i]} fails if the specified element doesn't exist.

a.bats:

@x-yuri
x-yuri / bash: word splitting.md
Last active December 8, 2024 22:12
bash: word splitting

gcloud functions deploy: .gcloudignore

(the beginning)

The algorithm is basically as follows:

for each dir:
  if allowed:
    for each file (of this dir):
@x-yuri
x-yuri / perl: internal representation of numbers.md
Created November 13, 2024 11:18
perl: internal representation of numbers

perl: internal representation of numbers

Perl can internally represent numbers in 3 different ways: as native integers, as native floating point numbers, and as decimal strings.

https://perldoc.perl.org/perlnumber

Small integer numbers are stored as signed integers. When that is not possible perl switches to unsigned integers. And then to floating point numbers:

a.pl:

@x-yuri
x-yuri / 01. perl: pack().md
Last active December 2, 2024 04:47
perl: pack()

perl: pack()

I'm going to ignore the j, J, f, F, d, D, p, P, u, w formats.

My machine has the x86_64 architecture (little-endian) and I'm running perl-5.38-2.

The way it's described is not necessarily matches the way it works internally. This is merely an explanation that seems to work.

$ perl -V:shortsize -V:intsize -V:longsize -V:longlongsize
@x-yuri
x-yuri / Building mecab (with its perl module) with debug symbols.md
Created October 31, 2024 06:22
Building mecab (with its perl module) with debug symbols

Building mecab (with its perl module) with debug symbols

Dockerfile:

FROM alpine:3.20.3
RUN set -x && apk add git build-base autoconf gdb automake libtool gettext-dev perl-dev \
    && git clone https://github.com/taku910/mecab \
    && cd mecab \
    && git checkout 05481e751dd5aa536a2bace46715ce54568b972a \
@x-yuri
x-yuri / Creating a shared library in C, C++.md
Last active November 1, 2024 20:10
Creating a shared library in C/C++

Creating a shared library in C/C++

a.c:

#include <stdio.h>
#include "a.h"

void f(void)
{
@x-yuri
x-yuri / Making a STUN request in C.md
Created October 28, 2024 17:58
Making a STUN request in C

Making a STUN request in C

a.c:

#include <stdlib.h>
#include <sys/socket.h>
#include <err.h>
#include <stdio.h>
#include <sys/random.h>