Skip to content

Instantly share code, notes, and snippets.

@topin89
topin89 / CMakeLists.txt
Last active March 20, 2023 19:21
Shape area count benchmark
cmake_minimum_required(VERSION 3.0.0)
project(unclean VERSION 0.1.0)
set (CMAKE_CXX_STANDARD 17)
add_executable(shape_bench main.cpp)
@topin89
topin89 / userscript.js
Last active October 15, 2019 19:48
Marking text in textarea with b and i tags
// ==UserScript==
// @name Notabenoid bbcode shortkey
// @namespace http://notabenoid.zapto.org/
// @version 0.1
// @description enter something useful
// @match http://notabenoid.zapto.org/*
// @copyright 2019, topin89@mail.ru
// ==/UserScript==
function changeSel(chr) // javascript
@topin89
topin89 / writepxm.cpp
Last active November 6, 2019 09:01
Write PGM or PPM images (Portable Graymap and Portable Pixmap)
#include <fstream>
#include <iostream>
#include <string>
void writeppm(char const * const image_buffer,
int const image_size,
int const width,
int const height,
std::string const filename){
std::ofstream file{filename, std::ios::binary};
@topin89
topin89 / README.txt
Last active July 8, 2019 15:21
How to create access point using network manager
# https://unix.stackexchange.com/a/384513
# by
# https://unix.stackexchange.com/users/10349/ysdx
hostname@user:~$ nmcli d
DEVICE TYPE STATE CONNECTION
wlp3s0 wifi connected InternetSSID
wlx8416f91eade2 wifi disconnected -- #your future AP
enp2s0 ethernet unavailable --
@topin89
topin89 / reflash_tolerant.ino
Last active December 21, 2018 14:20
Save some variables across all Arduino resets and most reprogrammings without EEPROM
struct SaveableData{
uint32_t update_counter;
};
struct UploadSafe{
char dummy[64];
uint32_t flag;
//Unless more than 64 bytes of global/static variables
//added/removed this will be saved
@topin89
topin89 / multidims.c
Last active December 16, 2018 16:14
Different way to create and zero-init multidimensional arrays
///bin/true;COMPILER_OPTIONS="-std=c99 -g -Wall -Wextra -O0";THIS_FILE="$(cd "$(dirname "$0")"; pwd -P)/$(basename "$0")";OUT_FILE="/tmp/build-cache/$THIS_FILE";mkdir -p "$(dirname "$OUT_FILE")";test "$THIS_FILE" -ot "$OUT_FILE" || $(which clang || which gcc) $COMPILER_OPTIONS -xc "$THIS_FILE" -o "$OUT_FILE" || exit;exec "$OUT_FILE" "$@"
///bin/true;COMPILER_OPTIONS="-g -Wall -Wextra --std=c11 -O3 -fsanitize=address,undefined";THIS_FILE="$(cd "$(dirname "$0")"; pwd -P)/$(basename "$0")";OUT_FILE="/tmp/build-cache/$THIS_FILE";mkdir -p "$(dirname "$OUT_FILE")";test "$THIS_FILE" -ot "$OUT_FILE" || $(which clang || which gcc) $COMPILER_OPTIONS -xc "$THIS_FILE" -o "$OUT_FILE" || exit;exec "$OUT_FILE" "$@"
// For windows dwellers like me, this will totally work in MSYS2, and most likely in Cygwin and MSYS.
// MSYS2 is better, though.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define xstr(a) str(a)
#define str(a) #a
@topin89
topin89 / infangle.cpp
Created October 30, 2018 11:33
converts [-180;+180] degree angle to (-inf;+inf)
#include <iostream>
class ContinuousAngle {
public:
auto &reset() {
trimmed_angle_ = 0;
turns_ = 0;
return *this;
}
@topin89
topin89 / multiprint.hpp
Last active October 25, 2018 07:47
handy print for Arduino
//example:
//multiprint("I = ")(10)("A")()("U = ")(10)("V")();
//result:
//I = 10A
//U = 20V
//
//arguments -- same as Serial.print
//no argument -- Serial.println()
@topin89
topin89 / static_counter.cpp
Last active August 22, 2018 11:54
C++ static counter (non standart, works for gcc, vc++, clang, icc)
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
#include <iostream>
void multiprint(){
static constexpr size_t base = __COUNTER__;
#define i (__COUNTER__ - base - 1)
std::cout << i << std::endl;
std::cout << i << std::endl;
std::cout << i << " " << i <<std::endl;
@topin89
topin89 / pilnplut.py
Created August 21, 2018 11:37
Custom lookup table for Pillow and Numpy
from PIL import Image
import numpy as np
IM_LUT=np.array([(255,255,255,255),(0,0,0,255),
(255,0,0,255),(0,255,0,255),(0,0,255,255),
(255,255,0,255),(255,0,255,255),(0,255,255,255),
(128,0,0,255),(0,128,0,255),(0,0,128,255),
(128,128,0,255),(128,0,128,255),(0,128,128,255),