Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / raise-arg-error.md
Created December 21, 2017 22:02
Ruby Argument Error with Custom Message

If you want to raise an argument error with a clearer message

def process_thing(account: nil, thing: nil)
  raise(ArgumentError.new("processing requires an account")) if account.blank?
  raise(ArgumentError.new("Must have a Thing to process")) if thing.blank?
  # ... Do the actual work
end
@blairanderson
blairanderson / jekyll.html
Last active February 4, 2022 21:10
Fullscreen Background Video Slideshow on iOS devices - note currently uses jquery :)
{% 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 December 20, 2021 17:57
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
#! /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:
@blairanderson
blairanderson / image-to-multiple-sizes.md
Last active October 17, 2017 15:38
imagemagick single image to multiple sizes
convert input.png \
\( -clone 0 -resize 128x128 -write icon-128.png \) \
\( -clone 0 -resize 96x96 -write icon-96.png \) \
\( -clone 0 -resize 48x48 -write icon-48.png \) \
\( -clone 0 -resize 16x16 -write icon-16.png \)
@blairanderson
blairanderson / bookmarklet.js
Created September 26, 2017 23:34
basic javascript bookmarklet
javascript: var d = document,
w = window,
e = w.getSelection,
k = d.getSelection,
x = d.selection,
s = e ? e() : k ? k() : x ? x.createRange().text : 0,
f = 'http://awesomewebsite.com/bookmarklet/iframe',
l = d.location,
e = encodeURIComponent,
u = f + '?u=' + e(l.href) + '&t=' + e(d.title) + '&s=' + e(s) + '&v=4';
@blairanderson
blairanderson / rails_asins_regex.rb
Created September 22, 2017 23:14
Amazon ASIN regex and Ruby for plucking asins from a textarea that is comma separated or newline separated
class SomeController
def asin_params
# comma or semicolon, optionally surrounded by whitespace
# or
# two or more whitespace characters
# or
# any number of newline characters
String(params[:asins])
.split(/ \s*[,;]\s* | \s{2,} | [\r\n]+/x)
.select { |item| item.length > 8 }
@blairanderson
blairanderson / mfr-abbrev.md
Last active September 18, 2017 17:40
Manufacturing / Shipping / Product Abbreviations

https://en.wikipedia.org/wiki/Shelf-ready_packaging

The preparation of a product so that it is delivered to a retailer in a ready-to-sell merchandised unit.

  • SRP - Shelf-ready packaging
  • RRP - Retail-ready packaging
  • PAV - prêt-à-vendre
  • PDQ - Wal-Mart refers to them as PDQ ("Pretty Darn Quick").
@blairanderson
blairanderson / github-readme.js
Last active August 5, 2017 22:38
Fetching a GitHub Repo Readme with AJAX (example)
function success(data, status, xhr) {
$('#readme-content').html(data);
}
function error(data, status, xhr) {
$('#readme-content').remove();
}
$.ajax({
dataType: 'text',
@blairanderson
blairanderson / ruby-frontmatter-weekly.rb
Created July 21, 2017 18:52
[Ruby][files,writing,frontmatter] How to create a frontmatter file for each week
start_date = Date.today + 1.month
end_date = start_date + 2.years
(start_date..end_date).group_by(&:wday)[1].each do |day|
pathname = "_drafts/weekly/#{day.year}/#{day.strftime("%m-%d")}.md"
open(pathname, 'w+') do |post|
post.puts "---"
post.puts "layout: weekly"
post.puts "title: Black River Weekly - #{day.strftime('%B %d %Y')}"
post.puts "category: weekly"
post.puts "---"
@blairanderson
blairanderson / skins-colors.scss
Created March 31, 2017 17:51
Color stylesheet skins auto generate color and background from list of color
@import 'variables';
$color-list: 'brand-color' $brand-color,
'turquoise' #1abc9c,
'green-sea' #16a085,
'emerland' #2ecc71,
'nephritis' #27ae60,
'peter-river' #3498db,
'belize-hole' #2980b9,
'amethyst' #9b59b6,