Bulk changing ownership on category base

I found it here:

I am getting this error:

[1] pry(main)> topics = Topic.where(category_id: categories).pluck(:id)

topics.each do |topic|
  PostOwnerChanger.new(
    post_ids: Post.where(topic_id: topic).where(post_number: 1).pluck(:id),
    topic_id: topic,
[1] pry(main)> topics = Topic.where(category_id: categories).pluck(:id)
topics.each do |topic|urse.system_user,
  PostOwnerChanger.new(
    post_ids: Post.where(topic_id: topic).where(post_number: 1).pluck(:id),
    topic_id: topic,
    new_owner: user,
    acting_user: Discourse.system_user,
    skip_revision: true
  ).change_owner!
NameError: undefined local variable or method `categories' for main:Object
from (pry):1:in `__pry__'
[2] pry(main)>
[3] pry(main)>