Skip to content

Instantly share code, notes, and snippets.

View seancdavis's full-sized avatar

Sean C Davis seancdavis

View GitHub Profile
<!-- ID: 881 -->
<div class="container-fluid sticky-top">
<div class="row">
<a href="javascript:void(0)" class="btn btn-live-schedule-trigger hidden-xs" data-smooth-scroll-to="live-stream-schedule"
data-smooth-scroll-offset="92" data-track-click="liveSeeScheduleClicked">
<span>See Schedule</span>
<svg class="icon icon-1" viewbox="0 0 256 256">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/svgs/icons.svg#chevron-down"></use>
</svg>
@seancdavis
seancdavis / script.rb
Last active January 6, 2023 08:21
Move files up one directory in Ruby
require 'fileutils'
path = File.expand_path('../', __FILE__)
Dir.glob("#{path}/**/*.*").each do |file|
new_path = "#{path}/#{file.split('/')[-1]}"
FileUtils.mv(file, new_path)
end
@seancdavis
seancdavis / base.rb
Created June 24, 2017 12:48
Load all modules within a namespaced directory
module Utils::All
# I wrote this originally for model concerns, in which case I needed
# the following line to be included:
# extend ActiveSupport::Concern
Dir.glob(File.expand_path('../', __FILE__) + '/*.rb').each do |util|
next if File.basename(util) == 'base.rb'
include "Utils::#{File.basename(util, '.rb').camelize}".constantize
end
end
@seancdavis
seancdavis / head-link.html
Last active May 30, 2017 18:49
Multiple CSS Imports
@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;
}
@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 / 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 / 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 / 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 / image.rb
Last active August 18, 2024 19:08
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