Skip to content

Instantly share code, notes, and snippets.

@johnnyicon
johnnyicon / add_keep_files.rb
Last active August 29, 2015 14:10
Add keep files recursively to a directory
#!/usr/bin/ruby
Dir['**/'].each do |dir|
puts "Placing .keep file in #{dir}"
`touch #{dir}.keep`
end
@johnnyicon
johnnyicon / Recursively add .gitignore files to empty dirs
Last active August 29, 2015 14:02
Recursively add .gitignore to all subfolders within a directory
# Recursively add a .gitignore file to all directories
# in the working directory which are empty and don't
# start with a dot. Helpful for tracking empty dirs
# in a git repository.
for i in $(find . -type d -regex ``./[^.].*''); do touch $i"/.gitignore"; done;
@johnnyicon
johnnyicon / Recursive Query
Created January 27, 2014 01:57
Recursive query to determine the page level and root page for a tree of pages
WITH RECURSIVE page_list AS (
SELECT root.id, root.title, root.parent_id, root.published_at,
1 AS page_level,
root.id AS root_id,
root.title AS root_title
FROM pages AS root
WHERE root.parent_id IS NULL
UNION ALL
@johnnyicon
johnnyicon / to_haml.rb
Created December 22, 2011 01:05
Convert all html.erb files to html.haml while preserving git history
# Adapted the script listed in the following link to maintain git history
# Original Script: http://snippets.dzone.com/posts/show/5449
# Usage:
# 1) Copy the file to the root of your Rails app
# 2) Run the script (i.e., ruby to_haml.rb app/views)
class ToHaml
def initialize(path)
@path = path
end