Skip to content

Instantly share code, notes, and snippets.

@sshaw
sshaw / rusage.rb
Last active October 19, 2017 13:55 — forked from itsderek23/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
@sshaw
sshaw / gh_update_remotes_owner.sh
Last active March 21, 2016 15:58
Batch update the GitHub user or organization in all repository remotes under the given directory.
# Batch update the GitHub user or organization in all repo remotes under the given directory.
# Does not work with JRuby.
#
# usage: usage: gh_update_remotes_owner dir oldorg neworg
gh_update_remotes_owner()
{
if [ $# -lt 3 ]; then
echo "usage: gh_update_remotes_owner dir oldorg neworg" >&2
return 1
fi
@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 / 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)
@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 / export-to-engine-mode
Last active September 24, 2015 03:16
Export Chrome search engine shortcuts to emacs' engine-mode
#!/bin/bash
#
# Export Chrome search engine shortcuts to emacs' engine-mode (https://github.com/hrs/engine-mode)
# https://gist.github.com/sshaw/9b635eabde582ebec442a
#
sql="select short_name,keyword,url from keywords where length(keyword) < 3"
source=${1:-$HOME/Library/Application Support/Google/Chrome/Default/Web Data}
@sshaw
sshaw / bh-flash.gemspec
Last active August 29, 2015 14:08
Render Flash Messages Using Ruby's Bootstrap Helpers (Bh)
Gem::Specification.new do |s|
s.name = "bh-flash"
s.version = "0.0.2"
s.date = "2015-08-02"
s.summary = "Render flash messages using Bootstrap Helpers"
s.description =<<-DESC
Render flash messages using Bootstrap Helpers: http://fullscreen.github.io/bh/
Inspired by: https://github.com/planetargon/flash-message-conductor
DESC
s.authors = ["Skye Shaw"]
@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 / q.rb
Last active August 29, 2015 14:05
SuckerPunch + GDBM: Don't think GDBM can be used with 2 writers...
require "gdbm"
require "sucker_punch"
class IdBasedJob
include SuckerPunch::Job
def perform(db, ids)
ids.each do |id|
SuckerPunch.logger.info(sprintf "Running %s [%d]\n", id, Thread.current.object_id)
if do_some_thang
@sshaw
sshaw / gist:1cd69d078cffeebc76cd
Created August 25, 2014 03:05
Install Ruby SBDB on OS X
brew install berkeley-db4
gem install sbdb -- --with-db-lib=/usr/local/opt/berkeley-db4/lib --with-db-include=/usr/local/opt/berkeley-db4/include/