Skip to content

Instantly share code, notes, and snippets.

View cesartalves's full-sized avatar

César Alves cesartalves

View GitHub Profile
@cesartalves
cesartalves / notes.rb
Last active September 13, 2022 17:21
Solidus Importer Redesign Notes / Sketch
# SolidusImporter::Row now has a `entity_id` field.
# It helps aggregate rows that belong to the same "entity" (Order for now) so we can process them together.
# With this, there's no need to maintain a huge context inside the `ProcessRow` job any longer.
# So how might we?
# lib/solidus_importer/process_row.rb
# 1. Associate the Row with an `Identifier` we an use to group related rows together
def prepare_rows(data)
messages = check_data(data)
@cesartalves
cesartalves / delete_users.rb
Last active September 12, 2022 18:00
Delete Users
# GET file from Importer url on dashboard
url = ''
file_data = Net::HTTP.get URI(url)
csv = CSV.parse(
file_data,
headers: true,
encoding: 'UTF-8',
header_converters: ->(h) { h.strip }
# GET file from Importer url on dashboard
url = ''
file_data = Net::HTTP.get URI(url)
csv = CSV.parse(
file_data,
headers: true,
encoding: 'UTF-8',
header_converters: ->(h) { h.strip }
@cesartalves
cesartalves / parse.rb
Created July 15, 2022 14:33
Parse VNT Files Ruby
Dir.glob('*').each do |file|
content = File.read(file)
parsed_content = content.split("\n")[2].sub('BODY;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:', '')
.unpack('M').first.encode('utf-8', 'iso-8859-1')
IO.binwrite(file.gsub('vnt', 'txt'), parsed_content)
end
string = '1,2,3,4,5,6'
number = true
string.chars.each do |char|
if number && char.number? # pseudo-code
number = false
continue
else
if char.comma?
@cesartalves
cesartalves / client_example
Created July 8, 2021 18:03 — forked from sandro/client_example
Ruby select socket server. An example of a single-threaded, event-driven (select) server.
$ irb -r ./select_server
>> client.puts "hi"
=> nil
>> client.puts "bye"
=> nil
>> client.close
=> nil
>> exit
@cesartalves
cesartalves / whatever.rb
Created July 5, 2021 13:51
Run SQL query and save to CSV rails
results = ActiveRecord::Base.connection.execute(sql)
CSV.open('csv.csv', 'w+') do |f|
f << results[0].keys
results.each do |r|
f << r.values
end
end
@cesartalves
cesartalves / script.rb
Last active July 1, 2021 08:37
Update Tax Total / Shipping Total
# note: this assumes the order never gets recalculated
csv = CSV.read('maker-orders.csv', headers: true)
orders = []
csv.each do |context|
order = Spree::Order.find_by_number(context['Name'])
next if order.nil?
corrected = []
File.open('original.txt', 'r').each_line do |date|
new_date = Time.parse(date, '%Y-%m-%d %H%M%S')
if new_date.month == 6 && new_date.year == 2021
corrected << new_date.next_month.beginning_of_month
next
end
@cesartalves
cesartalves / .env
Last active April 13, 2021 09:44
Rails Conf k8s quick setup
# https://github.com/ddollar/forego
ASSET_HOST=localhost:3000
APPLICATION_HOST=localhost:3000
BCRYPT_COST=12
PORT=3000
RACK_ENV=development
RACK_MINI_PROFILER=0
SECRET_KEY_BASE=development_secret
EXECJS_RUNTIME=Node