Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / application.html.erb
Created March 1, 2011 06:28
How to logout completely from Facebook using Ruby on Rails and Devise + Omniauth. I'm just modifying the Omniauth Railscast http://railscasts.com/episodes/236-omniauth-part-2
<div id="user_nav">
<% if user_signed_in? %>
<img src="<%= user_avatar %>" id="main_avatar"> Signed in as <%= current_user.email %>.<br />
Not you?
<% if session[:fb_token].nil? %>
<%= link_to "Sign out", destroy_user_session_path %>
<% else %>
<%= link_to "Sign out", facebook_logout_path %>
<% end %>
@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 / vbox_savestate.sh
Created August 3, 2011 06:47
Save the State of all your VirtualBox Virtual Machines. Great if you need to reboot remotely.
#!/bin/sh
VBoxManage list runningvms | awk '{split($0, a, " {"); gsub(/\"/,"", a[1]); print a[1]}' | xargs -I {} -t VBoxManage controlvm {} savestate
@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 / 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 / README.txt
Created June 1, 2011 23:29
Setup Monitoring for a rake ts:dd job (Thinking Sphinx Delayed Delta)
The purpose of all this is to see if sphinx, thinking sphinx and thinking sphinx delayed delta are all working properly.
I created a test controller on a separate monit subdomain that simply generates and posts a test value and then uses curl to retrieve it. If the two values match, then sphinx is working properly with delayed delta.
This example assumes a Linux installation.
The file 'delayed_delta.sh' spawns the `rake ts:dd` process in the background, saving its PID to tmp/pids in your Rails project. You can start and stop it by running '/etc/init.d/delayed_delta.sh start' and '/etc/init.d/delayed_delta.sh stop'. You will use these in your monitoring to, see the monitrc snippet.
In a crontab, every X seconds or minutes, run 'ar_sphinx_mon.sh' to see if records are properly being inserted and indexed. If they aren't, then kill all Thinking Sphinx processes and monit should restart them.