Skip to content

Instantly share code, notes, and snippets.

Skye Shaw sshaw

Block or report user

Report or block sshaw

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
@sshaw
sshaw / shopify_api_retry.rb
Last active Jul 13, 2019
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
View shopify_api_retry.rb
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)
@sshaw
sshaw / erb_test_fixture.rb
Last active Jun 14, 2019
Ruby module that allows you use ERB in your test/spec fixtures and easily load them
View erb_test_fixture.rb
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 / rle.txt
Last active Apr 5, 2019
Run-length encoding in Perl. Does not support integers :)
View rle.txt
perl -E'print $+[1]-$l,$& and $l=$+[1] while $ARGV[0] =~ /(.)(?!\1)/g' aaabbbcdeee
3a3b1c1d3e
perl -E'print $2 x $1 while $ARGV[0] =~ /(\d+)(.)/g' 3a3b1c1d3e
aaabbbcdeee
@sshaw
sshaw / rspec-checksum-matchers.rb
Last active Oct 31, 2018
RSpec::Checksum::Matchers: Check if a String looks like a checksum produced a the given algorithm.
View rspec-checksum-matchers.rb
# 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 / page_number.gemspec
Last active Sep 14, 2018
Ruby utility methods for pagination page and per page that make sure you'll always have a valid number. Use them your controllers or model or anywhere where you process page info. Moved to https://github.com/sshaw/page_number.git
View page_number.gemspec
Gem::Specification.new do |s|
s.name = "page_number"
s.version = "0.0.2"
s.date = "2016-09-19"
s.summary = "Utility methods for pagination page and per page that make sure you'll always have a valid number."
s.description =<<-DESC
Utility methods for pagination page and per page that make sure you'll always have a valid number.
Use them your controllers or model or anywhere where you process page info.
DESC
s.authors = ["Skye Shaw"]
@sshaw
sshaw / db.rake
Last active Jun 19, 2018
Remove MySQL AUTO_INCREMENT From Rails db:structure:dump
View db.rake
namespace :db do
namespace :structure do
task :dump => :environment do
# Can add more dump options to ~/.my.cnf:
#
# [mysqldump]
# skip-comments
#
command = %q{perl -i -pe's/AUTO_INCREMENT=\d+\s//' %s} % Rails.root.join("db/structure.sql")
sh command, :verbose => false do |ok, res|
@sshaw
sshaw / bad.plist
Created Jun 15, 2018
Example of Apple Property List (Plist) DTD Validation With xmllint
View bad.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>A</key>
<key>B</key>
<string>sshaw</string>
<string>DDEX</string>
</dict>
</plist>
@sshaw
sshaw / app-service-view-examples.rb
Last active Nov 11, 2017
Examples on the ways to separate an ActiveRecord domain model from UI layer in Rails/Ruby.
View app-service-view-examples.rb
module PropertyManagement
class OnBoarding
#
# **********
# Setup
# **********
#
# ActiveRecord: None
# ActiveModel+freeze: None
# Hash: None, but param massaging may be necessary unless everything matches ActiveRecord
View rusage.rb
require 'get_process_mem'
require 'rusage' # gem install rusage
require 'benchmark'
n = 2000
gpm = GetProcessMem.new
Benchmark.bm(10) do |x|
x.report("status:") { n.times do gpm.linux_status_memory end }
# In sshaw version
You can’t perform that action at this time.