Skip to content

Instantly share code, notes, and snippets.

View TrinityCoder's full-sized avatar

Miroslav Mareš TrinityCoder

View GitHub Profile
@TrinityCoder
TrinityCoder / .rustfmt.toml
Created May 30, 2019 09:24
My default rustfmt config
edition = "2018"
enum_discrim_align_threshold = 20
fn_single_line = true
imports_indent = "Visual"
inline_attribute_width = 70
max_width = 70
reorder_impl_items = true
struct_field_align_threshold = 8
tab_spaces = 2
unstable_features = true
@TrinityCoder
TrinityCoder / Cargo.toml
Last active July 20, 2022 17:40
Rust: Converting Vec<String> into a C-style 'char**' array to be used in libc library calls, such as in libc::execvp()
# Build by running `cargo make`
# or `cargo build`.
#
# Run by `cargo run`.
[package]
name = "experiment"
version = "0.1.0"
edition = "2018"
@TrinityCoder
TrinityCoder / arg_separators.rb
Last active May 18, 2019 15:50
This is the original Ruby script just slightly adjusted so that it runs with today's Ruby. ORIGINAL: https://github.com/textmate/cmake.tmbundle/blob/926867a414c1125abefa38161d82d71756f591a2/Support/arg_separators.rb
#!/usr/bin/env -vS ruby -wKU
commands = `/usr/bin/env cmake --help-command-list`.lines
commands.shift # Skip version number
constants = []
commands.each do |cmd|
cmd = cmd.strip.upcase
help = `/usr/bin/env cmake --help-command #{cmd}`
@TrinityCoder
TrinityCoder / FindLibiberty.cmake
Last active May 8, 2019 15:14
CMake module which finds libiberty (inlude dirs & library files) and makes it available to you via IMPORTED library target Libiberty::Libiberty.
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLibiberty
-------------
Find the libiberty library.
Libiberty is a C library usually distributed with gcc, gdb and binutils.
@TrinityCoder
TrinityCoder / FindThorsSerializer.cmake
Last active April 23, 2019 10:27
This CMake module finds the ThorsSerializer library (JSON & YAML C++ parser) - both include directory and .so file.
# ------------------------------------------------------------------------
# If target ThorsSerializer::ThorsSerializer does not exist, create it.
# We'll need to find two variables to do it:
#
# 1) ThorsSerializer_INCLUDE_DIR (i. e. /usr/local/include/ThorSerialize)
# 2) ThorsSerializer_LIBRARY (i. e. /usr/local/lib/libThorSerialize17.so)
# ------------------------------------------------------------------------
find_path(ThorsSerializer_INCLUDE_DIR
NAMES JsonThor.h YamlThor.h
PATH_SUFFIXES ThorSerialize)
@TrinityCoder
TrinityCoder / CMakeLists.txt
Last active August 11, 2019 17:23
Basic CMakeLists.txt contents I often use in my projects...
cmake_minimum_required(VERSION 3.8)
project(FakeDev VERSION 0.1 LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS Yes)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED Yes)
set(CMAKE_CXX_EXTENSIONS No)
@TrinityCoder
TrinityCoder / ukazkove_priklady.md
Last active January 26, 2017 06:53
Ukázkové příklady v C

Všechny následující programy kompilovat např. pomocí:

gcc -std=c99 -Wall -Werror -pedantic -g -o main main.c

(pokud jste kód zkopírovali do souboru jménem main.c).


Úloha 15. (oprava funkce print + vylepšení funkce add_to_data). Přidal jsem navíc funkci main + trochu omáčky na začátek, aby šel kód ihned spustit a byla vidět jeho funkčnost.

#include <stdio.h>
@TrinityCoder
TrinityCoder / center_text_in_bash.md
Last active April 18, 2024 12:02
How to center text in Bash

Sometimes we might want to print some text in Bash and we might want it to be centered to the centre of the terminal. It is a cheap way how we can increase clarity of output of our script and make it look much more attractive.

The whole magic is hidden in a program called tput.

To get number of rows and cols of current terminal, we need just two simple shell substitutions:

    TERM_ROWS="$(tput rows)"
@TrinityCoder
TrinityCoder / ukazatele_v_c.md
Last active December 11, 2016 13:19
Ukazatele v C

V tomto článku bych se rád pokusil vysvětlit, co jsou to ukazatele v jazyce C a jak s nimi pracovat. Uvidíme, že se ve skutečnosti jedná o jednoduchý koncept, kterého není třeba se bát.

Co je to ukazatel?

Každý program spuštěný v operačním systému je načtený do paměti (RAM) a spuštěn. Operační paměť není nic jiného než posloupnost bajtů, z nichž každý má svoji adresu, což není nic jiného než obyčejné číslo (bez znaménka). 64-bitové operační systémy jsou charakteristické tím,