Skip to content

Instantly share code, notes, and snippets.

View RoyBellingan's full-sized avatar

Roy Bellingan RoyBellingan

View GitHub Profile
@RoyBellingan
RoyBellingan / fmt.cpp
Created July 5, 2022 10:05
Custom Formatter
#include <fmt/color.h>
#include <fmt/format.h>
#include <iostream>
struct X {
int id;
uint8_t r{1};
uint8_t g{2};
uint8_t b{3};
};
@RoyBellingan
RoyBellingan / rotary.ino
Last active July 1, 2022 10:57
Rotary Encoder, skipping arduino logic and using low level OS call to keep up with high interrupt rate
#include "Arduino.h"
constexpr double thickPerTurn = 1200;
constexpr double wheelCircum = 0.09538 * 3.14159265359; //in meter
constexpr double ticksDistance = wheelCircum / thickPerTurn;
//write also wheel tick for debug and calibration
constexpr int LCDPrintTick = true;
//which pin to use for reset
@RoyBellingan
RoyBellingan / LPS22HB.c
Last active June 24, 2022 12:48
Raspberry pi sensor hat temperature and pressure logger
/*
To autostart
crontab -e
* * * * * cd "/wherever you put the file/" && ./FILE_NAME
*/
#include "LPS22HB.h"
#include <bcm2835.h>
#include <math.h>
@RoyBellingan
RoyBellingan / ReasonableImageGallery.php
Created May 28, 2022 17:24
ReasonableImageGallery.php
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<style>
html,body {
text-size-adjust: none;
-webkit-text-size-adjust: none;
-moz-text-size-adjust: none;
-ms-text-size-adjust: none;
font-size:30px;
}
#include "enum.h" //this is https://github.com/aantron/better-enums https://raw.githubusercontent.com/aantron/better-enums/master/enum.h
#include "fmt/format.h"
#include <fmt/ranges.h> //of course remember to link -lmft
#include <vector>
BETTER_ENUM(Channel, int,
Red = 1,
Green = 1 << 2,
Blue = 1 << 3,
@RoyBellingan
RoyBellingan / mt.py
Created January 22, 2022 14:35
mt.py
#!/usr/bin/env python3
import logging
import threading
import time
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
@RoyBellingan
RoyBellingan / pmd.cpp
Last active September 7, 2021 03:29
poor man dig
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#ifndef NI_MAXHOST
#define NI_MAXHOST 1025
@RoyBellingan
RoyBellingan / post.md
Created February 21, 2021 00:27
post.md

Overview

"A web service is a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web. In a web service, the Web technology such as HTTP—originally designed for human-to-machine communication—is utilized for machine-to-machine communication, more specifically for transferring machine-readable file formats such as XML and JSON." -- Wikipedia

Example

#include <memory>
@RoyBellingan
RoyBellingan / readCSVRow.cpp
Last active February 15, 2021 22:49
readCSVRow.cpp
std::vector<QStringRef> readCSVRow(const QString& line, const QStringList& separator, const QStringList& escape) {
std::vector<QStringRef> part;
// newState = delta[currentState][event]
// rows are states
// columns are events:
// 0 = read separator
// 1 = read escape
@RoyBellingan
RoyBellingan / arab1.cpp
Created October 29, 2020 20:04
arab1.cpp
#include <codecvt>
#include <fmt/format.h>
#include <iostream>
#include <locale>
int main() {
std::string bytestring = "ئەرەب ئەلىفبەسى";
std::cout << bytestring << "\n";
fmt::print("{} contains {} byte, no idea of the char \n", bytestring, bytestring.size());