Skip to main content

Posts

PyCache - A simple, yet extensible in memory Python caching library/framework

https://github.com/Abhisar/PyCache A Small library/extensible framework that aims to solve the problem of needing a cache while coding small/medium scale python projects without depending on 3rd party cache systems. PyCache This library aims to solve the problem of generic object(Python) caching without depending on 3rd party caching systems like Memcached or Redis for cases where it isn't really required. Library has been written in such a way it can be extensible by following standards through implementations of Python Abstract Base Classes. pycache folder  : It has all the base classes. One that ensures ensures all cache schemes follow a similar implemntation i.e https://github.com/Abhisar/PyCache/blob/master/pycache/BaseCache.py  and Other one is for the Objects to be cacheable they have to subclass this Base class  https://github.com/Abhisar/PyCache/blob/master/pycache/BaseCacheable.py CacheImplenations folder : This folder contains different caching schemes. Cur
Recent posts

DNS - Domain Name Subsytem (A very High Level Dive)

Many of us would already know what a DNS is but for starters, it is the thing that converts the URL to IP address when we to hit a URL. The part I want to focus is how underrated and much unknown is this system to people apart from the fact I mentioned above.  In fact, I am lucky enough to get an in-depth look at how crucial DNS system and how it forms the backbone of highly scalable distributed system where you agree to an SLA for some milliseconds or might less at InMobi. So this post is more focused towards starters and not so fancy because that's how it should be understood. Why is DNS important ? Imagine you have to deploy a service on the internet and you agree to your consumers for 100 or 200 ms latency  but an improper DNS setup or DNS query can add 200ms or up of latency and added to that your geolocation.Hence it becomes important to tune your DNS server to your need.Let's get into details. This is a very high-level view of things and people should explor

How HTTPS works- SSL/TLS

Difference between spin locks and semaphores--Some Notes

up vote down vote accepted Both manage a limited resource. I'll first describe difference between binary semaphore (mutex) and spin lock. Spin locks  perform a busy wait - i.e. it keeps running loop(In turn heavy CPU usage example is in Reactor usage of AsyncTaskExecutors): while (try_acquire_resource ()); ... release(); It performs very lightweight locking/unlocking but if the locking thread will be preempted by other which will try to access the same resouce the second one will simply try to acquitre resource untill it run out of it CPU quanta. On the other hand  mutex  behave more like: if (!try_lock()) { add_to_waiting_queue (); wait(); } ... process *p = get_next_process_from_waiting_queue (); p->wakeUp (); Hence if the thread will try to acquire blocked resource it will be suspended till it will be avaible for it. Locking/unlocking is much more heavy but the waiting is 'free' and 'fair'. Semaphore  is a lock that is allowed to

HTTP 2 and How does it matters

Since a decade or so we have been using HTTP 1.1 for all kind server requests in application layer.There are a lot of latency issues when we used that for our traditional request response approach and the only thing we have found is hacks around this old HTTP 1.1 to suffice or solve a particular problem. Hence that created a need for new version of HTTP which addresses all these issues at foundational protocol level. I have been reading and exploring this a lot lately and have some useful things listed out as I explored it and can help even a beginner figure out HTTP 2. HTTP 2 SPDY  is a networking protocol introduced by Google in 2009. Its aim was to decrease web latency(time interval between request and response) and increase security. HTTP/2 is a clone of SPDY. Google has now stopped developing SPDY and started working on HTTP/2 with the same ideas of SPDY. HTTP2 is a binary protocol where as HTTP1.1 is an text based protocol  Here is a simple explanation to it : 

Write a program such that given a BST,return the size of largest subtree that lies within a given range[a,b].

Write a program such that given a BST,return the size of largest subtree that lies within a given range[a,b]. N.B: This  exact question was asked in a Google interview.  This problem when looked at first looks simple and may be for some it it but for me when it wasn't because when I started coding it I got all confused between recursions and the flow the algorithm will take.So i started simple on pen and paper tried for a couple of hours and could make it work . Point to be noted here is that the following approach here I took is not the most  efficient way but yes it does works perfectly. Steps or rather my thoughts : I had to touch each node so that I can calculate the size of the subtree in case the tree below and the node itself lied in the range.And after i calculate it I have maintained a global variable that stores the current max and when new value comes it compares it with existing one and updates it with the max value between them. To do so ,we

Graphs - DFS

Its been a while I posted because I had been busy with other stuff.From now on i would be posting basically what I learn and how I implement it in my journey of preparing for the best interviews. Now I am going to implement GRAPH DFS algorithm. Graphs as we all know many people tend to fear as we implement but once you start  realising  the underlying beauty and power of the data-structure, you can not hold yourself implementing it. Graphs can be represented as 2 ways: Adjacency lists or Adjacency matrices. Here I use adjacency list because as i am using java it pretty easy to implement it using Collections framework. DFS is pretty simple : Start with a node timestamp it and go deep and deep until u cannot go anywhere and then timestamp it. Finally you would end up creating a forest of multiple trees(Starting nodes). Code below is self explanatory and if any one has any queries please let me know. And the algorithm is direct implementation of book by Cormen (Intro