Skip to content

Instantly share code, notes, and snippets.

View bluurn's full-sized avatar
💭
My other car is cdr

Vladimir Suvorov bluurn

💭
My other car is cdr
  • Xempus AG
  • Berlin
View GitHub Profile
@bluurn
bluurn / main.cpp
Last active April 5, 2019 19:52
CPP: make_shared and shared_ptr demo
#include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
#include <memory>
#include <cmath>
using namespace std;
const double PI = 3.14;
@bluurn
bluurn / serializable_struct.rb
Last active March 26, 2019 12:56
Ruby: Implement SerializableStruct
require 'json'
module SerializableStruct
class Dummy
def self.members
@members
end
def initialize(*vals)
vals.each_with_index do |val, idx|
@bluurn
bluurn / templates.cpp
Created March 1, 2019 14:05
CPP: Implementation of Sqr via templates
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;
template <typename T>
T Sqr(T x) {
return x * x;
@bluurn
bluurn / main.cpp
Created February 26, 2019 14:38
CPP: Implementation of Rational
#include <iostream>
#include <sstream>
#include <cmath>
#include <map>
#include <vector>
#include <set>
using namespace std;
class Rational {
@bluurn
bluurn / inject.js
Last active February 13, 2019 14:14
JS: Implement DI
/**
* Constructor DependencyInjector
* @param {Object} - object with dependencies
*/
var DI = function (dependency) {
this.dependency = dependency;
};
// Should return new function with resolved dependencies
DI.prototype.inject = function (func) {
@bluurn
bluurn / cartesian.js
Created February 5, 2019 10:15
JS: Implementation of Cartesian product
const cartesian = (...arrays) => arrays.reduce((cartesianPart, array) => (
[].concat(...
cartesianPart.map(cartesianPartTuple =>
array.map(it => cartesianPartTuple.concat(it))
)
)
), [[]]);
console.log(cartesian([1,2], [3,4], [5,6]))
@bluurn
bluurn / flatten.js
Created February 1, 2019 09:15
JS: Implementation of flatten
function flatten(arr) {
return arr.reduce((acc, it) =>
acc.concat((it instanceof Array) ? flatten(it) : it)
, [])
}
flatten([[[1, [1.1]], 2, 3], [4, 5]]);
@bluurn
bluurn / graph.js
Created January 30, 2019 09:15
JS: Implementation of Graph
class Graph {
constructor() {
this.adjList = new Map();
}
addVertex(v) {
this.adjList.set(v, []);
return this;
}
@bluurn
bluurn / tree.js
Created January 29, 2019 16:16
JS: Tree Implementation
function Node(data) {
this.data = data;
this.parent = null;
this.children = [];
}
function Tree(data) {
this._root = new Node(data);
}
@bluurn
bluurn / queue.js
Last active January 30, 2019 08:51
JS: Queue Implementation
class Queue {
constructor() {
this.items = [];
}
enqueue(obj) {
this.items.push(obj);
}
dequeue() {