Skip to content

Instantly share code, notes, and snippets.

@csghone
csghone / enable_if_t.cpp
Last active October 19, 2021 12:58
Example for enable_if_t
// Ref: https://en.cppreference.com/w/cpp/types/enable_if
#include <type_traits>
#include <iostream>
struct TypeTrue {
static constexpr bool enable_if_condition = true;
};
struct TypeFalse {
@csghone
csghone / socat_telnet_example.sh
Created June 23, 2020 07:37
Telnet communication via STDIN/STDOUT using socat
#!/bin/bash
HOST=192.xxx.xxx.xxx
PORT=1234
echo 'some_string' | socat - EXEC:"telnet $HOST $PORT",pty,setsid,ctty | tail -n +5
@csghone
csghone / photography.md
Last active March 11, 2025 06:33
photography

Summary

  • High level explanation of basic photography terminology as well as optics and imaging in general
  • References to give a non-mathematical, intuitive understanding of optics and imaging
  • Corrections/Additions are welcome

Focal length of lenses

@csghone
csghone / listen_udp.sh
Created May 20, 2020 06:55
UDP listener using socat
#!/bin/bash
# listen_feed.sh 224.0.31.130 14382 ens6d1 out_file
# Runs: socat udp-datagram:224.0.31.130:14382,bind=:14382,ip-add-membership=224.0.31.130:ens6d1 /dev/null > out_file
UDP_ADDRESS="224.0.31.130"
UDP_PORT="14382"
INTERFACE="ens6d1"
if [ $# -ne 3 ] && [ $# -ne 4 ]; then
@csghone
csghone / .vimrc
Last active August 18, 2022 09:45
Minmal vimrc
" If startup is slow - change clipboard options
" Show line/row/col numbers
set showcmd " This should be before nocompatible or nocp
set nu
set ruler
set laststatus=2
set incsearch
set history=10000
@csghone
csghone / using_cffi_module.py
Last active May 7, 2020 07:03
CFFI Python Example - Part 2/2
from cffi_example.lzo_ext import ffi, lib
# `compressed_data` is `bytes` array
# `compressed_data_len` is int
uncompressed_data = ffi.new("char[]", 10000)
ret_val = lib.decompress(compressed_data, compressed_data_len, uncompressed_data)
@csghone
csghone / generate_cffi_example_module.py
Last active May 7, 2020 07:03
CFFI Python Example - Part 1/2
# Generate module `cffi_example` using `python3 generate_cffi_example_module.py`
import os
from cffi import FFI
ffi = FFI()
person_header = """
unsigned int decompress(const uint8_t* raw_data, size_t compressed_size, uint8_t* decompressed_data);
"""
@csghone
csghone / logging_exceptions_argparsing_retry_in_python.py
Last active June 18, 2020 02:16
Python - Logging, Exceptions, ArgParse, Retry sample code
#!/usr/bin/env python3
"""
eg:
python3 ./logging_exceptions_argparsing_retry_in_python.py -w -x opt1 -y 3 -z 1 2 3 -f ~/.bashrc -d 20190101 --inp_datestring 20191101
"""
from __future__ import print_function
import os
import sys
import argparse
@csghone
csghone / iptables.sh
Created December 20, 2019 07:33
Few IPTABLES commands
# Block internet access and limit SSH to single host to user 'vnc'
# NOTE: This is not a perfect implementation, it can be worked around.
sudo iptables -A OUTPUT -p tcp -m tcp --dport 80 -m owner --uid-owner vnc -j DROP
sudo iptables -A OUTPUT -p tcp -m tcp --dport 443 -m owner --uid-owner vnc -j DROP
sudo iptables -A OUTPUT ! -d 192.168.101.168/32 -p tcp -m tcp --dport 22 -m owner --uid-owner vnc -j REJECT --reject-with icmp-port-unreachable
@csghone
csghone / parse_binary_construct.py
Last active November 28, 2019 12:00
Parse binary data in structures in contstruct
#!/usr/bin/env python3
# https://github.com/construct/construct - actively developed
import construct
from construct import RepeatUntil, Struct, Bytes, Int16ub, Int8ub, Construct, Const, Computed, BitStruct, BitsInteger
Test = Struct(
"const_val" / Const(b'AB'),
"bit_fields" / BitStruct('b1' / BitsInteger(4), 'b2' / BitsInteger(3), 'b3' / BitsInteger(1)),
"variable_array_length" / Int8ub,