Skip to content

Instantly share code, notes, and snippets.

@mgarg1
mgarg1 / merge_pdf.py
Created October 14, 2026 10:58
Merge PDF in python
import os
from PyPDF2 import PdfMerger
def merge_all_pdfs_in_folder(folder_path, output_path):
merger = PdfMerger()
pdf_files = sorted([f for f in os.listdir(folder_path) if f.lower().endswith(".pdf")])
for pdf in pdf_files:
merger.append(os.path.join(folder_path, pdf))
@mgarg1
mgarg1 / raspberry pi GSM HAT
Last active October 23, 2021 19:48
my experiment with GSM HAT
import serial
import os, time
import RPi.GPIO as GPIO
#SERIAL_PORT = "/dev/ttyAMA0"
SERIAL_PORT = "/dev/ttyS0"
BAUD_RATE = 9600
GPIO.setmode(GPIO.BOARD)
@mgarg1
mgarg1 / Throttler.cpp
Last active February 13, 2020 06:28
Throttler with threads - t1 thread is for throttling, t2 is for just getting input (tail a file) main thread is controlling the influx
// https://onlinegdb.com/r1y2ERAfL
#include <chrono>
#include <fstream>
#include <sstream>
#include <iostream>
#include <thread>
#include <queue>
@mgarg1
mgarg1 / 2D_efficient_array.cpp
Last active August 22, 2019 10:52
efficient 2d array implementation refer : https://stackoverflow.com/a/936709/1496826
// based on https://stackoverflow.com/a/936709/1496826
template <typename T,typename sizeDim=size_t>
struct array2d{
T *arr;
sizeDim row,col;
array2d(sizeDim r,sizeDim c,T defVal=0):row(r),col(c){
arr = new T[r*c];
// -*- coding:utf-8-unix; mode:c; -*-
/*
get the active window on X window system
http://k-ui.jp/blog/2012/05/07/get-active-window-on-x-window-system/
*/
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
define hook-next
info locals
end
https://github.com/cs01/gdbgui
https://sourceware.org/gdb/onlinedocs/gdb/Hooks.html
https://sourceware.org/gdb/onlinedocs/gdb/Command-Files.html
https://github.com/mgarg1/gdb-dashboard
#include <string>
#include <iostream>
#define SWITCH(CASE, VALUE) case CASE : return VALUE;
#define LIST_OF_VARIABLES \
SWITCH(2 , "two") \
SWITCH(5 , "five") \
SWITCH(7 , "seven")
@mgarg1
mgarg1 / Facade_GOF.cpp
Last active March 2, 2017 18:47
Facade Design Pattern
//Facade
class Compiler {
public:
Compiler();
virtual void Compile(istream & , BytecodeStream & );
};
void Compiler::Compile(
istream & input, BytecodeStream & output
) {
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define INIT_VALUE 1.0f
pthread_mutex_t m;
float *getValue(){
static int is_initialized = 0;
@mgarg1
mgarg1 / APF2.cpp
Last active October 10, 2016 21:58
Abstract Factory Design Pattern GOF Book example
class WidgetFactory{
public:
virtual ScrollBar *createScrollBar() = 0;
virtual Window *createWindow() = 0;
};
class Window{
public:
virtual void Paint() = 0;
};