This file contains hidden or 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 counterIncrement = (collector, char) => { | |
| const lastItemIndex = collector.length - 1; | |
| if(lastItemIndex === -1) { | |
| return [[char, 1]]; | |
| } | |
| if(collector[lastItemIndex][0] == char) { | |
| collector[lastItemIndex][1] += 1 | |
| } else { |
This file contains hidden or 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 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') | |
| ]); |
This file contains hidden or 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
| { | |
| "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", |
This file contains hidden or 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 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| |
This file contains hidden or 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
| image: ruby:2.4.3 | |
| stages: | |
| - test | |
| services: | |
| - postgres:latest | |
| variables: | |
| POSTGRES_DB: sw-test-db |
This file contains hidden or 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 Trie | |
| Node = Struct.new(:char, :children, :is_complete_word) | |
| attr_reader :root | |
| def initialize | |
| @root = Node.new('', {}, false) | |
| end | |
| def add_word(word) |
This file contains hidden or 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
| #!/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 |
This file contains hidden or 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 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 |
This file contains hidden or 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
| //= require jquery | |
| //= require jquery_ujs | |
| $(function() { | |
| var source = new EventSource('/stream'); | |
| source.addEventListener('counter', function(e) { | |
| $('body').after(e.data + '<br />'); | |
| }); | |
| }); |
This file contains hidden or 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
| require 'sinatra' | |
| set server: :thin | |
| get '/' do | |
| erb :welcome | |
| end | |
| get '/stream', provides: 'text/event-stream' do | |
| stream do |out| | |
| loop do |
NewerOlder