Skip to content

Instantly share code, notes, and snippets.

Avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / DependencyInjectionInRuby.md
Last active Oct 17, 2020
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 / conv.sh
Last active Sep 26, 2020
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 / 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 / bs_toast.js
Last active Aug 23, 2020
Bootstrap 5 : jQuery Toast Builder
View bs_toast.js
var toastIDCounter = 0;
(function ($) {
$.fn.bsToast = function (options) {
if (typeof options === "string") {
options = {
body: options
}
}
var settings = $.extend({
@blairanderson
blairanderson / cleanup.rb
Created Aug 22, 2020
just some nasty file cleanup for an old computer
View cleanup.rb
require 'fileutils'
Dir.glob('/Documents/dev/*').each do |directory|
dir = directory.split("/").last
next if File.file?(dir)
is_git = false
git_remote = ""
has_changes = false
message = ""
@blairanderson
blairanderson / fetch.rake
Last active Jul 22, 2020
Rakefile for fetching the current dist/sass/etc folders from the bootstrap and tachyons GitHub repository
View fetch.rake
namespace :fetch do
desc "fetch tachyons scss files"
task :tachyons do
`curl -LkSs https://github.com/tachyons-css/tachyons-sass/archive/v4.7.1.tar.gz | tar xz`
`mv -f ./tachyons-sass-*/scss ./_sass/tachyons-sass`
`mv -f ./tachyons-sass-*/tachyons.scss ./_sass/tachyons-sass`
`rm -rf ./tachyons-sass-*`
end
desc "fetch bootstrap scss files"
@blairanderson
blairanderson / jekyll.html
Last active Jul 19, 2020
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 / 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"
You can’t perform that action at this time.