Skip to content

Instantly share code, notes, and snippets.

class StressTestOrders
def call(order_number, amount)
logger = Logger.new('log/stress_test_orders.log')
200.times do
order = Spree::Order.find_by_number(order_number)
new_order = Spree::Cart::Create.call(user: order.user, store: nil, currency: nil)
new_order = new_order.value
new_order.email = order.email
new_order.ship_address = order.ship_address.dup
@Vchekryzhov
Vchekryzhov / image_embeding.py
Created October 26, 2022 19:52
Image embeding module
from torchvision.io import read_image
from torchvision.models import resnet50, ResNet50_Weights
import torch
import glob
import pickle
from tqdm import tqdm
from PIL import Image
def pil_loader(path):
# ПРЕДВАРИТЕЛЬНАЯ ОБРАБОТКА ИЗОБРАЕНИЙ. Некоторые изображения из датасета представленны не в RGB формате, необходимо их конверитровать в RGB
@Vchekryzhov
Vchekryzhov / remove-snaps.sh
Created October 12, 2021 11:28
remove snaps
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
###########################################################
#################### Rubocop Rspec ########################
###########################################################
# You can find all configuration options for rubocop-rspec here: https://docs.rubocop.org/rubocop-rspec/cops.html
RSpec/AnyInstance:
Enabled: false
RSpec/BeforeAfterAll:
###########################################################
#################### Rubocop Rails ########################
###########################################################
# You can find all configuration options for rubocop-rails here: https://docs.rubocop.org/rubocop-rails/cops_rails.html
Rails/ActiveRecordCallbacksOrder:
Enabled: true
Rails/AfterCommitOverride:
@Vchekryzhov
Vchekryzhov / puma.service
Created June 29, 2021 18:16
Rails puma user service
#~/.config/systemd/user/puma.service
#systemctl --user status|start|stop puma
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/www/PROJET_NAME/current
Environment=RAILS_ENV=production
ExecStart=/home/${USER}/.rbenv/bin/rbenv exec bundle exec puma
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import NMF
from sklearn.decomposition import PCA
from sklearn.decomposition import TruncatedSVD as SVD
from sklearn.metrics import mean_absolute_error as mae
from sklearn.metrics import explained_variance_score as evs
from sklearn.metrics import mean_squared_error as mse
@Vchekryzhov
Vchekryzhov / max_multiplication.rb
Last active February 22, 2020 15:49
max multiplication
# negative numbers are also taken into code
def max_multiplication(str)
return nil if !str.is_a?(String)
multipliers = CircularBuffer.new(4)
negative_factor = 1
max_multiplication = nil
str.each_char do |char|
if char == '-' && negative_factor == 1
@Vchekryzhov
Vchekryzhov / .rubocop.yml
Last active August 17, 2022 21:43
rubocop
# inherit_from:
# - ".rubocop-rspec.yml"
# - ".rubocop-rails.yml"
# require:
# - rubocop-rails
# - rubocop-rspec
AllCops:
TargetRubyVersion: 3
@Vchekryzhov
Vchekryzhov / carrier_wave recreate
Created February 13, 2019 15:50
carrierwave recreate
YourModel.find_each do |ym|
begin
ym.process_your_uploader_upload = true # only if you use carrierwave_backgrounder
ym.your_uploader.cache_stored_file!
ym.your_uploader.retrieve_from_cache!(ym.your_uploader.cache_name)
ym.your_uploader.recreate_versions!(:version1, :version2)
ym.save!
rescue => e
puts "ERROR: YourModel: #{ym.id} -> #{e.to_s}"
end