Skip to content

Instantly share code, notes, and snippets.

View rexim's full-sized avatar
📺
https://twitch.tv/tsoding

Alexey Kutepov rexim

📺
https://twitch.tv/tsoding
View GitHub Profile
#!/usr/bin/env python3
# https://www.hackerrank.com/challenges/alphabet-rangoli/problem
import math
# ----c----
# --c-b-c--
# c-b-a-b-c
# --c-b-c--
@rexim
rexim / main.c
Created March 30, 2021 11:46
Simple dl example using SDL2 on Linux
// $ cc -o main main.c -ldl
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <dlfcn.h>
#define SDL_LIBRARY_NAME "libSDL2-2.0.so"
#define SDL_INIT_VIDEO 0x00000020u
#define SDL_WINDOW_RESIZABLE 0x00000020
// $ gcc `pkg-config --cflags libcurl` -o main main.c `pkg-config --libs libcurl`&& ./main
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
int main(void)
{
if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0) {
fprintf(stderr, "ERROR: could not initialize global CURL state for some reason.\n");
#include <stdio.h>
#define ROWS 10
#define COLS 10
typedef enum {
DEAD = 0,
ALIVE = 1,
} Cell;
use std::ffi::{c_void, CStr, CString};
use std::os::raw::c_char;
const SDL_INIT_VIDEO: u32 = 0x00000020;
const SDL_WINDOW_RESIZABLE: u32 = 0x00000020;
const SDL_RENDERER_ACCELERATED: u32 = 0x00000002;
const SDL_QUIT: u32 = 0x100;
@rexim
rexim / if-label-paradox.md
Last active March 10, 2021 12:09
Quick Gist of the paradox we are trying to prevent in our assembly

The "If-Label" Paradox

In our assembly we are implementing the support for conditional translation:

%include "natives.hasm"
%const N 10
main:
    push 1
 push 2
@rexim
rexim / simple_openssl_client.c
Last active April 16, 2024 11:03
Simple OpenSSL example that makes HTTPS request
// cc `pkg-config --cflags openssl` -o simple_openssl_client simple_openssl_client.c `pkg-config --libs openssl`
// Copyright 2021 Alexey Kutepov <reximkut@gmail.com>
//
// 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 furnished to do so, subject to
#!/usr/bin/env python3
import random
cs = "BCDFGHJKLMNPQRSTVWXZY"
vs = "AEIOU"
def generate_name(n=3):
result = ""
for i in range(n):
@rexim
rexim / main.c
Created February 2, 2021 11:09
Stretching Buffer in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
size_t size;
size_t capacity;
char *data;
} Buffer;
@rexim
rexim / main.c
Created February 1, 2021 14:58
Region-based memory management
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
typedef struct Region Region;
struct Region {
Region *next;