Skip to content

Instantly share code, notes, and snippets.

View devendranaga's full-sized avatar
🍈

Dev devendranaga

🍈
  • Bangalore
View GitHub Profile
@devendranaga
devendranaga / csvparser.cpp
Created December 12, 2018 05:14
simple CSV parser Class
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
class csvParse {
public:
csvParse(std::string input, std::vector<std::string> &output);
};
@devendranaga
devendranaga / ActionActor.cpp
Created December 24, 2018 14:56
Action and Actor design class
#include <iostream>
#include <thread>
#include <unistd.h>
template <typename T1, typename T2>
class action {
public:
int registerPeriodicAction(T1 *data, T2 *specificCtx)
{
d = data;
int list_add_tail(void *data)
{
struct linked_list *t;
t = malloc(sizeof(struct linked_list));
if (!t) {
return -1;
}
t->data = data;
#include <iostream>
#include <vector>
int main()
{
std::vector<int> ints;
int i;
for (i = 0; i < 100; i ++) {
ints.push_back(i);
@devendranaga
devendranaga / rsa_keygen.c
Last active December 26, 2019 06:45
generate RSA key pair and write them to a file (openssl)
/**
* Author: Devendra Naga (devendra.aaru@gmail.com)
* License: MIT
* Code failure paths are not taken care.. this program is only for demonstration purposes
*/
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
@devendranaga
devendranaga / arrow_keys.c
Created January 30, 2019 03:51
detect arrow keys in linux
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int getch (void)
{
int ch;
struct termios oldt, newt;
tcgetattr(STDIN_FILENO, &oldt);
@devendranaga
devendranaga / openssl_hashapi.cpp
Created February 5, 2019 02:31
create hash with openssl
/**
* Author: Devendra Naga <devendra.aaru@gmail.com>
*
* LICENSE MIT
*/
#include <iostream>
#include <string>
// for ERR_ functions
#include <openssl/err.h>
@devendranaga
devendranaga / README.md
Last active February 8, 2019 02:30 — forked from gburd/README.md
Hardening C code at compile time

Hardening C code

format

Adds the -Wformat -Wformat-security -Werror=format-security compiler options. At present, this warns about calls to printf and scanf functions where the format string is not a string literal and there are no format arguments, as in printf(foo). This may be a security hole if the format string came from untrusted input and contains %n.

-Wformat is usually added with the -Wformat=2 option to be more stricter.

stackprotector

#include <iostream>
#include <functional>
void f(int i)
{
std::cout << " called f" << std::endl;
}
class my_class {
private:
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
#include <functional>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>