Skip to content

Instantly share code, notes, and snippets.

View codealchemy's full-sized avatar

Alexandre Schmitt codealchemy

  • San Carlos, CA
  • 23:15 (UTC -08:00)
View GitHub Profile
@codealchemy
codealchemy / pull_html_images_to_csv.rb
Created August 29, 2015 19:02
Pulls each image from html content to clean urls to match to uploaded page attachments in NationBuilder
require 'csv'
require 'nokogiri'
CSV.open('slug_with_image.csv', 'w') do |csv|
CSV.foreach('blog_file.csv', headers: true) do |row|
content_html = Nokogiri::HTML(row['content'])
content_html.css('img').each do |img|
csv << [img['src'], row['slug']]
end
end
@codealchemy
codealchemy / script.rb
Created March 22, 2018 01:36
Replace all '_url' route helpers in templates across a Rails project with '_path' helpers
def update_nested_templates(path)
if File.directory?(path)
Dir.foreach(path) do |filename|
next if %w(. ..).include?(filename)
update_nested_templates(File.absolute_path(filename, path))
end
else
update_template!(path)
end
end
@codealchemy
codealchemy / afi_top_100.rb
Created August 29, 2018 04:47
Script to randomly return one of the AFI top 100 films, while keeping a record of movies that have already been seen.
#!/usr/bin/env ruby
require "json"
module AFITop100
extend self
WATCHED_FILMS_JSON = File.join(File.dirname(__FILE__), "./watched_films.json").freeze
AFI_TOP_100 = [
@codealchemy
codealchemy / pg_api_docker_template.rb
Last active September 7, 2018 18:56
Basic Rails API template with Docker
remove_file "Gemfile"
run "touch Gemfile"
add_source 'https://rubygems.org'
gem 'bootsnap', require: false
gem "health_check"
gem 'rails', '~> 5.2'
gem 'puma'
gem 'pg'