This file contains 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
# Submits a feed to Walmart | |
# @param feed_data [Hash] data that will be submited with the feed | |
# @param type [String] Enum: "item" "RETIRE_ITEM" "MP_ITEM" "MP_WFS_ITEM" "MP_ITEM_MATCH" "MP_MAINTENANCE" "SKU_TEMPLATE_MAP" "SHIPPING_OVERRIDES" | |
def submit_feed(feed_data, type) | |
# To add a param to a multipart POST request you need to append the params to the URL | |
endpoint = "https://marketplace.walmartapis.com/v3/feeds?feedType=" + type | |
headers = self.api_client.headers.with_indifferent_access | |
uri = URI(endpoint) |
This file contains 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
# Simple tracking number class just to streamline scraped numbers and user created tracking | |
class Tracking | |
include ActiveModel::Model | |
validates :carrier, presence: true | |
validates :tracking_number, presence: true | |
validates :ship_date, presence: true | |
attr_accessor :carrier | |
attr_accessor :tracking_number |
This file contains 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
# Find files modified | |
# Only works before git add | |
modified_file_paths = %x(git diff --name-only).split("\n") | |
# Make sure zeitwerk doesn't surprise you | |
print(%x(bin/rails zeitwerk:check)) | |
# Loop through files and check syntax, print status | |
modified_file_paths.each do |path| | |
next if !path.include?('.rb') |
This file contains 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
seen = {} | |
def fib(n) -> int: | |
if n <= 2: | |
return 1 | |
if n not in seen: | |
seen[n] = fib(n - 1) + fib(n - 2) | |
return seen[n] |
This file contains 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
# Write a function, best_bridge, that takes in a grid as an argument. | |
# The grid contains water (W) and land (L). There are exactly two islands in the grid. | |
# An island is a vertically or horizontally connected region of land. | |
# Return the minimum length bridge needed to connect the two islands. | |
# A bridge does not need to form a straight line. | |
from collections import deque | |
def explore_first_island(r, c, grid): | |
rows = len(grid) | |
cols = len(grid[0]) |
This file contains 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
# This script helps calculate the total number of requests given a failure rate | |
# Example: 1,000,000 requests with a 33% failure rate will result in 492,536 retries | |
# This means it would take 1,492,536 requests to update 1M objects in an endpoint | |
# that has a 33% failure rate. | |
total_retries = 0 | |
requests = 1_000_000 | |
faliure_rate = 0.33 | |
attempt = 1 |
This file contains 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 'openssl' | |
require 'base64' | |
require 'json' | |
# Open certificate file | |
cert = OpenSSL::X509::Certificate.new(File.read('certificate.pem')) | |
modulus = cert.public_key.n.to_s(2) | |
modulus_b64 = Base64.urlsafe_encode64(modulus, padding: false) |
This file contains 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
AmzSpApi::SpApiClient.class_eval do | |
def request_lwa_access_token | |
newself = self.dup | |
newself.config = config.dup | |
newself.config.host = 'api.amazon.com' | |
data, status_code, headers = newself.super_call_api(:POST, '/auth/o2/token', | |
:header_params => { | |
'Content-Type' => 'application/x-www-form-urlencoded' |