Skip to content

Instantly share code, notes, and snippets.

View ant1fact's full-sized avatar

David Pacsuta ant1fact

  • Deutsche Telekom
  • Keszthely, Hungary
View GitHub Profile
@ant1fact
ant1fact / tail_reader.zig
Last active July 18, 2024 15:14
Get the last line of a text file in Zig
const std = @import("std");
/// Try to get the last line of a text file. The returned line will be trimmed of any new line characters.
/// If the file is empty, or if the file only contains new lines, the returned slice will be empty.
pub fn getTail(allocator: std.mem.Allocator, file: *std.fs.File) ![]const u8 {
var result = std.ArrayList(u8).init(allocator);
const step_size: i64 = 4096; // Same as default BufferedReader
var read_buffer: [step_size]u8 = undefined;
var reader = file.reader();
@ant1fact
ant1fact / enumerate_physical_devices.zig
Created May 4, 2024 20:35
Enumerate available Vulkan physical devices in Zig
// Zig 0.12.0
// Vulkan 1.3.280.0
// Get device count
var physical_device_count: u32 = 0;
if (vk.vkEnumeratePhysicalDevices(instance, &physical_device_count, null) != vk.VK_SUCCESS) {
std.debug.panic("Failed to get number of physical devices.", .{});
}
// Populate physical devices array
@ant1fact
ant1fact / enumerate_extensions.zig
Created May 3, 2024 15:04
Enumerate available Vulkan extensions using Zig
// Zig 0.12.0
// Vulkan 1.3.280.0
// Get the number of extensions
var extension_count: u32 = 0;
if (vk.vkEnumerateInstanceExtensionProperties(null, &extension_count, null) != vk.VK_SUCCESS) {
std.debug.panic("Failed to retrieve instance extension count.", .{});
}
// Allocate array to hold enumerated extension properties
@ant1fact
ant1fact / install_nvim_ubuntu.sh
Last active September 3, 2023 20:10
Install neovim in Ubuntu/WSL
cd
sudo apt-get install ninja-build gettext cmake unzip curl
git clone https://github.com/neovim/neovim.git
cd neovim
git checkout v0.9.1
make CMAKE_BUILD_TYPE=Release
sudo make install
sudo cp ./build/bin/* /usr/bin/
@ant1fact
ant1fact / gist:49a51a260f65b3e1adc6b7d8d18d5d39
Created August 24, 2022 21:05
Copy data from CSV w/ header into Postgres table
psql <database>
\COPY <table> (<optional list of columns>,) FROM <relative path to .csv> WITH CSV HEADER;
@ant1fact
ant1fact / ubuntu_postgres.sh
Created April 6, 2022 11:51
Install postgres on ubuntu
sudo apt update
sudo apt upgrade
# Install and start postgres server
sudo apt install postgresql
sudo service postgresql start
# Create new (super) user
sudo -u postgres createuser --interactive
# Create db for the new user
sudo -u postgres createdb <USER>
# Test
@ant1fact
ant1fact / install.sh
Created February 20, 2022 12:33
Install python3.10 as python on ubuntu 20.04
# Setup
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa -y
# Python 3.10
sudo apt install python3.10
sudo apt install python3.10-dev
sudo apt install python3.10-distutils
sudo apt install python3.10-venv
@ant1fact
ant1fact / flask_sqlalchemy_required_fields.py
Created February 7, 2022 12:37
Easily get a list of required fields of a Flask-SQLAlchemy model, i.e. where db.Column(..., nullable=False)
from flask_sqlalchemy import Model, SQLAlchemy
from sqlalchemy import inspect
# Extend the base Model, for more details see:
# https://flask-sqlalchemy.palletsprojects.com/en/2.x/customizing/#model-class
class ExtendedModel(Model):
@classmethod
def required_fields(cls) -> list:
'''Returns column names for the Model where nullable=False'''
mapper = inspect(cls)