Skip to content

Instantly share code, notes, and snippets.

@lmon
lmon / gist:43c9d647f4c32358007fbf17e66e64c9
Created September 20, 2018 20:17
Export Tables to CSV
# rake task to dump these tables
# post
file = "/tmp/post_data.csv"
posts = Post.all.order(:id => :desc)
columns = Post.columns.map { |column| column.name }
CSV.open( file, 'w' ) do |writer|
posts.each do |s|
writer << s.attributes.map { |a,v| v }
end
# copy all the blocks in a story to another story
def copy_story_blocks(params, replace_all_blocks = false)
HashParamsChecker.check_params!({ :user_id => 22,
:story_id => 44,
:revision_id => 55,
:block_id => 66,
:from_story_id => 2,
:to_story_id => 1 },
params
)
@lmon
lmon / gist:43772fd7686601373b7191c3aef6fc1b
Last active July 18, 2018 16:21
example code for migration
# Task update all posts that have more than one content_item in a row.
# Create a content_gallery and put them in it. Remove the original content_items
# Save the post with a new revision
# Example: one post
post = Post.find(22628)
story = Story.find_by_id(post.story_id)
story_block_ids = StoryRevisionsBlock.where(:story_revision_id => story.draft_revision_id).pluck(:story_block_id)
content_items = nil
@lmon
lmon / gist:40254e2c1f4565644b29e30d8890c917
Created February 27, 2018 23:01
verify some an urls
require 'curb'
require 'json'
urls = [
"/blog/21665-recipes-to-use-miso/an",
"/blog/20423-joshua-fields-millburn-the-minimalists-rebecca-shern-minimal-wellness-interview/an",
"/blog/21574-the-tunisian-lamb-stew-i-first-tasted-in-the-desert-recreated-at-home/an",
"/blog/21574-the-tunisian-lamb-stew-i-first-tasted-in-the-desert-recreated-at-home/an",
"/blog/21632-instant-stock-broth-hack-for-quick-braised-fish/an",
"/blog/21224-an-interview-with-buffy-maguire-of-lady-falcon-coffee-club-about-blends/an",