Skip to content

Instantly share code, notes, and snippets.

View vastus's full-sized avatar
🦅
all(good)

Juho Hautala vastus

🦅
all(good)
View GitHub Profile
from enum import Enum
from typing import Any, Optional
class TokenType(Enum):
NUMBER = 1
BANG = 2
CARET = 3
STAR = 4
SLASH = 5
PLUS = 6
@vastus
vastus / defer.c
Created January 31, 2025 06:36
defer in C (gcc only)
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#define CAT_IMPL(x, y) x##y
#define CAT(x, y) CAT_IMPL(x, y)
#define defer DEFER_IMPL(CAT(defer__, __COUNTER__))
#define DEFER_IMPL(name) auto void name (void*); \
@vastus
vastus / echo-fork.c
Created January 21, 2025 02:35
TCP echo server w/ fork handler
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#define PORT 42069
@vastus
vastus / select.c
Created January 18, 2025 00:38
chat using `select`
/**
* host1$ make select && ./select
* host1$ telnet host1 6969
* host2$ telnet host1 6969
* ...
* ???
* profit
*/
#include <errno.h>
#include <stdio.h>
// $ make simple && ./simple &
// $ telnet localhost 6969
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#!/bin/bash
# Usage:
# $ sh mkcert example.com
set -euo pipefail
main() {
DOMAIN="$1"
local key="${KEY:-$DOMAIN.pem}"
Attaching to zkevm-pool-db, zkevm-prover, zkevm-rpc, zkevm-state-db, zkevm-sync
zkevm-pool-db |
zkevm-pool-db | PostgreSQL Database directory appears to contain a database; Skipping initialization
zkevm-state-db |
zkevm-pool-db |
zkevm-state-db | PostgreSQL Database directory appears to contain a database; Skipping initialization
zkevm-state-db |
zkevm-sync | Version: v0.3.3
zkevm-sync | Git revision: d36d1d3
zkevm-sync | Git branch: HEAD
#!/bin/bash
# Usage:
# EMAIL='you@example.com' PASSWORD='your password' bash api_v2_getting_started.sh
TOKEN=
GET() {
curl -s -H 'content-type: application/json' \
-H "authorization: Bearer ${TOKEN}" \
@vastus
vastus / Makefile
Last active February 24, 2021 03:08
cclsexample
CC = clang
CFLAGS += -Iinclude
main: src/main.o
$(CC) $(CFLAGS) -o main src/main.o
@vastus
vastus / common.sh
Created August 18, 2020 20:34
Common provisioning
set -euxo pipefail
PROVIS_PATH="$HOME/provis"
git clone https://github.com/vastus/provis.git ${PROVIS_PATH}
make -C ${PROVIS_PATH} common