Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / gist:40eb58d41a7f8a4271f01e3453b69154
Created November 7, 2019 20:54
DIRECT FULFILMENT (lead time calculation)
1. download all orders from https://vendorcentral.amazon.com/hz/vendor/members/df/orders
2. Move column Y to column E
3. Remove timezone string from the columns D & E
4. column F =ROUND(24*(E2-D2),1)
@blairanderson
blairanderson / transfer.rb
Created November 5, 2019 19:00
Ruby / Rails transfer files from SFTP to FTP folder
# ftp_uri is calculated from environment variable and database encrypted account/password
class Transfer
def transfer
require 'net/sftp'
require 'net/ftp'
current_business = Business.find(business_id)
old_directory = "/orders/"
directory = "orders"
sftpuri = current_business.sftp_uri

Keybase proof

I hereby claim:

  • I am blairanderson on github.
  • I am blairanderson (https://keybase.io/blairanderson) on keybase.
  • I have a public key ASBO7gg1K05ibXO41y3bjm2-S6xY6ixX2Zft1TXd2wJNkwo

To claim this, I am signing this object:

@blairanderson
blairanderson / rails-query-by-email-domain.md
Created August 20, 2019 16:42
rails query email by domain

A simple way to add querying by email

# frozen_string_literal: true

module DomainQuery
  extend ActiveSupport::Concern

  class_methods do
 def by_email(domain=nil)
@blairanderson
blairanderson / rails-email-multiple.rb
Last active July 1, 2019 22:17
RAILS email input with multiple=true
# simple_form sends params inside an array
# ["first@email.com,second@email.com"]
def email_cc_list=(list)
write_attribute(:email_cc_list,
Array.wrap(list).first.split(",").uniq.join(",")
)
end
# is it possible the array ever holds more than 1 value?
@blairanderson
blairanderson / recipe.md
Last active June 23, 2019 00:26
Spring Rolls with Fresh Prawns and Spicy Peanut Dipping Sauce

Easy Peanut Dipping Sauce

  • 125g (1/2 cup) creamy peanut butter
  • 35g (2 tbsp) hoisin sauce
  • 20g (4 tsp) soy sauce
  • 1 clove garlic
  • 10g (2 tsp) Sriracha
  • 25g (2 tbsp) warm water
  • tablespoon crushed peanuts
  • sprinkle of crushed red pepper
@blairanderson
blairanderson / asin-to-dims.rb
Created March 16, 2019 00:27
get the product matches
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sellercentral.amazon.com/fba/profitabilitycalculator/productmatches?searchKey=B000I1TJW6&language=en_US&profitcalcToken=taco")
request = Net::HTTP::Get.new(uri)
request["Authority"] = "sellercentral.amazon.com"
request["Upgrade-Insecure-Requests"] = "1"
request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"
request["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
<mjml>
<mj-body background-color="#ccd3e0" font-size="13px">
<mj-section background-color="#fff" padding-bottom="20px" padding-top="20px">
<mj-column width="100%">
<mj-image src="https://www.andersonassociates.net/img/favicons/anderson-logo-large.png" alt="" align="center" border="none" width="100px" padding-left="0px" padding-right="0px" padding-bottom="10px" padding-top="10px"></mj-image>
<mj-text align="center" color="#356cc7" font-size="13px" font-family="Helvetica" padding-left="25px" padding-right="25px" padding-bottom="28px" padding-top="28px">
<span style="font-size: 28px">Anderson & Associates</span><br/>
<span style="font-size: 20px">Invoice [[InvoiceDate]]</span>
</mj-text>
</mj-column>
@blairanderson
blairanderson / downloader.rb
Created January 28, 2019 23:38
ActiveStorage Downloader takes attachment input and yields a tempfile
# frozen_string_literal: true
module ActiveStorage
class Downloader #:nodoc:
def initialize(blob, tempdir: nil)
@blob = blob
@tempdir = tempdir
end
def download_blob_to_tempfile
@blairanderson
blairanderson / ruby_module_with_class_instance.rb
Created November 13, 2018 21:00
Ruby Module with Class and Instance methods extended
module Persistence
def self.included(klass)
klass.extend(ClassMethods)
end
module ClassMethods
def all
puts 'all'
end