Skip to content

Instantly share code, notes, and snippets.

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

Ivan Roth okiroth

🏠
Working from home
View GitHub Profile
@okiroth
okiroth / find_triplets.js
Last active September 2, 2020 16:10
Find ordered geometric progressions of 3 numbers in array. O(n)
function countTriplets(arr, r) {
let pairs = {}
let freq = {}
let count = 0
arr.reverse().forEach(a => {
let b = a * r
if (b in pairs) {
count += pairs[b]
}
if (b in freq) {
@okiroth
okiroth / BackEnd.js
Created December 4, 2017 23:30
Upload file with JS, no libraries, process and save it with Node.js locally and AWS bucket
post('/upload/photo', async (ctx, next) => {
// Check if a file was sent
if (!ctx.request.body || !ctx.request.body.files || !ctx.request.body.files.file || !ctx.request.body.files.file.path) {
throw new Error('No file provided.');
}
const file = ctx.request.body.files.file;
// Save the file locally on your server
export default class ExampleDirective {
constructor() {
this.template = '<div>{{ctrl.name}}</div>';
this.restrict = 'E';
this.scope = {};
this.controller = ExampleDirectiveController;
this.controllerAs = 'ctrl';
this.bindToController = true;
}
@okiroth
okiroth / flattArray.js
Created April 22, 2016 17:22
flatten array in javascript
var result = [];
for (var i = 0; i < source.length; ++i) {
for (var j = 0; j < source[i].length; ++j)
result.push(source[i][j]);
}
@okiroth
okiroth / gist:c6aa19ad33c8ac55a65970561e36c3a8
Created April 22, 2016 17:21
flatten array in Javascript
var result = [];
for (var i = 0; i < source.length; ++i) {
for (var j = 0; j < source[i].length; ++j)
result.push(source[i][j]);
}