Skip to content

Instantly share code, notes, and snippets.

View seancdavis's full-sized avatar

Sean C Davis seancdavis

View GitHub Profile
@seancdavis
seancdavis / zshrc
Last active January 24, 2024 17:10
zshrc file to work with `rbenv` and oh-my-zsh
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# ZSH_THEME="alanpeabody"
# Example aliases
@seancdavis
seancdavis / load_tasks.rake
Last active August 16, 2022 07:27
Automatically load rake tasks within namespaces based on directory structure within `lib/tasks` directory.
# lib/tasks/load_tasks.rake
# ------------
# Looks at every .rb file in the lib/tasks and adds them to rake within the
# namespace of their subdirectories
# ------------
# Important to note we are looking specifically for .rb files, so they
# aren't added to the global rake namespace
Dir.glob("#{Rails.root}/lib/tasks/**/*.rb").each do |file|
@seancdavis
seancdavis / _post.html.erb
Last active September 27, 2018 11:31
rails scaffold that belongs to a Devise user model
<% # app/views/posts/_post.html.erb %>
<article>
<h2><%= post.title %></h2>
<!-- ... -->
</article>
@seancdavis
seancdavis / Gemfile
Last active March 24, 2017 07:23
Related Content (without metadata) in Rails using tf-idf
gem 'htmlentities'
gem 'nokogiri'
@seancdavis
seancdavis / image.rb
Last active January 12, 2022 14:06
Rails has_many :through Polymorphic Association (http://goo.gl/lxmehk)
# app/models/image.rb
class Image < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
@seancdavis
seancdavis / project
Created November 17, 2014 18:45
Simple command line script using Ruby (http://goo.gl/3qcCnv)
#!/usr/bin/env ruby
# Include libraries
#
require 'fileutils'
# Make sure we have our argument
#
if ARGV.size < 1
puts "Usage: project [DIR]"
@seancdavis
seancdavis / dragonfly_import.rake
Last active August 29, 2015 14:12
Transition from CarrierWave to Dragonfly in Rails
require 'csv'
desc 'Import local files (with csv references) using Dragonfly'
task :dragonfly_import => :environment do
config = [
{:model => Attachment, :attr => :document}
]
storage_dir = "#{Rails.root}/lib/cw_refs"
@seancdavis
seancdavis / download_image.rb
Created December 7, 2015 12:24
Download a collection of images from URLs using Ruby
require 'open-uri'
def download_image(url, dest)
open(url) do |u|
File.open(dest, 'wb') { |f| f.write(u.read) }
end
end
urls = [
'http://petsfans.com/wp-content/uploads/2014/11/edfsaf.jpg',
@seancdavis
seancdavis / notify_slack.rb
Created December 7, 2015 12:55
Post incoming webhook to Slack using Ruby
# Assumes:
# - curl is installed
# - you have a slack channel with an incoming webhook configured
require 'json'
def notify_slack(webhook_url, channel, username, text, image)
payload = {
:channel => channel,
:username => username,
@seancdavis
seancdavis / index.html
Created March 3, 2016 21:00
Full-Size, Looping Background Video with YouTube Video
<style>
.bg-video {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
z-index: -1;
}