Skip to content

Instantly share code, notes, and snippets.

View Indy9000's full-sized avatar
🏠
Working from home

Indy M. Indy9000

🏠
Working from home
View GitHub Profile
@Indy9000
Indy9000 / merge_two_sorted_vectors.cc
Created February 8, 2017 16:12
Merge two sorted vectors
#include <iostream>
#include <vector>
std::vector<int> merge_vec(const std::vector<int>& v1, const std::vector<int>& v2){
std::vector<int> result;
if(v1.size()==0) return v2;
if(v2.size()==0) return v1;
std::size_t i = 0; //v1 indexer
@Indy9000
Indy9000 / median-of-two-sorted-vectors.cc
Created February 12, 2017 16:23
Median of two sorted vectors
// median of two sorted arrays
#include <iostream>
#include <vector>
#include <queue>
std::vector<int> merge(const std::vector<int>& v1, const std::vector<int>& v2){
std::vector<int> result(v1.size()+v2.size());
int i=0;
int j=0;
@Indy9000
Indy9000 / Vim Fu
Last active June 11, 2017 11:38
Lesser known Vim Magic
Execute currently saved .py file
`:! python %`
Count the number of words in the saved file
`:!wc %`
Read a file in to Vim
`:!r filename`
Insert output of a shell command to current file

docker save | gzip > .tar.gz zcat .tar.gz | docker load

This loads the docker image with as the name and tag. Have to set the tag after loading

@Indy9000
Indy9000 / ActiveObject.cpp
Last active November 13, 2017 16:06
Active Object Pattern
#include <functional>
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <iostream>
class Active {
public:
using Message = std::function<void()>;
@Indy9000
Indy9000 / index.html
Created April 17, 2019 08:34
barebones html template
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My HTML App Template</title>
<meta name="description" content="My HTML App Template">
<meta name="author" content="indy9000">
@Indy9000
Indy9000 / concurrency-kata.cpp
Created October 1, 2019 12:23
difference between threads and async
// worker threads vs async/futures
//
// This demonstrates that for heavy compute that require multiple workers that
// send the results in a queue to the caller, using async/futures is
// much simpler than using worker threads
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
@Indy9000
Indy9000 / my_shared_ptr.cpp
Created October 1, 2019 12:31
Implementing a simple shared_ptr class
// In C++11 we got shared pointer. The standard implementation is much more complete and robust,
// but here I show a barebones version of it to illustrate the main components.
// Behaviour: SharedPTR manages the lifetime of a pointer to a templated object
// SharedPTR can be used to share the pointed object among other SharedPTRs.
// When all of them have given up the pointed object, The SharedPTR deallocates the
// pointed object
// For this we use reference counting. And the main point is that the counter should be a shared object itself
// that would be shared among the SharedPTRs.
template<typename T>
@Indy9000
Indy9000 / remove-consecutive-sum-to-n.py
Created October 17, 2019 14:05
Given a linked list of integers, remove all consecutive nodes that sum up to n.
class Node():
def __init__(self, value, next=None):
self.value = value
self.next = next
# returns a node if the sum is n
def sumTo(n, node):
s = 0
while node != None:
s = s + node.value
@Indy9000
Indy9000 / n-queen-problem.py
Created October 17, 2019 19:58
This function solves the N Queen problem using backtracking
# This function solves the N Queen problem using
# Backtracking. It mainly uses solveNQUtil() to
# solve the problem. It returns false if queens
# cannot be placed, otherwise return true and
# placement of queens in the form of 1s.
# note that there may be more than one
# solutions, this function prints one of the
# feasible solutions.
def solveNQ():
board = [ [0, 0, 0, 0],