Skip to content

Instantly share code, notes, and snippets.

View devendranaga's full-sized avatar
🍈

Dev devendranaga

🍈
  • Bangalore
View GitHub Profile
@devendranaga
devendranaga / threadpool.cc
Last active August 28, 2023 15:15
Thread pool with RR scheduling in C++
/**
* @brief - Thread pool implementation within 200 lines.
*
* @author - Devendra Naga (github.com/devendranaga/)
*
* @copyright - 2023-present.
* @license - GPLv2
*/
#include <iostream>
#include <queue>
@devendranaga
devendranaga / signalfd_example.c
Created June 20, 2015 06:06
signalfd() syscall example
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/signalfd.h>
int segv_handle()
{
printf("segv\n");
exit(0);
@devendranaga
devendranaga / gmac.c
Created January 22, 2023 18:26
GMAC openssl example
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <openssl/evp.h>
int main()
{
int ret = 0, unused = 0;
uint8_t key[] = {
@devendranaga
devendranaga / main.cpp
Created January 17, 2023 18:15 — forked from grejdi/main.cpp
Using openssl to encrypt and decrypt a message with public/private key.
using namespace std;
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <iostream>
#include <string>
int main()
{
@devendranaga
devendranaga / gcd.cc
Created October 8, 2019 16:24
Grand Central Dispatch in C++
/**
* @description GCD in C++
*
* @copyright 2019-present Devendra Naga (devnaga@tuta.io) All rights reserved
*/
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <thread>
@devendranaga
devendranaga / htons.rs
Created October 22, 2022 20:06
htons in rust
fn htons(val: &u16) -> u16 {
return ((val & 0x00FF) << 8) | ((val & 0xFF00) >> 8)
}
@devendranaga
devendranaga / rust_memcpy.rs
Created October 4, 2022 14:00
memcpy in rust
fn memcpy(src: &[u8], dst: &mut [u8], len: usize) {
let i: usize = 0;
while i < len {
dst[i] = src[i];
}
}
fn main() {
let buf: [u8; 10] = [1; 10];

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@devendranaga
devendranaga / nmea_checksum_creator.c
Created September 5, 2016 20:06
NMEA checksum calculator in C
#include <stdio.h>
#include <string.h>
int nmea0183_checksum(char *nmea_data)
{
int crc = 0;
int i;
// the first $ sign and the last two bytes of original CRC + the * sign
for (i = 1; i < strlen(nmea_data) - 3; i ++) {
@devendranaga
devendranaga / double_list.c
Created March 12, 2022 16:29
o(1) based double linked list implementation
#include <stdio.h>
#include <stdlib.h>
struct list {
void *data;
struct list *prev, *next;
};
static struct list *head, *last;