Skip to content

Instantly share code, notes, and snippets.

@rdetert
rdetert / Ruby Apple Silicon M1
Last active February 11, 2021 05:16
Get Ruby stuff to compile on Apple Silicon M1
Here are my notes on getting the codebase to work on the new M1 processors:
Upgrade the Ruby version to 2.7.2. You may need to set some compiler flags such as:
RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.7.2
Update all gems with 'bundle update'
Modify the Gemfile to detect the new hardware:
if RUBY_PLATFORM =~ /arm64.*darwin/ && `sysctl -n machdep.cpu.brand_string` =~ /M1/
# Get things to compile for Apple Silicon - minimum Ruby version of 2.7.2
@rdetert
rdetert / counties.rb
Last active November 28, 2020 05:36
Ruby Hash of All United States Counties
::Counties = {
AK: [
"Aleutians East Borough",
"Aleutians West Census Area",
"Anchorage, Municipality of",
"Bethel Census Area",
"Bristol Bay Borough",
"Denali Borough",
"Dillingham Census Area",
"Fairbanks North Star Borough",
@rdetert
rdetert / unsplash.css
Last active April 18, 2018 05:06
Customize the Unsplash badge if you don't like the bulky black and white one. Just cut and paste this code to the end of your CSS code.
a[href*="//unsplash.com"] {
background-color: transparent !important;
color: black !important;
font-size: 10px !important;
svg {
height: 10px !important;
fill: black !important;
}
@rdetert
rdetert / countries.rb
Last active July 26, 2016 15:45
Hash of all countries in Ruby
::Countries = { AF: "Afghanistan",
AL: "Albania",
DZ: "Algeria",
AS: "American Samoa",
AD: "Andorra",
AO: "Angola",
AI: "Anguilla",
AQ: "Antarctica",
AG: "Antigua and Barbuda",
AR: "Argentina",
@rdetert
rdetert / time_ago.rb
Last active August 29, 2015 14:07
A quick and dirty helper method to display a short form distance of time in words.
# Usage:
# short_time_in_words(Time.now, 5.seconds.ago) # => "5s"
# short_time_in_words(Time.now, 5.minutes.ago) # => "5m"
# short_time_in_words(Time.now, 5.hours.ago) # => "5h"
# short_time_in_words(Time.now, 55.hours.ago) # => "2d"
#
def short_time_in_words(from_time, to_time)
from_time = from_time.to_i
@rdetert
rdetert / action_mailer.rb
Created August 22, 2014 04:15
AOL and Yahoo! now use DMARC to force email services like SendGrid and MailChimp to reject emails if the FROM field gets 'spoofed' for their domain. To get around this, we will check for the `p=reject` key/value combo in the TXT record on _dmarc.domain.com. Here is a quick and dirty way to check if the DMARC field is set using ActionMailer on Ru…
class ActionMailer::Base
def dmarc(email)
domain = email.split('@')[1]
dmarc_domain = "_dmarc.#{domain}"
Resolv::DNS.open do |dns|
records = dns.getresources(dmarc_domain, Resolv::DNS::Resource::IN::TXT)
records.empty? ? nil : records.map(&:data).join(" ")
end
@rdetert
rdetert / states.rb
Last active March 30, 2023 17:53 — forked from dblandin/states.rb
Hash of the United States in Ruby
::States = { AK: "Alaska",
AL: "Alabama",
AR: "Arkansas",
AS: "American Samoa",
AZ: "Arizona",
CA: "California",
CO: "Colorado",
CT: "Connecticut",
DC: "District of Columbia",
DE: "Delaware",
@rdetert
rdetert / app_annie_sales_api.rb
Created January 5, 2014 23:58
An example of how to use the App Annie API to get sales using Ruby.
require "net/https"
require "uri"
require "date"
ACCOUNT_ID = "000000"
APP_ID = "000000000"
API_KEY = "0000000000000000000000000000000000000000"
yesterday = (Date.today.to_time - 1).strftime("%Y-%m-%d")
@rdetert
rdetert / shopify_api.conf
Last active May 31, 2017 20:12
Sync Shopify Customers who Accept Marketing with Sendy Using ActiveRecord 4
SHOPIFY_API_KEY = 'my-key'
SHOPIFY_PASSWORD = 'my-pass'
STORE_NAME = 'my-store'
@rdetert
rdetert / gist:7633417
Last active December 29, 2015 07:08
Sport Statistics
class SportStatistic
include Mongoid::Document
end
class AthleteStatistic < SportStatistic
end
class SoccerAthleteStatistic < AthleteStatistic
field: goals