Skip to content

Instantly share code, notes, and snippets.

@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",
@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
# 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: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
@lmon
lmon / gist:de268da9fd167804e0a5ec6ebc116116
Last active August 5, 2019 20:13
RMA allocation & ledger line updates
irb(main):007:0> ap rma.rma_allocation_lines
[2019-08-05T20:04:47] DEBUG ActiveRecord::Base : RmaAllocationLine Exists (0.9ms) SELECT 1 AS one FROM "rma_allocation_lines" WHERE "rma_allocation_lines"."rma_id" = $1 LIMIT $2 [["rma_id", 11439], ["LIMIT", 1]]
[2019-08-05T20:04:47] DEBUG ActiveRecord::Base : RmaAllocationLine Load (0.6ms) SELECT "rma_allocation_lines".* FROM "rma_allocation_lines" WHERE "rma_allocation_lines"."rma_id" = $1 [["rma_id", 11439]]
[
[0] #<RmaAllocationLine:0x000000000b3717b0> {
:id => 9115,
:rma_id => 11439,
:description => "Sales Tax",
:total_allocation_micros => 8000,
:customer_allocation_micros => 8000,
@lmon
lmon / GiftsCategory_cleaned-minus10
Last active August 21, 2019 17:11
Subcategory_Taxonomy2019-FINALCHANGES-JULY2019.csv-GiftsCategory_cleaned-minus10
product_id,product_name,x2019_subcategory_1,x2019_subcategory_2
6286,Degrenne Salam Insulated Teapot,Food Gift Sets,Food Gifts
6276,Cookie Maker & Storage Container (Set of 2),Kitchen Storage & Organization,Unique Gifts
6256,Perfect Slice Bread Knife,Knives,Cooking Gifts
6250,Portable Espresso Maker,Coffee & Tea Accessories,Unique Gifts
6249,"Smithey Cast Iron Chef Skillet, 10""",Frying Pans & Skillets,Cooking Gifts
6247,100% Extra Virgin Heirloom Olive Oil,Food Gift Sets,Food Gifts
6244,Hand-Painted Metallic Moon Coasters (Set of 4),Barware,Unique Gifts
6244,Hand-Painted Metallic Moon Coasters (Set of 4),Barware,Handmade Gifts
6243,Hand-Painted Brass Napkin Rings (Set of 4),Table Decor,Handmade Gifts
2019-10-21T15:56:30] DEBUG ActiveRecord::Base : UserBillingGatewayInfo Load (0.9ms) SELECT "user_billing_gateway_infos".* FROM "user_billing_gateway_infos" WHERE "user_billing_gateway_infos"."gateway" = $1 AND "user_billing_gateway_infos"."token" = $2 LIMIT $3 [["gateway", "worldpay"], ["token", "4111111518931111"], ["LIMIT", 1]]
[2019-10-21T15:56:30] DEBUG ActiveRecord::Base : UserBillingInfo Load (0.9ms) SELECT "user_billing_infos".* FROM "user_billing_infos" WHERE "user_billing_infos"."hidden" = $1 AND "user_billing_infos"."id" = $2 [["hidden", false], ["id", 424226]]
[2019-10-21T15:56:30] INFO Rails : {"method":"POST","path":"/shop/admin/rmas/create","format":"html","controller":"Shop::Admin::RmasController","action":"create_rma","status":500,"error":"RuntimeError: Invalid payment method ''","duration":683.36,"view":0.0,"db":301.3,"dd":{"trace_id":8961126303114190952,"span_id":8636043102367750020},"ddsource":["ruby"],"http_status":null,"user_agent":null,"remote_addr":null,"tracking_code":null,"c
Merchant SKU Inventory Restock Date
75002-137 999 2019-12-31 valid+valid+valid
75000-667 -999 2019-12-31 valid+invalid+valid
75001-530 2019-12-31 valid+blank+valid
75000-668 999 12-31-19 valid+valid+invalid
75002-107 999 valid+valid+blank
75002-108 -999 12-31-19 valid+invalid+invalid
75000-999 -999 valid+invalid+blank
75000-993 12-31-19 valid+blank+invalid
75000-994 valid+blank+blank
{
"file_846": {
"header": true,
"delimiter": ",",
"mapping": {
"0": "merchant_sku",
"1": "inventory_value",
"2": "restock_date"
}
}
Merchant SKU Inventory Restock Date
HNY.500.30.001.000 999 2019-12-31 valid+valid+valid
HNY.500.20.025.050 -999 2019-12-31 valid+invalid+valid
HNY.500.20.023.050 2019-12-31 valid+blank+valid
HNY.500.10.028.095 999 12-31-19 valid+valid+invalid
HNY.500.70.040.000.BRS 999 valid+valid+blank
HNY.500.70.040.000.CPR -999 12-31-19 valid+invalid+invalid
HNY.300.30.052.930 -999 valid+invalid+blank
HNY.500.70.044.100.MRBL 12-31-19 valid+blank+invalid
HNY.500.70.045.000.MRBL valid+blank+blank