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 MassUpdateWorker | |
| include Sneakers::Worker | |
| QUEUE_NAME = MassUpdatePublisher::QUEUE_NAME | |
| from_queue QUEUE_NAME, arguments: { 'x-dead-letter-exchange': "#{QUEUE_NAME}-retry" } | |
| def work(msg) | |
| data = ActiveSupport::JSON.decode(msg) | |
| data["mutations"].each do |mutation | | |
| update_balance(mutation.to_h) |
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
| # config/initializers/sneakers.rb | |
| require 'sneakers' | |
| require 'sneakers/handlers/maxretry' | |
| module Connection | |
| def self.sneakers | |
| @_sneakers ||= begin | |
| Bunny.new( | |
| addresses: ENV['BUNNY_AMQP_ADDRESSES']&.split(','), | |
| username: ENV['BUNNY_AMQP_USER'], |
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 MassUpdatePublisher | |
| QUEUE_NAME = 'user.mass_update_using_csv'.freeze | |
| def initialize(mutations) | |
| @mutations = mutations | |
| end | |
| def publish(options = {}) | |
| channel = RabbitQueueService.connection.create_channel | |
| exchange = channel.exchange( |
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 RabbitQueueService | |
| def self.logger | |
| Rails.logger.tagged('bunny') do | |
| @@_logger ||= Rails.logger | |
| end | |
| end | |
| def self.connection | |
| @@_connection ||= begin | |
| instance = Bunny.new( |
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
| sudo apt-get update | |
| sudo apt-get install apt-transport-https ca-certificates curl software-properties-common | |
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
| sudo apt-key fingerprint 0EBFCD88 | |
| sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
| sudo apt-get update | |
| sudo apt-get install docker-ce |
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
| version: '2' | |
| services: | |
| rabbitmq: | |
| image: rabbitmq:alpine | |
| ports: | |
| - 5672:5672 | |
| - 15672:15672 |
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 UserController < ApplicationController | |
| def index | |
| @user = User.all | |
| render json: @user, each_serializer: UserSerializer | |
| end | |
| def mass_update | |
| update_using_csv(params[:csv]) |
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 gensim.models import Word2Vec | |
| import re | |
| import pickle | |
| import numpy as np | |
| def tokenize(sentence): | |
| remove_dots = re.sub("[.]", "", sentence.lower()) | |
| return re.findall("[A-Za-z]{2,}", remove_dots) | |
| def w2v_tfidf(sentence, w2v_model, tfidf_model): |
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 gensim.models import Word2Vec | |
| import re | |
| def tokenize(sentence): | |
| remove_dots = re.sub("[.]", "", sentence.lower()) | |
| return re.findall("[A-Za-z]{2,}", remove_dots) | |
| def w2v_average(sentence, w2v_model): | |
| words = tokenize(sentence.lower()) | |
| sum_w2v = 0 |
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
| import pandas as pd | |
| from gensim.models import Word2Vec | |
| import logging | |
| import re | |
| # Diplay log | |
| logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO) | |
| # Load data | |
| data = pd.read_csv('training-data.csv', header=None) |
NewerOlder