Skip to content

Instantly share code, notes, and snippets.

gcloud functions deploy: .gcloudignore

The algorithm is basically as follows:

for each dir:
  if allowed:
    for each file (of this dir):
      if allowed: add
@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 1, 2024 14:59
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>
@x-yuri
x-yuri / c, c++: jumping over declarations.md
Last active October 28, 2024 13:03
c/c++: jumping over declarations

c/c++: jumping over declarations

In C one can't have a labeled variable declaration. This quirk probably appeared in C99. Before that variable declarations had to be at the beginnings of blocks, so there could never be a variable declaration after a label. C99 allowed intermixing variable declarations and statements, but the grammar [remained the same][a], allowing only statements after labels.

cases
$ gcc --version
gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309
@x-yuri
x-yuri / A poor man's http server.md
Created October 26, 2024 20:00
A poor man's http server

A poor man's http server

The server process handles a request and exits. But the server is running in a docker container with --restart always, so after each request docker restarts the server.

Dockerfile:

FROM alpine:3.20
COPY a.c a.c
RUN apk add gcc musl-dev \
@x-yuri
x-yuri / Reading an HTTP request without blocking.md
Created October 26, 2024 18:57
Reading an HTTP request without blocking

Reading an HTTP request without blocking

It's assumed that only valid requests are received. And that read() doesn't block until \r\n\r\n is received.

a.c:

#include <unistd.h>
#include <err.h>
#include <string.h>
@x-yuri
x-yuri / a. mecab.md
Last active October 31, 2024 12:25
mecab

mecab

Dockerfile (git):

FROM alpine:3.20
RUN apk add git build-base curl \
    && git clone https://github.com/taku910/mecab \
    && cd mecab/mecab \
    && ./configure \