Skip to content

Instantly share code, notes, and snippets.

class HashTable
DEFAULT_BUCKETS_COUNT = 10
RESIZE_STORE_FACTOR = 2
def initialize
@buckets_count = DEFAULT_BUCKETS_COUNT
@store = Array.new(@buckets_count)
@size = 0
end
@vano468
vano468 / url_shortener.rb
Last active March 14, 2019 20:57
Url shortener application based on roda, redis and thin with fiber pool
#############
# Gemfile
#############
source 'https://rubygems.org'
gem 'rack', '>= 2.0'
gem 'roda'
gem 'thin'
gem 'rack-fiber_pool', github: 'alebsack/rack-fiber_pool'
@vano468
vano468 / server.rb
Last active January 29, 2017 13:49
Simplest implementation of rack compatible web server
require 'socket'
require 'http_tools'
require 'sinatra/base'
require 'sinatra/cookies'
class Server
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 3000
def self.run(app, **options)
class Container
module Dependent
def dependencies(*deps)
@dependencies ||= []
deps.each { |d| @dependencies << d }
@dependencies.uniq!
end
end
attr_reader :instances
data Error = ParsingError | IncompleteDataError | IncorrectDataError String
deriving (Show, Eq)
data Person = Person { firstName :: String, lastName :: String, age :: Int }
deriving (Show, Eq)
parsePerson :: String -> Either Error Person
parsePerson = validatePerson . buildPerson (Right $ Person "" "" (-1)) . parse where
trim = unwords . words
@vano468
vano468 / wercker.yml
Last active May 24, 2016 11:18
Wercker EB deploy
deploy:
steps:
- script:
name: create necessary folders
code: |-
mkdir -p $HOME/.aws
mkdir -p $WERCKER_SOURCE_DIR/.elasticbeanstalk
- create-file:
name: setting up AWS credentials
filename: $HOME/.aws/credentials
@vano468
vano468 / restaurant.sql
Last active April 22, 2021 04:47
restaurant oracle
SET SERVEROUTPUT ON
/*
* dishes table
*/
DROP TABLE dishes;
DROP SEQUENCE dishes_seq;
CREATE TABLE dishes (
module PerformAsync
extend ActiveSupport::Concern
included do
def method_missing(method, *args, &block)
parts = method.to_s.split('_')
async_method_to_call = parts[0...-1].join('_')
if parts.last == 'async' && self.class.async_method_allowed?(async_method_to_call) && !async_method_to_call.empty?
perform_method_async async_method_to_call, args, block
else
findMissedValues = (arr) ->
result = []
findWithBinarySearch result, arr, 0, arr.length - 1
result
findWithBinarySearch = (result, arr, from, to) ->
from = to if from > to
if (from == to && arr[to] != to)
diffPosition = arr[to] - to - 1
diffNeighbor = if diffPosition == 0
# Preparation
# gem install sinatra
# gem install timezone
#
# Launch
# RACK_ENV=production ruby time_utc.rb
#
# Check working
# curl http://localhost:4567/time?Moscow,New%20York
#