Skip to content

Instantly share code, notes, and snippets.

@rdetert
rdetert / Ruby Apple Silicon M1
Last active Feb 11, 2021
Get Ruby stuff to compile on Apple Silicon M1
View Ruby 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 Nov 28, 2020
Ruby Hash of All United States Counties
View counties.rb
::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 Apr 18, 2018
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.
View unsplash.css
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 Jul 26, 2016
Hash of all countries in Ruby
View countries.rb
::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 Aug 29, 2015
A quick and dirty helper method to display a short form distance of time in words.
View time_ago.rb
# 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 Aug 22, 2014
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…
View action_mailer.rb
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 Aug 9, 2022 — forked from dblandin/states.rb
Hash of the United States in Ruby
View states.rb
::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 Jan 5, 2014
An example of how to use the App Annie API to get sales using Ruby.
View app_annie_sales_api.rb
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
Sync Shopify Customers who Accept Marketing with Sendy Using ActiveRecord 4
View shopify_api.conf
SHOPIFY_API_KEY = 'my-key'
SHOPIFY_PASSWORD = 'my-pass'
STORE_NAME = 'my-store'
@rdetert
rdetert / gist:7633417
Last active Dec 29, 2015
Sport Statistics
View gist:7633417
class SportStatistic
include Mongoid::Document
end
class AthleteStatistic < SportStatistic
end
class SoccerAthleteStatistic < AthleteStatistic
field: goals