Skip to content

Instantly share code, notes, and snippets.

View willbuilds's full-sized avatar
💭
🏗️ 🚀 👨‍🚀 🌔 👽 🌡️ 🍑

Will Mulligan willbuilds

💭
🏗️ 🚀 👨‍🚀 🌔 👽 🌡️ 🍑
View GitHub Profile
@willbuilds
willbuilds / new-wsl-ubuntu-install.md
Last active February 3, 2022 05:20
Steps for setting up a new WSL ubuntu install (zsh|asdf|node|ruby|postgres|redis|docker

Before: always trust yourself

entering a password all the time sucks. This is maybe naughty but I like it :shrug

# open sudoers file in editor (nano)
sudo nano /etc/sudoers

in the edit append the following line

{% comment %}
Snippet 'responsive-content'
This snippet takes rich text content (ie product.description, article.content etc) and, where possible, adds responsive image markup
Requires snippet 'responsive-image' to be defined (https://gist.github.com/wmulligan87/d2065346592eb3929147dbeca342f64c)
Usage:
{% include 'responsive-content' with article.content %}
{% endcomment %}
{% comment %}
Place at bottom of DOM, before </body>
{% endcomment %}
{% comment %}
Article structured data
https://developers.google.com/search/docs/data-types/articles
{% endcomment %}
{% if template contains 'article' %}
{% comment %}
Use this snippet to add a responsive image to page.
Requires lazysizes.js
Specify Shopify image you want to make responsive in the "with" parameter (see examples below).
You can use following variables to customize the image
* type: specifies the type of image file being accessed (ie an image from content, a product image, or a theme asset image).
* default_size: size of placeholder image until full image is loaded (default: '150x')
@willbuilds
willbuilds / discrete_array_loop.rb
Created July 2, 2015 00:04
Pattern for handling array vs single
# value arg could be Array of objects, or single object
def print_this(value)
print = ''
(value.is_a?(Array) ? value : [value]).each do |v|
print += v
end
puts print
end
# eg
// General loadmasking for all ajax controls using jquery loadmask
// Prevents double requests and gives users better feedback ('Did i click that properly?'), especially on touch devices.
// On ajaxBefore (which equates to onclick in most cases) a mask will render over the target element
// On ajaxComplete the mask is destroyed.
// requires jquery.loadmask.js (@ https://code.google.com/p/jquery-loadmask/)
$(document).on('ajaxBefore', function(event, request) {
return $(event.target).mask('loading...');
}).on('ajaxComplete', function(event, request) {
return $(event.target).unmask();
@willbuilds
willbuilds / activerecord_association_custom_builder
Last active August 29, 2015 14:17
Custom builder method for an ActiveRecord association (Logic localised to has_many's class)
class Line << ActiveRecord::Base
belongs_to :group
belongs_to :product
def build_for_product(product_id)
product = Product.find(product_id)
line = Line.new(
:product => product,
:line_type => 'stock',
:quantity => 1,
@willbuilds
willbuilds / try_chain.rb
Last active August 29, 2015 14:14
Chain methods together in an Array (or string, split('.') ) and perform sequentially.Can be used to fetch related object's attributes without explicit ruby code (ie Front-End JS).NOTE: Will fallback to 'nil' instead of throwing error
## Controller
## value = send_chain(@activity, 'asset.product.code')
def try_chain(record, attrib)
attrib.split('.').inject(record) {|o, a| o = o.try(a); o }
end
## Model
## value = send_chain('asset.product.code')
@willbuilds
willbuilds / 0_reuse_code.js
Last active August 29, 2015 14:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console