Skip to content

Instantly share code, notes, and snippets.

@egoarka
egoarka / org.eclipse.jdt.core.prefs
Last active December 3, 2018 13:11
format streams and lamdas eclipse config | chain method calls eclipse
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.lineSplit=80
org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
@egoarka
egoarka / eba.sh
Created November 30, 2018 13:38
JS alike destructuring assignment for bash
echo "33:34" | awk -F':' '{ print $1, $2 }' | read a b <<< (cat)
read c d <<< $(echo "21:22" | awk -F':' '{ print $1, $2 }')
@egoarka
egoarka / collect.js
Last active November 18, 2018 19:30
collect all dependencies from js file
const s = process.argv[2];
const searchString = (string, pattern) =>
string
.match(new RegExp(pattern.source, pattern.flags))
.map(match => new RegExp(pattern.source, pattern.flags).exec(match));
console.log(
searchString(s, /require\(\'(.*)'\)/gi)
.map(([_, r]) => r)
.join(' '),
@egoarka
egoarka / .bash
Created October 13, 2018 19:18
This will clean and configure your packages
sudo apt-get update
sudo apt-get clean
sudo apt-get autoremove
sudo apt-get update && sudo apt-get upgrade
sudo dpkg --configure -a
sudo apt-get install -f
@egoarka
egoarka / nested_arrays_mongodb.js
Last active September 5, 2018 20:50
working on nested arrays in mongodb
/*
{
name,
tags: [{
name,
subtags: [{
name
}]
}]
}
@egoarka
egoarka / iterator.cpp
Created May 29, 2018 09:33
simple iterator for container
#include <iostream>
#include <fstream>
using namespace std;
template <typename T>
class Vector {
private:
T* data;
int _size;
@egoarka
egoarka / notmaybe.js
Last active April 14, 2018 22:53
notmaybe
const data = { user: { address: { street: "my street" } } };
const data2 = { user: {} };
const proxy = obj => new Proxy(obj, { get });
const get = (t, p) =>
t && t[p] && (typeof t[p] === "object") ? proxy(t[p]) : t[p] ? t[p] : "";
const safe = obj => proxy(obj);
var out = safe(data).user.address.street;
var out2 = safe(data2).user.address.street;
console.log(out); // my street
@egoarka
egoarka / load_json_files_from_directory.js
Created April 3, 2018 14:50
load_json_files_from_directory.js
const { promisify } = require("util");
const { resolve } = require("path");
const fs = require("fs");
const readdir = promisify(fs.readdir);
const rename = promisify(fs.rename);
const stat = promisify(fs.stat);
const readfile = promisify(fs.readFile);
async function getFiles(dir) {
const subdirs = await readdir(dir);
@egoarka
egoarka / pureswap.js
Last active March 19, 2018 19:34
pureswap.js
const swap = (arr, id, id2) => {
const left = { [id2]: arr[id] };
const right = { [id]: arr[id2] };
return Object.assign([...arr], left, right);
}