Skip to content

Instantly share code, notes, and snippets.

View esnosy's full-sized avatar

Eyad Ahmed esnosy

  • Egypt
  • 09:57 (UTC +03:00)
View GitHub Profile
@esnosy
esnosy / write_eigen_matrix_as_pgm_image.cpp
Created October 4, 2023 19:31
Write Eigen Matrix as PGM image
constexpr size_t N = 900;
Eigen::Matrix<uint8_t, -1, -1> output(N, N);
output.fill(255);
std::ofstream ofs("output.pgm", std::ofstream::binary);
ofs << "P5\n"
<< N << ' ' << N << "\n255\n";
// Otherwise the image will be flipped due to how PGM file format is layed out
output.rowwise().reverseInPlace();
ofs.write(reinterpret_cast<char *>(output.data()), N * N * sizeof(uint8_t));
@esnosy
esnosy / asan.cmake
Last active October 1, 2023 18:26
CMake snipped to enable ASAN for MSVC and non-MSVC in Debug config correctly 😊
if(MSVC)
target_compile_options(eigen_vis_cpp PRIVATE $<$<CONFIG:RelWithDebInfo,Debug>:/fsanitize=address>)
elseif()
target_compile_options(eigen_vis_cpp PRIVATE $<$<CONFIG:RelWithDebInfo,Debug>:-fsanitize=address -fno-omit-frame-pointer>)
target_link_options(eigen_vis_cpp PRIVATE $<$<CONFIG:RelWithDebInfo,Debug>-fsanitize=address>)
endif()
@esnosy
esnosy / skip_line.cpp
Created September 28, 2023 01:05
A skip_line function for std::ifstream
static void skip_line(std::ifstream &ifs)
{
// Thanks to Eljay and CPPReference
// https://stackoverflow.com/questions/53693218/how-to-skip-a-line-of-standard-input#comment94242047_53693218
// https://en.cppreference.com/w/cpp/string/basic_string/getline#Notes
// ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
// also thanks to https://stackoverflow.com/a/72365435/8094047
// and https://jdhao.github.io/2018/12/08/newline_vim_python_sublime_notepad/
// Skip all characters until newline or carriage return
@esnosy
esnosy / fast_foreach_set_vertices.py
Created September 16, 2023 12:02
Ultra fast setting vertices locations of Blender mesh in Python, faster than foreach_set
import numpy as np
import ctypes
def fast_foreach_set_vertices(mesh: bpy.types.Mesh, array: NDArray):
# Ultra fast vertices setting
# Thanks a ton!: https://blender.stackexchange.com/a/298488/53664
# beware all things could go wrong here!
assert array.dtype == np.float32
assert len(array.shape) == 1
@esnosy
esnosy / naf_simple_jump.js
Last active August 25, 2023 02:18
networked-aframe simple jump component
// License Public Domain
// These constants are arbitrary but make sure they do not accidentally collide with other things
const animationAttributeName = 'animation__onkeydown_space';
const animationStartEvent = 'onkeydown_space';
AFRAME.registerComponent('simple-jump', {
schema: {},
init: function () {
var el = this.el;
// Thank you!!!: https://stackoverflow.com/a/47019444/8094047
// https://stackoverflow.com/a/51050251/8094047
@esnosy
esnosy / numpy_binary_search_on_disk.py
Created August 22, 2023 19:41
binary search numpy sort and search on disk
import mmap
from struct import Struct
from multiprocessing import Pool
import numpy as np
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
@esnosy
esnosy / timer.hpp
Created June 30, 2023 22:40
Neat TIMER macro for C++11
# GPLv3 iyadahmed430@gmail.com (Iyad Ahmed)
#pragma once
#include <chrono>
#include <functional>
void time_function(const char *message, std::function<void()> function)
{
auto start = std::chrono::high_resolution_clock::now();
@esnosy
esnosy / settings.json
Last active June 30, 2023 16:26
My VSCode settings
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnType": false
},
"cmake.configureOnOpen": true,
"editor.fontFamily": "'Fira Code', 'IntelOne Mono', 'JetBrains Mono', 'Cascadia Code', 'Droid Sans Mono', 'monospace', monospace",
"workbench.tree.indent": 20,
"cSpell.userWords": [
"AABB",
@esnosy
esnosy / cpp_11_generic_byte_swap.hpp
Last active March 7, 2023 18:42
Generic integer byte swap function for C++11, C++23 already has one https://en.cppreference.com/w/cpp/numeric/byteswap
#pragma once
#include <type_traits>
template <typename Integer,
std::enable_if_t<std::is_integral<Integer>::value, bool> = true>
static Integer swap_bytes(Integer value)
{
Integer out;
for (int i = 0; i < sizeof(value); i++)
@esnosy
esnosy / qt_rhel8.sh
Last active February 16, 2023 17:15
Dependenceis needed to run the Qt online installer on RHEL 8 Linux
# All expect last dependency were covered in this answer: https://forum.qt.io/post/636988
sudo apt-get install libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxkbcommon-x11