Skip to content

Instantly share code, notes, and snippets.

@terminaldweller
terminaldweller / cstruct2luatable2.md
Last active August 14, 2020 21:04
C Struct to Lua Table

C Struct to Lua table

Overview

For this tutorial we'll change a C struct into a Lua table. The structure we'll be using won't be the simplest structure you'll come across in the wild so hopefully the tutorial will do a little more than just cover the basics.
We'll add the structures as userdata and not as lightuserdata. Because of that, we won't have to manage the memory ourselves, instead we will let Lua's GC handle it for us.
Disclaimer:

  • This turotial is not supposed to be a full dive into lua tables, metatables and their implementation or behavior. The tutorial is meant as an entry point into implementing custom Lua tables.

Yet Another One?

There are already a couple of tutorials on this, yes, but the ones I managed to find were all targeting older versions of lua and as the Lua devs have clearly stated, different Lua version are really different. The other reason I wrote this is I needed a structures that had structure members themselves and I couldn't find a tutorial for t

Lazy Makefiles

I kept finding myself needing to build some C or C++ code but I just couldn't be bothered to write a makefile from ground up. My life's too short for that. The code was either not that big of a deal or the build process was not anything complicated.
Yes, I'm lazy.
The alternative to writing a makefile is just typing in gcc or clang instead of make into the terminal. I know. The horror. It's 2018. What sort of a barbarian does that?
So I just decided to write a lazy makefile so I would never have to type in the name of my compiler of choice ever again. Mostly because that's what you do with things that you love. Forget about them until you need them. We're still talking about compilers and makefiles for your information. Don't go assuming things about my personal life.

First off, you can find the makefiles here. They are licensed under the Unlicense. And I'm using plural because there's one for C and one for C++.
Now t

@terminaldweller
terminaldweller / telegram-cli-i3.md
Created April 1, 2019 11:52
Telegrtam-cli and i3

Telegram-cli Notifications for i3wm

My first experience with a Linux desktop environment was gnome. It was fine, I guess, but I spent most of my time in the terminal so I never really learned where anythign was or how to do anything using gnome. I just had it.
Later on I got introduced to i3wm(i3 for short). Love at first sight.
I use vim, I use tmux, you'd think I already had enough tabs, panes, windows, sessions. You'd be most certainly wrong. After i3 I realised I still needed more.
I use telegram because friends, family, life.
It's annoying to have to pay attention to my cellphone(I know I'm a horrible person, no need to point that out). Having i3 notifications is just more convinient.
So the next obvious step was to get just that. Telegram-cli has both Python and Lua APIs. I used the Lua API. I have no reason whatsoever to back my decision up other than I just felt like doing it in Lua.
TL;DR.
A Telegram-cli Lua script has to implement a couple of hook functions(the

@terminaldweller
terminaldweller / wavelet.py
Last active May 31, 2021 00:17
different wavelet families and their results
#!/usr/bin/env python3
# _*_ coding=utf-8 _*_
import argparse
import code
import signal
import sys
# import numpy as np
import matplotlib.pyplot as plt
import pywt
#!/usr/bin/env python3
# _*_ coding=utf-8 _*_
import argparse
import code
import signal
import sys
import math
INFO global: Vagrant version: 2.2.17
INFO global: Ruby version: 3.0.1
INFO global: RubyGems version: 3.2.15
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_DEFAULT_PROVIDER="libvirt"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="/opt/vagrant/embedded"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_EXECUTABLE="/opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/bin/vagrant"
WARN global: resolv replacement has not been enabled!
INFO global: Vagrant version: 2.2.17
INFO global: Ruby version: 3.0.1
INFO global: RubyGems version: 3.2.15
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_DEFAULT_PROVIDER="libvirt"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_EXECUTABLE="/opt/vagrant/embedded/gems/2.2.17/gems/vagrant-2.2.17/bin/vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="/opt/vagrant/embedded"
INFO global: VAGRANT_INSTALLER_VERSION="2"
WARN global: resolv replacement has not been enabled!
/usr/bin/ld: ../lib/.libs/libshadow.a(libshadow_la-encrypt.o):/home/dev/Projects/git.zharfpouyan.net/router/shadow.git/4.10/lib/shadowlog_internal.h:2: multiple definition of `shadow_logfd'; ../lib/.libs/libshadow.a(libshadow_la-commonio.o):/home/dev/Projects/git.zharfpouyan.net/router/shadow.git/4.10/lib/shadowlog_internal.h:2: first defined here
/usr/bin/ld: ../lib/.libs/libshadow.a(libshadow_la-encrypt.o):/home/dev/Projects/git.zharfpouyan.net/router/shadow.git/4.10/lib/shadowlog_internal.h:1: multiple definition of `Prog'; ../lib/.libs/libshadow.a(libshadow_la-commonio.o):/home/dev/Projects/git.zharfpouyan.net/router/shadow.git/4.10/lib/shadowlog_internal.h:1: first defined here
/usr/bin/ld: ../lib/.libs/libshadow.a(libshadow_la-getdef.o):/home/dev/Projects/git.zharfpouyan.net/router/shadow.git/4.10/lib/shadowlog_internal.h:2: multiple definition of `shadow_logfd'; ../lib/.libs/libshadow.a(libshadow_la-commonio.o):/home/dev/Projects/git.zharfpouyan.net/router/shadow.git/4.10/lib/shadowlog_internal.h:2: fi
AR util-linux/lib.a
LINK busybox_unstripped
Static linking against glibc, can't use --gc-sections
Trying libraries: crypt m pam pam_misc resolv rt
Failed: -Wl,--start-group -lcrypt -lm -lpam -lpam_misc -lresolv -lrt -Wl,--end-group
Output of:
cc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os -static -ldl -o busybox_unstripped -Wl,--sort-common -Wl,--sort-section,alignment -Wl,--start-group applets/built-in.o archival/lib.a archival/libarchive/lib.a console-tools/lib.a coreutils/lib.a coreutils/libcoreutils/lib.a de
-bash-5.0# bash -c 'LD_LIBRARY_PATH=/debug/ LD_DEBUG=libs /debug/sshd -h'
1233: find library=libpam.so.0 [0]; searching
1233: search path=/debug/glibc-hwcaps/x86-64-v2:/debug/tls/x86_64/x86_64:/debug/tls/x86_64:/debug/tls/x86_64:/debug/tls:/debug/x86_64/x86_64:/debug/x86_64:/debug/x86_64:/debug (LD_LIBRARY_PATH)
1233: trying file=/debug/glibc-hwcaps/x86-64-v2/libpam.so.0
1233: trying file=/debug/tls/x86_64/x86_64/libpam.so.0
1233: trying file=/debug/tls/x86_64/libpam.so.0
1233: trying file=/debug/tls/x86_64/libpam.so.0
1233: trying file=/debug/tls/libpam.so.0
1233: trying file=/debug/x86_64/x86_64/libpam.so.0
1233: trying file=/debug/x86_64/libpam.so.0