Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / algolia-searchbox-debounce.md
Last active November 17, 2023 02:55
Algolia Search Debounce Example (using debounce with the algolia instant search.)

queryHook is a hook function that provides the query, and the search callback. You can do your own debouncing or special logic here.

default debounce example:

var timeout = 500;

var queryHook = _.debounce(function(query, search){
  search(query)
},timeout);
@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 / 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 / simple_form_textarea_rows_columns.md
Created January 14, 2015 01:57
Simple_form Textarea Rows Columns

You need to do this

<%= f.input :message, :input_html => {:rows => 10} %>
<%= f.input :description, :as => :text, :input_html => { 'rows' => 5, 'cols' => 10 } %>
@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 / DependencyInjectionInRuby.md
Last active September 3, 2022 04:41
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache.

Dependency Injection in Ruby 07 Oct 04

Introduction

At the 2004 Ruby Conference, Jamis Buck had the unenviable task to explain Dependency Injection to a bunch of Ruby developers. First of all, Dependency Injection (DI) and Inversion of Control (IoC) is hard to explain, the benefits are subtle and the dynamic nature of Ruby make those benefits even more marginal. Furthermore examples using DI/IoC are either too simple (and don’t convey the usefulness) or too complex (and difficult to explain in the space of an article or presentation). I once attempted to explain DI/IoC to a room of Java programmers (see onestepback.org/articles/dependencyinjection/), so I can’t pass up trying to explain it to Ruby developers.

Thanks goes to Jamis Buck (the author of the Copland DI/IoC framework) who took the time to review this article and provide feedback.

What is Dependency Injection?