Skip to content

Instantly share code, notes, and snippets.

@carun
carun / Log.hpp
Created November 20, 2012 11:35
Singleton in a header only library
#include <iostream>
#include <stdint.h>
namespace Home { namespace Arun {
class Log
{
public:
static void Init(std::string& logPath, std::string& logFilename,
int32_t maxFileSize);
@carun
carun / Makefile
Created November 20, 2012 11:45
Advanced options in makefile
mode := release
CC := gcc
v := 0
cov := 0
arc := 64
ifeq ($(cov), 0)
else
COV_CFLAGS = -fprofile-arcs -ftest-coverage
COV_LFLAGS = -lgcov
endif
@carun
carun / gist:4117614
Created November 20, 2012 12:20
Explode in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char **explode(char *string, char separator, int *arraySize)
{
int start = 0, i, k = 0, count = 2;
char **strarr;
for (i = 0; string[i] != '\0'; i++){
/* Number of elements in the array */
@carun
carun / gist:4117631
Created November 20, 2012 12:24
Multithreaded application to process files in a directory
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <pthread.h>
#define NAME_MAX (256)
/* #define MAX_THREADS (99) */
@carun
carun / Inkpot.xml
Created July 8, 2013 11:57
Inkpot color scheme with dark background for QtCreator.
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme version="1.0" name="Inkpot (Dark)">
<style name="Text" foreground="#cfcfcf" background="#141414"/>
<style name="Link" foreground="#409090"/>
<style name="Selection" foreground="#ffffff" background="#4e4e8f"/>
<style name="LineNumber" foreground="#5f5fff" background="#2e2e2e"/>
<style name="SearchResult" foreground="#000000" background="#ffef0b"/>
<style name="SearchScope" foreground="#000000" background="#f8fafc"/>
<style name="Parentheses" foreground="#ffff00" background="#4e4e8f"/>
<style name="CurrentLine" foreground="#000000" background="#2d2d32"/>
@carun
carun / multithreaded-bind.c
Last active November 21, 2019 22:07
Sample code to illustrate multiple threads binding on the same port using SO_REUSEPORT option introduced in kernel 3.9. Here is the LWN article on the same https://lwn.net/Articles/542629/
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <pthread.h>
void* do_work(void *arg)
{
@carun
carun / API.md
Created December 9, 2016 01:22 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

import std.stdio; [59/187]
// import std.math;
import core.stdc.stdio;
import core.stdc.math;
enum pi = 3.141592653589793;
enum solar_mass = (4 * pi * pi);
enum days_per_year = 365.24;
struct Planet {
@carun
carun / memcpyd-output.log
Created June 14, 2018 05:59
memcpyd output for Mike Franklin
Intel(R) Core(TM) i7-6770HQ CPU @ 2.60GHz
16 GB RAM
---
dmd memcpyd.d
./memcpyd
size memcpyC memcpyD
1 38096 26341
2 40524 27605
@carun
carun / gist:09e332dea6b6c99cc3d678e6d261e321
Created July 16, 2018 09:28 — forked from luckydev/gist:b2a6ebe793aeacf50ff15331fb3b519d
Increate max no of open files limit in Ubuntu 16.04 for Nginx
# maximum capability of system
user@ubuntu:~$ cat /proc/sys/fs/file-max
708444
# available limit
user@ubuntu:~$ ulimit -n
1024
# To increase the available limit to say 200000
user@ubuntu:~$ sudo vim /etc/sysctl.conf