Skip to content

Instantly share code, notes, and snippets.

@agvxov
agvxov / gist:7e093a2dd7641e95ec667213d9dcf99f
Created January 29, 2025 13:17
#Getting the TTY size in C without ncurses
>*NIX only
>it is baffling how everyone only ever says "uh oh use ncurses or something"
{
// @BAKE gcc -o $*.out $@
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
int get_tty_size(int * width_out, int * height_out) {
struct winsize ws;
>since MySQL uses an internal system for identifying users a few hoops must be jumped
>root is always preregistered
1. Log in as root
$ sudo mysql
2. Create a new user
CREATE USER '<your_name>'@'localhost' IDENTIFIED BY '<password>';
>NOTE: <password> doesnt have to be the same as the user's system login password
3. Grant privileges to the new user
GRANT ALL PRIVILEGES ON *.* TO '<your_name>'@'localhost';
//@BAKE g++ $@ $(pkg-config --cflags --libs ncurses readline)
/* NOTE:
* We are using C++ here to have access to lambdas.
* The C version would look exactly like this, but with traditional callback functions.
*/
#include <ncurses.h>
#include <readline/readline.h>
#define WINDOW_WIDTH 32
{
// --- AnimalRepository.java ---
/* By using the Farm package here,
* we make the contents of
* FarmApplication.java visible
*/
package com.example.Farm;
import org.springframework.data.jpa.repository.JpaRepository;
1. Set up dependencies
-gateway is all we need:
spring-cloud-starter-gateway
-NOTE: in case you missed it during initialization,
this is how it would look like under gradlew:
{
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
}
{// examples
>the goal is the same with each methodology
>we have data.txt
>it contains key-value pairs
¤its generated with this script
{ @begin=sh@
#!/bin/bash
# generator.sh
1. Assume the following type in C
{
typedef struct {
int i;
} hello_world_t;
// and an exemplary instance
hello_world_t my_hw;
}
>NOTE: compiling with debugging information is required (-ggdb under gcc)
XXX:
>basic knowledge of public key cryptography
>the server holds a public key, while the client has a private key
which it will use for authentication
>this way we protect from brute forcing attacks and
optionally avoid having to enter a password manually when connecting
1. Create a key pair
Green( anon@Client )$ ssh-keygen
"Generating public/private rsa key pair."
1. Start up the guest machine
2. Install "guest additions"
>lauch the virtual machine click "Devices/Insert Guest Additions CD image..." (on the top bar)
>run the contents of the CD
3. Configurate
>in the main menu click the guest systems settings
>find the "Shared Folders" tab
>click the pluss folder sign
input:
{ // sdl_hw.c
// @BAKE gcc $@ -o sdl_hw.out -Wall -Wpedantic $(pkg-config --cflags --libs sdl2)
#include <SDL.h>
signed main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("HW", 0, 0, 800, 800, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);