Skip to content

Instantly share code, notes, and snippets.

View mafayaz's full-sized avatar

Asif mafayaz

  • Utrecht, The Netherlands
View GitHub Profile
@mafayaz
mafayaz / arrayLeftRotate.cpp
Created October 18, 2016 09:55
Left rotate array
#include <boost/assign/list_of.hpp>
#include <vector>
using namespace std;
vector<int> array_left_rotation(vector<int> a, int n, int k) {
vector<int> rotated;
int index = k % n;
for(int i=index; i<n; i++)
{
@mafayaz
mafayaz / reverse_linkedlist.cpp
Last active October 11, 2016 14:41
reversing a linked list in C++
#include <iostream>
#include <vector>
using namespace std;
struct Node
{
int data;
struct Node *next;
};
@mafayaz
mafayaz / simpleRestfulHttpServerInPython
Created July 5, 2016 11:57
Writing Simple HTTP Server in Python (With REST and JSON)
There are many already existing powerful http servers that can be used in python e.g. gevent, twisted web server. However, they are a bit complex to use and you cannot start them in a thread other than the main thread.
Here is a sample of basic http server using "BaseHTTPRequestHandler". The example exposed two rest interfaces:
To ingest records into the web server
To retrieve already ingested records from the web server
The records are assumed to be JSON based, however, any type of records can be ingested.
[sourcecode language="python" wraplines="false" collapse="false"]
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer