Skip to content

Instantly share code, notes, and snippets.

View s8sg's full-sized avatar
🙌
Eventual Consistency

Swarvanu Sengupta s8sg

🙌
Eventual Consistency
View GitHub Profile
@s8sg
s8sg / GraphGist-SimpleRBAC.adoc
Last active August 18, 2020 05:27 — forked from mikesname/GraphGist-SimpleRBAC.adoc
Very simplistic way of doing role-based access control (RBAC) with Neo4j.

This is a very simple approach to doing role-based access control with Neo4j. It is optimistic, in the sense that all items are assumed to be world-readable unless they have specific constraints. Item visibility can be constrained to either individual users or all users who belong to a role. Roles are also hierarchical, so can inherit privileges from other roles.

This file is updated based on CYPHER guideline of 3.0

Setup:

Using docker is the easiest way to get started quickly

docker pull neo4j
@s8sg
s8sg / cache.py
Created June 8, 2017 06:56
A cache dict implementation with object level timeout
import time
import collections
class Cache(collections.MutableMapping):
def __init__(self, timeout=1, *args, **kwargs):
self.__store = dict()
self.__time_table = dict()
self.__time_out = timeout
@s8sg
s8sg / airports.json
Created July 24, 2017 03:08 — forked from tdreyno/airports.json
JSON data for airports and their locations
This file has been truncated, but you can view the full file.
[
{
"code": "AAA",
"lat": "-17.3595",
"lon": "-145.494",
"name": "Anaa Airport",
"city": "Anaa",
"state": "Tuamotu-Gambier",
"country": "French Polynesia",
"woeid": "12512819",
@s8sg
s8sg / lockless_counter.c
Created November 8, 2017 07:36
Lockless Counter
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>
#include<stdbool.h>
#include<time.h>
#define SYNC_INCREASE_COUNT(var_ref, temp) while(true) {temp=*var_ref; if(__sync_bool_compare_and_swap(var_ref, temp, (temp + 1))) {break;}pthread_yield();}
#define sync_increase_count(var_ref, mutex_ref) pthread_mutex_lock(mutex_ref);*var_ref=*var_ref+1;pthread_mutex_unlock(mutex_ref);
@s8sg
s8sg / single_p_multi_c_buffer.c
Last active September 4, 2022 10:03
A blazing fast single producer multiple consumer lockless queue
/* NOTE: The design decision of the req pool is tuned to get the
* best possible performance. Below point describes
* the design decisions:
* >> reqpool is a buffer queue where the producer adds at the start
* and consumers consume from the end
* >> it is strictly one consumer and multiple producers queue
* >> It is unbounded queue and avoids any resource allocation on heap
* >> It is lockless and use atomic operation to avoid race condition
* for consumers
*/
@s8sg
s8sg / multi_p_single_c.c
Created November 14, 2017 10:17
A blazing fast multi producer single consumer lockless buffer queue
#include <stdbool.h>
#include <pthread.h>
#define EMPTY(pool) pool->end == NULL;
/* pool_node_t must be the last member of data item that needs
* to be added in the queue:
*
* typedef struct mydata {
* ....
* pool_node_t node;
@s8sg
s8sg / protocol_proxy_parser.c
Created January 31, 2018 03:09
a sample code to parse the protocol proxy header (v1/v2)
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@s8sg
s8sg / fassinate-use-case.md
Last active April 5, 2018 08:28
a user-case and design desc for fassinate

Facinate Daemon:

Provide Conf: $ cat /usr/local/fasinate/fasinate.conf

{
     "api" : {
         "port": 80,
         "enable": true
     },
@s8sg
s8sg / getting_started_openfaas_in_mac.md
Last active April 23, 2018 03:53
Start Openfaas in MAC from scratch