Skip to content

Instantly share code, notes, and snippets.

@topin89
topin89 / lbf_extractor.py
Last active November 27, 2021 17:30
Extract files from LG Backup .lbf file
# For modern LG backup files use a script from here: https://github.com/Mysak0CZ/LBFtool
# with details from there https://forum.xda-developers.com/android/general/tool-lg-restore-com-lge-bnr-lbf-file-t4053579
# Fair warning, this script was designed for really old version of LGBackup and won't work on with new devices
# So, if you don't get what you wanted, try to use every data carving tools you can get
#
# Also, good person with nickname SEVENTY ONE recommends ExtractJPEG( https://www.gunamoi.com.au/soft/extractjpeg/download.html )
# To, well, extract JPG Images from a backup
# 0. You will need 7-zip context menu "Extract here".
@topin89
topin89 / get_processes_dlls_threads.py
Created June 12, 2018 20:52
For Windows, get all processes, theirs modules (aka DLLs) and threads in Python 3
#Based on recipe http://code.activestate.com/recipes/576362-list-system-process-and-process-information-on-win/
#also hosted here https://github.com/ActiveState/code/blob/master/recipes/Python/576362_List_System_Process_Process/recipe-576362.py
#by winterTTr Dong , http://code.activestate.com/recipes/users/4164498/
#updated by topin89
#License: MIT
from ctypes import c_long , c_int , c_uint , c_char , c_ubyte , c_char_p , c_void_p, c_size_t, c_ulong, c_wchar
from ctypes import windll
from ctypes import Structure
from ctypes import sizeof , POINTER , pointer , cast
@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),
@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 / 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 / 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 / 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 / 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 / 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 / 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};