Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / fromPdfToJpg
Created July 16, 2018 20:08 — forked from dvcama/fromPdfToJpg
bash: extract high-res images from pdf using imagemagick (recursively)
#!/bin/bash
# extract jpg from PDF
# based on a script edited by Purch
#####################################
if [ -z $1 ];then echo Give target directory; exit 0;fi
find "$1" -depth -name '*.pdf' | while read file ; do
directory=$(dirname "$file")
oldfilename=$(basename "$file")
@blairanderson
blairanderson / wysiwyg.md
Last active February 27, 2018 18:51
Easiest WYSIWYG implementation I have found. 2018 Edition

I found it very annoying how quickly these WYSIWYG editors go out of date.

The open sources ones have mostly rotted away, and the others are paid.

<% content_for :head do %>
  <%= stylesheet_link_tag('https://cdnjs.cloudflare.com/ajax/libs/Trumbowyg/2.9.4/ui/trumbowyg.css') %>
&lt;% end %&gt;
@blairanderson
blairanderson / convert-pdf-to-png.sh
Last active January 6, 2018 00:56
converting PDF to a png
// 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 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").