Skip to content

Instantly share code, notes, and snippets.

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / radio-html.md
Created Mar 11, 2017
5 star rating system HTML using radio buttons. credit to https://jsfiddle.net/leaverou/CGP87/
View radio-html.md
<fieldset class="rating">
    <legend>Please rate:</legend>
    <input type="radio" id="star5" name="rating" value="5" /><label for="star5" title="Rocks!">5 stars</label>
    <input type="radio" id="star4" name="rating" value="4" /><label for="star4" title="Pretty good">4 stars</label>
    <input type="radio" id="star3" name="rating" value="3" /><label for="star3" title="Meh">3 stars</label>
    <input type="radio" id="star2" name="rating" value="2" /><label for="star2" title="Kinda bad">2 stars</label>
    <input type="radio" id="star1" name="rating" value="1" /><label for="star1" title="Sucks big time">1 star</label>
</fieldset>
@blairanderson
blairanderson / extract.rb
Created May 14, 2020
write JSON file data to multiple files [ruby]
View extract.rb
require 'active_support'
require 'active_support/core_ext'
require 'json'
JSON.parse(File.open("./_data/companies.json").read).each do |company|
File.open("./_companies/#{company['name'].parameterize}.md", "w") do |f|
f.write "---\n"
f.write "layout: company\n"
f.write "title: #{company['name']}\n"
f.write "categories: prep\n"
@blairanderson
blairanderson / gist:f0b49fb84abfb56e32f13395ddba0196
Created Mar 5, 2020
idea for rails ETL with ActiveStorage
View gist:f0b49fb84abfb56e32f13395ddba0196
class HighAvailabilityETL < RailsFoo
has_one_attached :input
has_one_attached :translate_step1
has_one_attached :translate_step2
has_one_attached :translate_step3
has_one_attached :output
def runner
step1_errors = input_to_translate_step1! unless input.attached?
step2_errors = step1_to_step2! unless translate_step1.attached?
@blairanderson
blairanderson / DependencyInjectionInRuby.md
Last active Dec 24, 2019
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache.
View DependencyInjectionInRuby.md

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?

@blairanderson
blairanderson / gist:40eb58d41a7f8a4271f01e3453b69154
Created Nov 7, 2019
DIRECT FULFILMENT (lead time calculation)
View gist:40eb58d41a7f8a4271f01e3453b69154
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 Nov 5, 2019
Ruby / Rails transfer files from SFTP to FTP folder
View transfer.rb
# 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
@blairanderson
blairanderson / jekyll.html
Last active Sep 27, 2019
Fullscreen Background Video Slideshow on iOS devices - note currently uses jquery :)
View jekyll.html
{% for video in site.static_files %}
{% if video.path contains 'img/videos' %}
<video muted playsinline>
<source src="{{ site.baseurl }}{{ video.path }}" type="video/mp4">
</video>
{% endif %}
{% endfor %}
@blairanderson
blairanderson / conv.sh
Last active Sep 11, 2019
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
View conv.sh
#! /bin/bash
# The Purpose of this Script is to batch convert and compress any video file to mp4 format
#
# WARNING: LOSSY COMPRESSION !!!
# Variable used:
# sourcedir is the directory where to be converted videos are. Converted video will be saved in the same folder
# usage:
View keybase.md

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:

You can’t perform that action at this time.