Skip to content

Instantly share code, notes, and snippets.

Blair Anderson blairanderson

Block or report user

Report or block blairanderson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@blairanderson
blairanderson / convert-pdf-to-png.sh
Last active Jan 6, 2018
converting PDF to a png
View convert-pdf-to-png.sh
// for single item
convert -density 150 -antialias "input_file_name.pdf" -append -resize 1024x -quality 100 "output_file_name.png"
// for bulk
mogrify -format png -alpha off -density 150 -quality 100 -resize 1024 *.pdf
@blairanderson
blairanderson / raise-arg-error.md
Created Dec 21, 2017
Ruby Argument Error with Custom Message
View raise-arg-error.md

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 Jun 12, 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:
@blairanderson
blairanderson / image-to-multiple-sizes.md
Last active Oct 17, 2017
imagemagick single image to multiple sizes
View image-to-multiple-sizes.md
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 Sep 26, 2017
basic javascript bookmarklet
View bookmarklet.js
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 Sep 22, 2017
Amazon ASIN regex and Ruby for plucking asins from a textarea that is comma separated or newline separated
View rails_asins_regex.rb
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 Sep 18, 2017
Manufacturing / Shipping / Product Abbreviations
View mfr-abbrev.md

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 Aug 5, 2017
Fetching a GitHub Repo Readme with AJAX (example)
View github-readme.js
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 Jul 21, 2017
[Ruby][files,writing,frontmatter] How to create a frontmatter file for each week
View ruby-frontmatter-weekly.rb
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 "---"
You can’t perform that action at this time.