Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / setsqsdestination.rb
Created March 22, 2023 16:08
set SQS destination. MWS is dead, but spapi likely uses a similar pattern.
business = Business.find(1)
client = business.mws
subscriptions = client.subscriptions.list_subscriptions(VDBMWS::SELLER_MARKETPLACE_US).parse.dig("SubscriptionList", "member")
subscriptions.pretty
subscriptions.each do |sub|
sqs_queue_url = sub.dig("Destination", "AttributeList", "member", "Value")
notif_type = sub.dig('NotificationType')
Rails.logger.info("client.subscriptions.delete_subscription(#{notif_type}, #{sqs_queue_url}, #{VDBMWS::SELLER_MARKETPLACE_US})")
puts client.subscriptions.delete_subscription(notif_type, sqs_queue_url, VDBMWS::SELLER_MARKETPLACE_US).parse
@blairanderson
blairanderson / jpg2png.sh
Last active March 19, 2023 18:34
jpg2png watcher script
#!/bin/bash
# Cleanup product images
# This will convert images from JPG to PNG and replace the white
# background with transparent one.
#
# SEEDED GPT4 a copy of the script from http://tech.natemurray.com/2007/12/convert-white-to-transparent.html
# Set source folder and extension
SRC_EXT=jpg
@blairanderson
blairanderson / index.mjs
Last active February 16, 2023 16:32
default / generic website scraping
import scrape from 'website-scraper'; // only as ESM, no CommonJS
const options = {
urls: ['https://www.something.com'],
recursive: true,
directory: '/public',
prettifyUrls: true,
ignoreErrors: true,
requestConcurrency: 4,
subdirectories: [
{directory: 'img', extensions: ['.jpg', '.png', '.svg']},
@blairanderson
blairanderson / rails_bootstrap.md
Last active January 28, 2023 17:00
new rails applications

create the app

RUN rails new your_app_name --database=postgresql --skip-jbuilder --master --javascript=esbuild --css=bootstrap --version 7.0.4 --skip-bundle

install javascript

RUN ./bin/rails javascript:install:esbuild

install css/bootstrap

RUN ./bin/rails css:install:bootstrap

create github repo

@blairanderson
blairanderson / ffmpeg-concat-mp4-videos.sh
Created November 1, 2022 14:52
ffmpeg concat mp4 videos
ffmpeg -i dockyard-diagonal.mp4 -i ship-up.mp4 -i dockyard-up.mp4 -i ship-pan.mp4 -i shipping-cranes.mp4 \
-filter_complex "[0:v] [1:v] [2:v] [3:v] [4:v]
concat=n=5:v=1:a=0 [vv] " \
-map "[vv]" mergedvideo.mp4
@blairanderson
blairanderson / netlify-cra-errors.txt
Last active August 16, 2022 16:10
Create React App netlify npm ERR! code ERESOLVE
8:33:29 AM: Build ready to start
8:33:31 AM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
8:33:31 AM: build-image tag: v4.10.1
8:33:31 AM: buildbot version: aa4e1c51618610360476c8cb99b22ac3191f186e
8:33:31 AM: Fetching cached dependencies
8:33:31 AM: Failed to fetch cache, continuing with build
8:33:31 AM: Starting to prepare the repo for build
8:33:31 AM: No cached dependencies found. Cloning fresh repo
8:33:31 AM: git clone https://github.com/blairanderson/kw-perm-builder
8:33:31 AM: Preparing Git Reference refs/heads/main
@blairanderson
blairanderson / rails-pg-stat-tables.rb
Created January 12, 2022 21:28
get some data from pg_stats
result_set = ApplicationRecord.connection.select_all("select * from pg_stat_user_tables")
column_types = result_set.column_types.dup
columns = result_set.columns.dup
results = result_set.rows.map { |row| columns.zip(row).to_h }
puts JSON.pretty_generate(results)
@blairanderson
blairanderson / parameterize.rb
Created January 9, 2022 03:59
rails / ruby parameterize
class String
def parameterize(separator: "-")
# Turn unwanted chars into the separator.
self.gsub!(/[^a-z0-9\-_]+/i, separator)
unless separator.nil? || separator.empty?
if separator == "-"
re_duplicate_separator = /-{2,}/
re_leading_trailing_separator = /^-|-$/i
else

New M1 Setup - Terminal / Homebrew / Rails

  1. Locate the Terminal application within the Utilities folder. Either (Finder > Go menu > Utilities) or open /Applications/Utilities/ in your terminal
  2. Select Terminal.app and right-click on it, then choose “Duplicate”
  3. Rename the duplicated Terminal app something obvious and distinct, like Rosetta Terminal
  4. Now select the freshly renamed Rosetta Terminal app and right-click and choose “Get Info” (or hit Command+i)
  5. Check the box for “Open using Rosetta”, then close the Get Info window
  6. Restart the Rosetta Terminal, which fully supports Homebrew and other x86 command line apps