Skip to content

Instantly share code, notes, and snippets.

@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];
@mgarg1
mgarg1 / Double_Dimension_Array_Class.cpp
Last active July 22, 2019 08:59
Double Dimension Array
// # define NDEBUG
# include <assert.h>
class array2D{
int rows,cols.**arr;
public:
// array2D():array2D(0,0,0){}
array2D(int r,int c,int val):rows(r),cols(c),arr(nullptr){
arr = new int *[rows];
// -*- 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
@mgarg1
mgarg1 / debugging_utilities.c
Last active December 6, 2017 08:03
Some of the debugging utilities
#ifdef assert
#undef assert
#endif
#define assert(expr,i) \
if (!(expr)) { \
std::cerr << "Error at line " << __LINE__ << ": " \
<< "assert(" #expr ");" <<"value of i: "<<i<< std::endl; \
exit(EXIT_FAILURE); \
}
#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;