<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ryo Kato on Medium]]></title>
        <description><![CDATA[Stories by Ryo Kato on Medium]]></description>
        <link>https://medium.com/@katryo?source=rss-a1d1ab5c50e7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Oxt6yQHgVLZShULhzEBQuw.png</url>
            <title>Stories by Ryo Kato on Medium</title>
            <link>https://medium.com/@katryo?source=rss-a1d1ab5c50e7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:45:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@katryo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What I learned from the first CS courses at the graduate school of USC]]></title>
            <link>https://medium.com/@katryo/what-i-learned-from-the-first-cs-courses-at-the-graduate-school-of-usc-82b7ef7fc0b4?source=rss-a1d1ab5c50e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/82b7ef7fc0b4</guid>
            <category><![CDATA[usc]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ryo Kato]]></dc:creator>
            <pubDate>Fri, 25 May 2018 16:12:47 GMT</pubDate>
            <atom:updated>2018-05-25T16:23:24.040Z</atom:updated>
            <content:encoded><![CDATA[<p>I started <a href="https://gapp.usc.edu/graduate-programs/masters/computer-science/cs-scientists-and-engineers">Scientists and Engineers program</a> at the University of Southern California (USC), Viterbi School of Engineering Computer Science Department in August 2017.</p><p>I attended two classes in the first semester, 2017 Fall. I would like write what I learned from these courses.</p><ul><li>CSCI 455x Introduction to Programming Systems Design</li><li>CSCI 570 Analysis of Algorithms</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2UWR7iNFUDcvOttnIL-Kw.jpeg" /><figcaption>USC University Park Campus</figcaption></figure><h3>CSCI 455x Introduction to Programming Systems Design</h3><p><a href="http://www-scf.usc.edu/~csci455/">http://www-scf.usc.edu/~csci455/</a></p><p>This course is basically for novice programmers. While I did not want to take it, this class was mandatory for all students in Scientists and Engineers program, so I had to take it. Since I had three years experience as a professional software engineer, CSCI455x was not very interesting.</p><ul><li>Basic algorithms, such as merge sort and binary tree</li><li>Fundamental data structures, such as hash table and linked list</li><li>Java</li><li>C++</li></ul><p>I learned them, but they all are what I knew already. Although I was required to take this course, I wanted to avoid attending the lectures. I think you can learn the same topics in Coursera and popular textbooks without paying tuition fee.</p><p>On the other hand, there were some advantages of attending the lectures. Since all the students in Scientists and Engineer program took this course, we recognized each other in the classroom soon.</p><p>I received an A grade in this course. I guess most of the students got A.</p><h3>CSCI 570 Analysis of Algorithms</h3><p><a href="http://www-bcf.usc.edu/~adamchik/570/index.html">http://www-bcf.usc.edu/~adamchik/570/index.html</a></p><p>This course is fairly good. I learned commonly used Algorithms, such as greedy algorithm, dynamic programming, and maximum flow.</p><p>Basically, specific programming languages are not used in CSCI570. We used pseudo code and English to express the ideas of algorithms even in the exams. Since I am not a native English speaker, trying to write answers in English was a good exercise of English.</p><p>CSCI570 was not too difficult, not too easy. Most of the students caught up on the lectures and passed the exams. At the same time, this course might be easy for people who do competitive programming. If you have won in competitive programming contests such as AtCoder, Codeforces, CSAcademy, and CodeChef, you will find it painless to get a good grade. I had not tried competitive programming when I started CSCI570, so it was a bit tough to follow up. I got A- in CSCI 570.</p><p>We used <a href="https://www.amazon.com/Algorithm-Design-Jon-Kleinberg/dp/0321295358">Algorithm Design</a> as a textbook. I like this book because the author chose to use simple wording to explain complicated algorithms. This method helped me a lot to understand the concept of algorithms by reading chapters again and again.</p><p>There was homework each week. All the submissions were graded and we were supposed to get feedback from graders. However, I did not receive the feedback of some of my submissions. I guess that graders were too busy to write the feedback. It disappointed me because some feedbacks were helpful to understand the way to solve the problems.</p><p>While assignments weregraded, it did not affect the final grade. This kind of policies is described <a href="http://www-bcf.usc.edu/~adamchik/570/policies.html">here</a>.</p><p>Who am I?</p><p>My name is Ryo Kato. As I wrote in the beginning, I enrolled in <a href="https://gapp.usc.edu/graduate-programs/masters/computer-science/cs-scientists-and-engineers">Scientists and Engineers program</a> at the University of Southern California (USC), Viterbi School of Engineering Computer Science Department.</p><p>I am currently working as a full-time intern for Pinscreen, Inc. and enjoy the summer semester attending CSCI 567 Machine Learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82b7ef7fc0b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I migrated my Rails app from a VPS to AWS Elastic Beanstalk and RDS]]></title>
            <link>https://medium.com/@katryo/how-i-migrated-my-rails-app-from-a-vps-to-aws-elastic-beanstalk-and-rds-8a6192627096?source=rss-a1d1ab5c50e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a6192627096</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <dc:creator><![CDATA[Ryo Kato]]></dc:creator>
            <pubDate>Thu, 24 May 2018 05:39:40 GMT</pubDate>
            <atom:updated>2018-05-24T06:05:36.115Z</atom:updated>
            <content:encoded><![CDATA[<p>I would like to describe how I switched my Rails app (<a href="http://denkinovel.com/">http://denkinovel.com/</a>) from VPS to AWS. This post consists of the following sections.</p><ol><li>The background story of this migration</li><li>512MB limitation of AWS Elastic Beanstalk</li><li>“Unknown primary key for table” problem after PostgreSQL data migration</li></ol><p>Here are versions of software I used.</p><ul><li>Ruby on Rails 4.2.10</li><li>Puma 3.11.4</li><li>PostgreSQL 10.3</li><li>Ruby 2.5.1-p57</li></ul><h3>1. The background story of this migration</h3><p>To be short, I migrated my Rails app to AWS to improve the response time.</p><p>I started developing the app as a homework for a graduate course at Kyoto University, Japan, 2014. It means that my Rails app had been running in a VPS for more than three years. My app responded well before the day I moved to Los Angeles, August 2017. After arriving in LA, I realized that my web app did not quickly respond. I guessed that it was because of the distance from here to the data center which was located in Japan.</p><p>It took too many seconds to connect to the VPS server. In addition, I realized that my VPS was unstable for some reasons. I thought that it is a good chance to switch the environment from the VPS to AWS. Using AWS Elastic Beanstalk (EB) makes it easier to deploy and use Amazon CloudFront as CDN. Plus, I was learning AWS so that migration seemed a good choice.</p><p>However, migrating was not easy. There were two problems that prevented me from migration.</p><ul><li>512 MB limitation of repository for AWS Elastic Beanstalk</li><li>“Unknown primary key for table” problem after data migration in PostgreSQL</li></ul><h3>2. 512MB limitation of AWS EB</h3><p>You cannot deploy a web app to AWS EB(Elastic Beanstalk) with more than 512 MB of files. This is not a strict limitation for most of the apps but was for my Rails app. My app, Denkinovel, contains a lot of images and audio files more than 2GB in total. Thus, I could not deploy the app without some kind of trick.</p><p>To make it possible to deploy the app, I changed the way to deploy.</p><p>Before the migration, I used Capistrano v2 to deploy the app. When you run “cap deploy” command, it connects to the server using SSH and runs rake assets:precompile. In this way, asset files in app/assets/images/, app/assets/audios/ and etc are copied to public/assets/ and public/assets/.sprockets-manifest-*.json is created. Then, web server restarts by systemd.</p><p>I totally changed the deploy procedure. First, I quitted using Capistrano and decided to use EB CLI. Second, I chose to run rake assets:precompile before deployment.</p><p>I decided to use <a href="https://github.com/AssetSync/asset_sync">asset_sync</a>. This gem makes it possible to upload your assets when you run rake assets:precompile.</p><p>I also changed the .gitignore like this.</p><pre>public/assets/*<br>!public/assets/.sprockets-manifest-*.json<br>app/assets/audios/*<br>app/assets/images/*</pre><p>Then Git does not see the changes in app/assets/audios/*, app/assets/audios/*, and public/assets/* but detects the changes in public/assets/.sprockets-manifest-*.json.</p><p>When I deploy the app, I run this command in the beginning.</p><pre>$ RAILS_ENV=production bundle exec rake assets:precompile</pre><p>Now assets files are copied to public/assets/ but Git does not know the actual files of images and audios. Git just detects diffs in Sprockets Manifest file. At the same time, asset_sync uploads these files to S3.</p><pre>$ git add .<br>$ git commit</pre><p>Now Git realized that we updated the assets while the actual contents of files are not recorded.</p><pre>$ eb deploy</pre><p>By this AWS EB CLI’s simple command, the Sprockets Manifest file and other updated files are uploaded and Puma restarts. Deployment complete!</p><pre>$ bundle exec rake assets:clobber</pre><p>I run this command to delete precompiled files after deployment.</p><h3>3. “Unknown primary key for table” after PostgreSQL data migration</h3><p>I copied the data from the PostgreSQL in my VPS to another PostgreSQL server in AWS RDS. First, I loaded dump file by this command.</p><pre>$ pg_dump -U myapp -Fc myapp_production &gt; myapp_production_db.dump</pre><p>After that, restored the data by this command.</p><pre>$ pg_restore -h aaaaaa.bbbbbbbb.us-west-1.rds.amazonaws.com -p 5432 -d myapp_production -U myapp myapp_production_db.dump</pre><p>It took some hours to migrate the data in PostgreSQL.</p><p>This procedure is not interesting. You can read the official user guide of RDS here. <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html">https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html</a></p><p>What is interesting happened later. After I deployed the Rails app to AWS EB, I got this error message when I accessed the app using a browser.</p><pre>(ActionView::Template::Error) “Unknown primary key for table …</pre><p>I searched this error message and realized that some people are confused about this problem too. <a href="https://stackoverflow.com/questions/18056162/getting-unknown-primary-key-for-table-while-the-id-is-there">https://stackoverflow.com/questions/18056162/getting-unknown-primary-key-for-table-while-the-id-is-there</a></p><p>From these posts, people seemed to get the error after they dump and restore data in PostgreSQL. This situation was similar to mine.</p><p>I eventually solved this problem by explicitly set primary_key to be id for each class that inherits from ActiveRecord::Base.</p><pre>class User &lt; ActiveRecord::Base<br> self.primary_key = :id</pre><p>I don’t know why the error happened while their primary_key is set to be id by default.</p><h3>Sum up</h3><p>Finally, I succeeded to deploy my Rails app to AWS EB and copied all the data in the PostgreSQL server to RDS. To accomplish this, I changed the way to deploy from using Capistrano to running rake:precompile before deployment. I also changed some code in the app to avoid errors of “Unknown primary key for table…” .</p><p><a href="http://denkinovel.com/">Denkinovel（デンキノベル） - 動く小説投稿サイト</a></p><p>This is the Rails app I migrated. Unfortunately, there is Japanese version only at this time.</p><p>I hope this article will help someone in the same situation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a6192627096" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>