This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CircularQueue { | |
constructor(size) { | |
this.size = size; | |
this.storage = Array.from(new Array(size)); | |
Object.seal(this.storage); | |
this.head = -1; | |
this.tail = -1; | |
} | |
queue(value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:10.14 | |
RUN mkdir /app | |
WORKDIR /app | |
RUN npm install [email protected] | |
COPY ./index.js . | |
CMD node ./index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flatten = <T>(arr: T[][]): T[] => ([] as T[]).concat(...arr); | |
test("flatten", () => { | |
expect(flatten([[1], [2], [3, 4]])).toEqual([1, 2, 3, 4]); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const groupBy = <T extends { [k in K]: string }, K extends string>( | |
arr: T[], | |
attr: K, | |
) => { | |
return arr.reduce<{ [k in T[K]]?: T[] }>((result, item) => { | |
const k = item[attr]; | |
if (result[k] === undefined) { | |
result[k] = []; | |
} | |
(result[k] as T[]).push(item); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uniq = <T>(arr: T[], fn: (el: T) => Object = (a) => a) => | |
arr.reduce<T[]>( | |
(acc, curr) => (acc.some((a) => fn(a) === fn(curr)) ? acc : [...acc, curr]), | |
[], | |
); | |
test("uniq", () => { | |
const deduped = uniq([{ a: 2 }, { a: -2 }], (el) => Math.abs(el.a)); | |
expect(deduped).toEqual([{ a: 2 }]); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Point = { | |
$type: "PlainPoint"; | |
x: number; | |
y: number; | |
}; | |
const removeRedundantPoints = (points: Point[]) => { | |
const redundantIndexes: number[] = []; | |
for (let i = 0; i < points.length - 2; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
from datetime import timedelta | |
from fabric.context_managers import settings | |
from fabric.contrib.files import sed, exists | |
from fabric.operations import sudo, run, put | |
from fabric.state import env | |
useful_software_list = [ | |
'htop', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
import base64 | |
import os | |
import tempfile | |
from smtpd import DebuggingServer | |
from json import loads, dumps | |
class TestSmtpServer(DebuggingServer): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest2 | |
from django import forms | |
class DynamicForm(forms.Form): | |
""" | |
Allows to alter fields amount and requireness via spec, e.g.: | |
form = DynamicFormSubclass(spec={ | |
'last_name': False, # Drops field from initial form | |
'gender': {'required': True}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*-coding: utf8 -*- | |
import unittest2 | |
from zope.interface import Interface | |
from zope.interface.declarations import implements, classImplements | |
class Storage(object): | |
CLASS_TEMPLATE = """ | |
class %(class_name)s(object): | |
def __init__(self, instance): |
NewerOlder