Skip to content

Instantly share code, notes, and snippets.

@sshaw
sshaw / erb_test_fixture.rb
Last active March 9, 2024 02:32
Ruby module that allows you use ERB in your test/spec fixtures and easily load them
require "erb"
require "shellwords"
#
# Use ERB in your test fixtures and easily load them.
#
# By: Skye Shaw (https://github.com/sshaw)
# Date: 2016-06-30
# Source: https://gist.github.com/sshaw/f9bad743bb53d2439501d03fb6056a4c
#
@sshaw
sshaw / export-product-metafields.sh
Created January 5, 2022 03:57
Export the metafields of all products in your Shopify store to a JSONL file
#!/bin/bash
#
# Export the metafields for products in your Shopify store to a JSONL file.
# Can be modified to output to a file per product or to text file(s).
# See Shopify Development Tools (sdt) for more infomation.
#
# By ScreenStaring (http://screenstaring.com)
#
#
@sshaw
sshaw / gender_api.gemspec
Last active August 13, 2023 20:26
Ruby API client for the Gender API (https://gender-api.com)
Gem::Specification.new do |s|
s.name = "gender_api"
s.version = "0.0.1"
s.date = "2016-03-05"
s.summary = "API client for the Gender API"
s.description = "API client for the gender detection service Gender API: https://gender-api.com/en/api-docs"
s.authors = ["Skye Shaw"]
s.email = "skye.shaw@gmail.com"
s.files = Dir["*.rb"]
s.require_paths = ["."]
@sshaw
sshaw / print-non-existant-ignored-columns.rb
Last active July 29, 2023 17:15
Rails: Print What Models Have Ignored Columns That No Longer Exist in DB (Moved: https://github.com/sshaw/ignored_columns_tasks)
(ApplicationRecord.subclasses + ActiveRecord::Base.subclasses).each do |klass|
next if klass.abstract_class? || klass.ignored_columns.none?
ignored = klass.ignored_columns
klass.ignored_columns = []
klass.reset_column_information
removed = ignored - klass.column_names
klass.ignored_columns = ignored
next unless removed.any?
@sshaw
sshaw / skye-shaw-s-ruby-is-the-new-perl-guide-to-proc-and-lambda-s-and-some-random-shit.rb
Last active October 7, 2022 03:19
Skye Shaw's Ruby is the New Perl ™️ Guide to Procs and lambdas
# coding: utf-8
# Skye Shaw's Ruby is the New Perl ™️ Guide to Procs and lambda and Some Random Shit
lambda do
p 1
p 2
p 3
end[]
lambda {
@sshaw
sshaw / classes-with-diff-eql-==-behavior.md
Created October 26, 2014 16:17
Ruby Classes With Different Equality Behavior

Ruby Classes With Different ==, eql?, and === Behavior

Float

1.0 == 1     # true
1.0.eql? 1   # false
1.0 === 1    # true

IPAddr

@sshaw
sshaw / rspec-checksum-matchers.rb
Last active December 20, 2021 13:49
RSpec::Checksum::Matchers: Check if a String looks like a digest produced a the given hash algorithm. Also see https://github.com/sshaw/has_checksum
# RSpec::Checksum::Matchers Check if a String looks like a checksum produced by the given algorithm.
# https://gist.github.com/sshaw/df14f6f89860b2dbcfd2
#
# Copyright (c) 2016 Skye Shaw. Released under the MIT License (https://opensource.org/licenses/MIT)
#
require "rspec/expectations"
RSpec::Matchers.define :be_a_checksum do
regex = /\A[0-9a-f]{32,128}\z/i
chars = {
@sshaw
sshaw / gist:2298052
Created April 4, 2012 05:34
Mojolicious Twitter Bootstrap Flash/Stash Alerts
use Mojo::ByteStream;
app->helper(alerts => sub {
my $c = shift;
my $html = '';
for my $message (qw|success info error|) {
my $css = "alert alert-$message";
if($c->flash($message)) {
$html .= $c->tag('div', class => $css, $c->flash($message));
@sshaw
sshaw / shopify_api_retry.rb
Last active May 9, 2021 00:31
Ruby module to retry a Shopify API request if an HTTP 429 (too many requests) is returned. Moved to https://github.com/ScreenStaring/shopify_api_retry with GraphQL support
require "shopify_api"
#
# Retry a ShopifyAPI request if an HTTP 429 (too many requests) is returned.
#
# ShopifyAPIRetry.retry { customer.update_attribute(:tags, "foo") }
# ShopifyAPIRetry.retry(30) { customer.update_attribute(:tags, "foo") }
# c = ShopifyAPIRetry.retry { ShopifyAPI::Customer.find(id) }
#
# By Skye Shaw (https://gist.github.com/sshaw/6043fa838e1cecf9d902)