Skip to content

Instantly share code, notes, and snippets.

@userx007
userx007 / print_sync.cpp
Created February 20, 2026 10:44
C++ threadsafe printout
#include <syncstream>
#include <iostream>
template<typename... Args>
void print_sync(Args&&... arg)
{
std::osyncstream out(std::cout);
(out << ... << arg) << "\n";
}
@userx007
userx007 / Sublime.txt
Last active February 20, 2026 10:53
Sublime Text settings
{
"font_size": 15,
"font_face": "Fira Code",
"trim_trailing_white_space_on_save": "all",
}
{
"cmd": ["bash", "-c", "g++ -pthread --std=c++20 \"${file}\" -o \"${file_base_name}\" -latomic && \"${file_path}/${file_base_name}\""],
"working_dir": "${file_path}",
"selector": "source.c++"
@userx007
userx007 / scp.txt
Created September 24, 2020 08:52
scp usage
Copy file from a remote host to local host SCP example:
$ scp username@from_host:file.txt /local/directory/
Copy file from local host to a remote host SCP example:
$ scp file.txt username@to_host:/remote/directory/
Copy directory from a remote host to local host SCP example:
$ scp -r username@from_host:/remote/directory/ /local/directory/
Copy directory from local host to a remote hos SCP example:
@userx007
userx007 / hexlifybins.cpp
Created July 7, 2020 15:54
Hexlify binary files from configuration
#include <fstream>
#include <iostream>
#include <vector>
#include <iterator>
#define CHUNK_SIZE (256U)
typedef std::vector<uint8_t> ByteBuffer;
/*
@userx007
userx007 / readline.cpp
Created July 7, 2020 05:55
Read from file line by line
#include <fstream>
std::ifstream infile("thefile.txt");
//-------------------------------------------
// Assume that every line consists of two numbers and read token by token:
int a, b;
while (infile >> a >> b)
{
// process pair (a,b)
}
@userx007
userx007 / dumper.c
Last active July 6, 2020 10:53
Small file dumper
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
static int dump(long address, long len);
static bool file2buffer(const char *pstrFileName, const char *pstrOpenMode, uint8_t **ppui8Buffer, uint32_t *puiBufSize);
static int dump(long address, long len)
@userx007
userx007 / strtol.c
Created July 4, 2020 18:46
string to long
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
typedef int (*CheckFct)(int);
bool isValidNumber( const char *str, CheckFct pFunc)
{
bool bIsNum = true;
@userx007
userx007 / checkheader.cpp
Created July 2, 2020 09:09
Check if a string starts with a specific header and if yes returns the content
#include <string>
#include <iostream>
std::string header("$$$:");
void check(std::string &teststring, std::string &header)
{
std::cout << "Testing: " << teststring << " if starts with header:" << header << std::endl;
if(0 == teststring.rfind(header, 0))
@userx007
userx007 / minimap.c
Created July 1, 2020 09:34
Minimal implementation of a dummy map in C
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#define NRELEM(x) (sizeof(x)/sizeof(x[0]))
#define INVALID_KEY_VALUE (0xFFFFFFFF)
/////////////////////////////////////////////////////////////////////
// TYPE DEFINITIONS
/////////////////////////////////////////////////////////////////////
#!/usr/bin/python
# How to install pySerial python library
#----------------------------------------
# 1.) install pip
# ----------------
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
# python get-pip.py
#
# 2.) install pySerial