Skip to content

Instantly share code, notes, and snippets.

View lisovskyvlad's full-sized avatar

Lisovskii Vladislav lisovskyvlad

View GitHub Profile
const counterIncrement = (collector, char) => {
const lastItemIndex = collector.length - 1;
if(lastItemIndex === -1) {
return [[char, 1]];
}
if(collector[lastItemIndex][0] == char) {
collector[lastItemIndex][1] += 1
} else {
@lisovskyvlad
lisovskyvlad / promise_playground.js
Created March 18, 2019 17:49
Learning of promises
const f = (wait_count, string) => (
new Promise((res, rej) => (setTimeout(() => res(string), wait_count)))
);
async function sequence() {
const a = await Promise.all([
f(2000, '2000 wait'),
f(500, '500 wait'),
f(1000, '1000 wait')
]);
@lisovskyvlad
lisovskyvlad / titanic.json
Created February 11, 2019 11:30
Response from http://www.omdbapi.com/ for titanic
{
"Title": "Titanic",
"Year": "1997",
"Rated": "PG-13",
"Released": "19 Dec 1997",
"Runtime": "194 min",
"Genre": "Drama, Romance",
"Director": "James Cameron",
"Writer": "James Cameron",
"Actors": "Leonardo DiCaprio, Kate Winslet, Billy Zane, Kathy Bates",
@lisovskyvlad
lisovskyvlad / middle_rate.rb
Last active July 29, 2018 08:15
Ruby solution for the task mentioned in the article http://grishaev.me/why-clj
class MiddleRate
attr_reader :data
def initialize(data)
@data = data
end
def call
# age rates got { 18 => [30, 15], 50 => [35] }
age_rates = data.each_with_object(memory_hash) do |data_item, acc|
image: ruby:2.4.3
stages:
- test
services:
- postgres:latest
variables:
POSTGRES_DB: sw-test-db
class Trie
Node = Struct.new(:char, :children, :is_complete_word)
attr_reader :root
def initialize
@root = Node.new('', {}, false)
end
def add_word(word)
@lisovskyvlad
lisovskyvlad / download-url-to-file.rb
Created February 29, 2016 15:52 — forked from johnjohndoe/download-url-to-file.rb
Ruby script to download a number of files from individual URLs via HTTP/HTTPS/FTP specified in an external file.
#!/usr/bin/env ruby
#
# Ruby script to download a number of files
# from individual URLs via HTTP/HTTPS/FTP
# specified in an external file.
#
# Author: Tobias Preuss
# Revision: 2013-04-18 16:26 +0100 UTC
# License: Creative Commons Attribution-ShareAlike 3.0 Unported
@lisovskyvlad
lisovskyvlad / Dockerfile
Created December 22, 2015 09:33
Good example of dockerfile for ruby in drone.
FROM ruby:2.2
RUN gem update --system && gem install bundler
RUN sed -i 's/deb http:\/\/httpredir.debian.org\/debian jessie main/deb http:\/\/httpredir.debian.org\/debian jessie main non-free/' /etc/apt/sources.list
RUN sed -i 's/deb http:\/\/security.debian.org jessie\/updates main/deb http:\/\/security.debian.org jessie\/updates main non-free/' /etc/apt/sources.list
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - && apt-get install -y nodejs unrar && npm install -g phantomjs
@lisovskyvlad
lisovskyvlad / application.js
Created November 23, 2015 23:56 — forked from lexmag/application.js
Rails streaming
//= require jquery
//= require jquery_ujs
$(function() {
var source = new EventSource('/stream');
source.addEventListener('counter', function(e) {
$('body').after(e.data + '<br />');
});
});
@lisovskyvlad
lisovskyvlad / counter.rb
Created November 23, 2015 23:56 — forked from lexmag/counter.rb
Terribly simple Sinatra streaming
require 'sinatra'
set server: :thin
get '/' do
erb :welcome
end
get '/stream', provides: 'text/event-stream' do
stream do |out|
loop do