Skip to content

Instantly share code, notes, and snippets.

View seancdavis's full-sized avatar

Sean C Davis seancdavis

View GitHub Profile
@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 / 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 / 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 / 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