<?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 Hiroshi Ogino on Medium]]></title>
        <description><![CDATA[Stories by Hiroshi Ogino on Medium]]></description>
        <link>https://medium.com/@ogin?source=rss-9915753605c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OSlzsbec9v45nXLLNOYEsw.jpeg</url>
            <title>Stories by Hiroshi Ogino on Medium</title>
            <link>https://medium.com/@ogin?source=rss-9915753605c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:52:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ogin/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[The Job As a Programmer]]></title>
            <link>https://medium.com/@ogin/the-job-as-a-programmer-48cc7e5c3f39?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/48cc7e5c3f39</guid>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[engineer]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Fri, 05 Apr 2019 12:51:00 GMT</pubDate>
            <atom:updated>2019-04-05T12:52:45.765Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you think what is the job <strong>As a Programmer</strong>? Solving technical problems? Implementing the wonderful software?</p><p>I have another answer and will share it in this article.</p><h3>Output vs Outcome</h3><p>First of all, let’s think of the difference between <strong>Output</strong> and <strong>Outcome</strong>. These are similar words but the meaning of two are completely different, see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*MNKHsmh6I_iFypNwMgrE_w.png" /></figure><p>For customers, <strong>MOST</strong> and <strong>ONLY</strong> important thing is if the software will definitely solve their issue. Thus, they have no interest in how it is implemented (even JAVA or Ruby). In other words, <strong>Outcome</strong> is what customers will feel using it and whether we will be able to deliver value to customers according to their expectations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*MEsyABJbdkjrcvyZYqzsgA.png" /></figure><p>Focus on <strong>Outcome</strong>!</p><h3>Trade-off</h3><p>Many programmers tend not to care about taking time for creating the wonderful software which has no tech debt and follows principles such as DRY, KISS, YAGNI, etc. However, future customers who will use it desire to solve their issue as soon as possible, so delivering earlier is also valuable.</p><p>Both making software with craftsmanship and delivering it earlier are essential, we always have to keep looking for a good landing point between them during development.</p><h3>Right Customer, Right Issue</h3><p>Can you explain the software under development is for who and it solves what issue?</p><p>Once we started developing, we focus on how wonderful we can implement and tend to forget these questions. The software is always for the people who use it, so we have to put ourselves in their position to consider - “What do we feel using this?” and “Do we really need this feature?” and much more.</p><p>In order to recognize <strong>Right Customer</strong> and <strong>Right Issue</strong> at all times, it is better to write down the persona and the issue on a paper and put it on the wall where the eyes stop.</p><h3>My Answer</h3><p>The job <strong>As a Programmer</strong> is delivering value to the customers and changing their world. To accomplish it, it is important to focus on <strong>Outcome</strong>, consider <strong>Trade-off</strong>, find <strong>Right Customer</strong> and <strong>Right Issue</strong>.</p><p>Why don’t we think once again that we are developing software for?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48cc7e5c3f39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tips: Practical RDS Settings]]></title>
            <link>https://medium.com/@ogin/tips-practical-rds-settings-23fee507dca2?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/23fee507dca2</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[aurora]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Tue, 22 Jan 2019 04:06:51 GMT</pubDate>
            <atom:updated>2019-01-22T04:09:18.141Z</atom:updated>
            <content:encoded><![CDATA[<p>Nowadays, we always need a datastore to persist information and I often use RDS, especially Amazon Aurora which is Cloud Datastore compatible with MySQL, but I met some troubles with bad settings of it. Therefore, I consider Practical Settings and keep it in mind not to encounter such annoyance in this article.</p><h4>max_connections</h4><p>The default value of <em>max_connections</em> is <strong>90</strong> which is a bit small, it’s better to extend it to <strong>1000 or more</strong>.</p><pre>mysql&gt; show variables where Variable_name = &#39;max_connections&#39;;<br>+-----------------+-------+<br>| Variable_name   | Value |<br>+-----------------+-------+<br>| max_connections | 1000  |<br>+-----------------+-------+</pre><h4><strong>utf8mb4</strong></h4><p>The <em>utf8mb4</em> is Character set which allows us to encode 4-byte UTF-8. We often need to deal with 4-byte character, which is 🍣 or 🐟 or …, therefore it is required.</p><pre>mysql&gt; show variables like &#39;%character_set\_%&#39;;<br>+--------------------------+---------+<br>| Variable_name            | Value   |<br>+--------------------------+---------+<br>| character_set_client     | utf8mb4 |<br>| character_set_connection | utf8mb4 |<br>| character_set_database   | utf8mb4 |<br>| character_set_filesystem | utf8mb4 |<br>| character_set_results    | utf8mb4 |<br>| character_set_server     | utf8mb4 |<br>| character_set_system     | utf8    |<br>+--------------------------+---------+</pre><h4>innodb_file_per_table, innodb_large_prefix, innodb_file_format</h4><p>For getting better performance, we create index appropriately but sometimes meet error: <strong>‘Specified key was too long; max key length is 767 bytes’</strong>. Adjust 3 settings to extend the key length.</p><pre>mysql&gt; show variables where Variable_name = &#39;innodb_file_per_table&#39; OR Variable_name = &#39;innodb_large_prefix&#39; OR Variable_name = &#39;innodb_file_format&#39;;<br>+-----------------------+-----------+<br>| Variable_name         | Value     |<br>+-----------------------+-----------+<br>| innodb_file_format    | Barracuda |<br>| innodb_file_per_table | ON        |<br>| innodb_large_prefix   | ON        |<br>+-----------------------+-----------+</pre><p>These settings already became as default from MySQL 5.7, you might not need to adjust now.</p><h4>timezone</h4><p>Where does the service run? What is its timezone? I guess it is not UTC in many cases, if so, to change into the same timezone with the server is better choice not to cause confusion.</p><pre>mysql&gt; show variables like &quot;%time_zone%&quot;;<br>+------------------+------------+<br>| Variable_name    | Value      |<br>+------------------+------------+<br>| system_time_zone | UTC        |<br>| time_zone        | Asia/Tokyo |<br>+------------------+------------+</pre><p>We can’t change <em>system_time_zone</em>, but it is enough to change only <em>time_zone</em>.</p><h4>interactive_timeout, wait_timeout</h4><p>The <em>interactive_timeout</em> will be referenced with the client which has <strong>CLIENT_INTERACTIVE</strong> option, and the <em>wait_timeout</em> will be referenced the client which doesn’t have that option.</p><p>The default value of both is <strong>28800 sec</strong>, it would stop the service for a long time if there would be a big query using almost 100 percent CPU. That is, the value is too long to run the service reliably, <strong>60 sec or less</strong> is better.</p><pre>mysql&gt; show variables where Variable_name = &#39;interactive_timeout&#39; OR Variable_name = &#39;wait_timeout&#39;;<br>+---------------------+-------+<br>| Variable_name       | Value |<br>+---------------------+-------+<br>| interactive_timeout | 60    |<br>| wait_timeout        | 60    |<br>+---------------------+-------+</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23fee507dca2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tips: The way of using Trigger in RDS]]></title>
            <link>https://medium.com/@ogin/tips-the-way-of-using-trigger-in-rds-252782d60f58?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/252782d60f58</guid>
            <category><![CDATA[trigger]]></category>
            <category><![CDATA[aurora]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Mon, 21 Jan 2019 02:16:43 GMT</pubDate>
            <atom:updated>2019-01-21T02:18:16.846Z</atom:updated>
            <content:encoded><![CDATA[<p>We can not use Trigger in RDS because MySQL and Aurora instance has no super privileges. Set <strong>log_bin_trust_function_creators</strong> ON to use it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UP7sQUioSpwqLtpUjootkw.png" /></figure><p>That’s all; the value of <strong>1</strong> means ON and don’t need reboot the instance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=252782d60f58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Valuable Custom Validators in Rails]]></title>
            <link>https://medium.com/@ogin/two-valuable-custom-validators-in-rails-a7d1aa469d64?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7d1aa469d64</guid>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 05:03:22 GMT</pubDate>
            <atom:updated>2018-11-08T05:03:22.745Z</atom:updated>
            <content:encoded><![CDATA[<p>There are a lot of services which request tasks to other system such as analyzing customer actions, batch delivery in e-commerce service, and so on. The simplest way to execute it is handing in a file which is made from the records of DB in our service to other system but we sometimes encounter problems not be able to connect correctly, especially <strong>Encode</strong> or <strong>Linefeed</strong> because of a difference of the specification. Therefore, we also need to validate customer’s inputs in accordance with the same specification in our service.</p><p>In this article, I’ll share the way to bridge the gap between our service and such a system by making Custom Validator in Rails. Thank you in advance for your understanding that I won’t get in touch with extracting data from DB and requesting to other system.</p><h3><strong>Custom Encode Validator</strong></h3><p>As you know, we have to define each Custom Validator under app/validators and I recommend you to create in each encode-validation.</p><pre>class Cp932Validator &lt; ActiveModel::EachValidator<br> def validate_each(record, attribute, value)<br> value.encode(&#39;cp932&#39;) if value.present?<br> rescue Encoding::UndefinedConversionError<br> record.errors[attribute] &lt;&lt; (options[:message] || &quot;can&#39;t include CP932 characters&quot;)<br> end<br>end</pre><pre>class ShiftJisValidator &lt; ActiveModel::EachValidator<br> def validate_each(record, attribute, value)<br> value.encode(&#39;Shift_JIS&#39;) if value.present?<br> rescue Encoding::UndefinedConversionError<br> record.errors[attribute] &lt;&lt; (options[:message] || &quot;can&#39;t include Shift_JIS characters&quot;)<br> end<br>end</pre><p>The reason why creating so, we can write like below in each model which makes easier to understand how it would be validated.</p><pre>validates :name, cp932: true, shift_jis: true</pre><h3>Custom Linefeed Validator</h3><p>We have to define Custom Validator under app/validators alike.</p><pre>class SingleLineValidator &lt; ActiveModel::EachValidator<br> def validate_each(record, attribute, value)<br> record.errors[attribute] &lt;&lt; (options[:message] || &quot;can&#39;t include line feed / carriage return&quot;) if value =~ /\R/<br> end<br>end</pre><p>It’s better to name it SingleLineValidator, because we can define like single_line: true which is clear not to accept a new line.</p><pre>validates :name, single_line: true</pre><h3>Conclusion</h3><p>We often come across these problems because there are many self-defined systems in Japan. I don’t know clearly there also would be in other countries but I hope that it would be helpful if you face with the same problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7d1aa469d64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to order by given array in ActiveRecord]]></title>
            <link>https://medium.com/@ogin/how-to-order-by-given-array-in-activerecord-bf0775c2b60?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf0775c2b60</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[activerecord]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Fri, 20 May 2016 11:16:44 GMT</pubDate>
            <atom:updated>2016-05-20T11:16:44.928Z</atom:updated>
            <content:encoded><![CDATA[<p>We sometimes want to get <strong>the data which is ordered by given array</strong>. In this case, we might write code like below.</p><pre>User.where(id: [4, 1, 3, 2])<br>=&gt;[#&lt;User:0x007f8b749eb720 <strong>id:1</strong>, ...&gt;, #&lt;User:0x007f8b749eb5e0 <strong>id:2</strong>, ...&gt;, #&lt;User:0x007f8b6b248f08 <strong>id:3</strong>, ...&gt;, #&lt;User:0x007f8b6b248940 <strong>id:4</strong>, ...&gt;]</pre><p>As you can see, we can’t get the data which is ordered by given array though we want to get it. Can’t we get the data? No, we can get it if we use each RDB function.</p><h3>MySQL</h3><p>In MySQL, we can order by given array like below.</p><pre>SELECT id, name FROM users ORDER BY <strong>FIELD(id, 4, 1, 3, 2)</strong>;<br>=&gt;<br>+----+---------+<br>| id |  name   |<br>+----+---------+<br>|  4 | andy    |<br>|  1 | judy    |<br>|  3 | erick   |<br>|  2 | lucas   |<br>+----+---------+</pre><p>Therefore, we can get the same result with code below in ActiveRecord.</p><pre>ids = %w(4 1 3 2)<br>sanitized_query <strong>=</strong> ActiveRecord<strong>::</strong>Base<strong>.</strong>send(:sanitize_sql_array, <strong>[</strong>&#39;field(id ,?)&#39;, ids<strong>]</strong>)<br>User.where(id: ids)<strong>.</strong>order(sanitized_query)</pre><p>Probably, we can write like below soon. (sanitize processing of order will be coming soon.)</p><pre>User.where(id: ids)<strong>.</strong>order(<strong>[</strong>&#39;field(id, ?)&#39;, ids<strong>]</strong>)</pre><h3>PostgreSQL</h3><p>In PostgreSQL, we can order by given array like below.</p><pre>SELECT id, name FROM users ORDER BY <strong>position(&#39;@&#39;||id::text||&#39;@&#39; in &#39;@4@1@3@2@&#39;)</strong>;<br>=&gt;<br>+----+---------+<br>| id |  name   |<br>+----+---------+<br>|  4 | andy    |<br>|  1 | judy    |<br>|  3 | erick   |<br>|  2 | lucas   |<br>+----+---------+</pre><p>It seems a little crazy... ‘@’ is the delimiter, so it’s necessary to deal with ids. You can use any mark instead of ‘@’, you can choose the delimiter you like if you don’t like ‘@’.</p><p>Therefore, we can get the same result with code below in ActiveRecord.</p><pre>ids = %w(4 1 3 2)<br>ids_with_delimiter = &#39;@4@1@3@2@&#39;<br>sanitized_query = ActiveRecord::Base.send(:sanitize_sql_array, [&quot;position(&#39;@&#39;||id::text||&#39;@&#39; in ?)&quot;, ids_with_delimiter])<br>User.where(id: ids).order(sanitized_query)</pre><h3>Conclusion</h3><p>You became able to order by given array now, and you might be able to <strong>look for a solution without Rails</strong>. In Rails development, I believe it’s very important we sometimes leave Rails and to look for a solution. You should leave Rails once when you face with some problem like this article’s case.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf0775c2b60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to store files to S3 by Paperclip]]></title>
            <link>https://medium.com/@ogin/how-to-store-files-to-s3-by-paperclip-f0c558d6f49b?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0c558d6f49b</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Wed, 13 Apr 2016 01:40:08 GMT</pubDate>
            <atom:updated>2016-04-13T01:56:30.593Z</atom:updated>
            <content:encoded><![CDATA[<p>Which gem do you use when you want to store files to S3?<br>Paperclip? Carrierwave? Dragonfly? I often use Paperclip because it is simpler than others.</p><p>In this article, I’ll introduce how to store files to S3 by Paperclip, and refer to what we have to care then.</p><h3>How can I store files to S3 by Paperclip?</h3><p><strong>Paperclip stores to local file system in default</strong>, so we have to change some options like below.</p><p><strong>config/initializers/paperclip.rb</strong></p><pre>Paperclip::Attachment.default_options.merge!(<br> storage: :s3,<br> bucket: &lt;bucket_name&gt;,<br> s3_credentials: {<br>   access_key_id: &lt;access_key&gt;,<br>   secret_access_key: &lt;secret_key&gt;<br> }<br>)</pre><p>As you can see, <strong>we have to set :s3 to storage, &lt;bucket_name&gt; to bucket, and s3_credentials</strong>.</p><h3>What do we have to care?</h3><p>As I previously described, it is easy to change Paperclip options to store to S3. But it is not enough when you use Paperclip in various environments (development, test, staging, etc…). <strong>There are 4 points to use in that environments</strong>.</p><h4>We don’t want to store files to S3 in test environment, and sometimes in other environments.</h4><p>First point is about <strong>when you store files to S3</strong>. If all files are always stored to S3, it is difficult to write specs, so I think they are stored to local file system in test environment. In addition, you may want to store in the same way in other environments when you don’t prepare AWS yet.</p><pre><strong>if ENV[‘NO_S3_ATTACHMENT’] || Rails.env.test?</strong><br> Paperclip::Attachment.default_options.merge!(<br>   path: ‘:rails_root/tmp/paperclip/:filename’,<br>   url: ‘:rails_root/tmp/paperclip/:filename’<br> )<br><strong>else</strong><br> Paperclip::Attachment.default_options.merge!(<br>   storage: :s3,<br>   bucket: &lt;bucket_name&gt;,<br>   s3_credentials: {<br>     access_key_id: &lt;access_key&gt;,<br>     secret_access_key: &lt;secret_key&gt;<br>   }<br> )<br><strong>end</strong></pre><p>As you can see, in test environment or when you set ‘NO_S3_ATTACHMENT’ to environment value, you can store to local file system.</p><h4>We should set private permission to uploaded files</h4><p>Second point is about <strong>S3 permission</strong>. In many cases, we should set private permission to uploaded files to prevent anyone could get them, right?</p><pre>Paperclip::Attachment.default_options.merge!(<br> storage: :s3,<br> bucket: &lt;bucket_name&gt;,<br> <strong>s3_permissions: :private</strong>,<br> s3_credentials: {<br>   access_key_id: &lt;access_key&gt;,<br>   secret_access_key: &lt;secret_key&gt;<br> }<br>)</pre><h4>We should set other S3 information</h4><p>Third point is about <strong>other S3 information</strong>. For example, if you don’t set a path option, you cannot control where files is stored. In addition, sometimes S3 host name is required, so you should set it, too.</p><pre>Paperclip::Attachment.default_options.merge!(<br> <strong>path: ‘/xxxx/:filename’</strong>,<br> storage: :s3,<br> bucket: &lt;bucket_name&gt;,<br> <strong>s3_host_name: &lt;host_name&gt;</strong>,<br> s3_credentials: {<br>   access_key_id: &lt;access_key&gt;,<br>   secret_access_key: &lt;secret_key&gt;<br> }<br>)</pre><h4>We should set v4 to s3_signature_version</h4><p>Final point is about <strong>S3 signature version</strong>. You should set :v4 to s3_signature_version. Let me explain about this in detail in next section.</p><pre><strong>AWS.config(s3_signature_version: :v4)</strong></pre><h3>About S3 Signature version</h3><p>If you set private to s3_permissions, you must get the pre-signed url to access the file by calling <strong>expiring_url</strong>.</p><p>In paperclip (now latest version 4.3.6, and uses aws-sdk gem 1.66), default s3 signature version is <strong>v3</strong>, so you can get the following url when you call expiring_url.</p><pre><strong>paperclip_object.expiring_url(https://medium.com/5.minutes)<br></strong>=&gt;<a href="https://xxxx.s3-ap-northeast-1.amazonaws.com/xxx.pdf">https://xxxx.s3-ap-northeast-1.amazonaws.com/xxx.pdf</a>?<strong>AWSAccessKeyId=AKIA…</strong>&amp;Expires=1459224186&amp;Signature=….</pre><p>Is this a problem? Maybe sometimes yes. It’s because <strong>anyone can get the AWSAccessKeyId</strong>. Of course, that is no problem only that, but it might cause something which leads to security issue, <strong>so</strong> <strong>we should not inform it if possible</strong>.</p><p>So I believe that we should set like below.</p><pre>AWS.config(s3_signature_version: :v4)</pre><p>When we set this way, expiring_url generates the url by s3 signature version 4.</p><pre><strong>paperclip_object.expiring_url(https://medium.com/5.minutes)<br></strong>=&gt;<a href="https://xxx.s3-ap-northeast-1.amazonaws.com/xxx.pdf">https://xxx.s3-ap-northeast-1.amazonaws.com/xxx.pdf</a>?X-Amz-Algorithm=…&amp;X-Amz-Credential=…&amp;X-Amz-Date=…&amp;X-Amz-Expires=300&amp;X-Amz-Signature=…&amp;X-Amz-SignedHeaders=…</pre><p>That’s good. <strong>We can no longer get the AWSAccessKeyId</strong>.</p><h3>Conclusion</h3><p>As I construct points of this article, I suggest following code.</p><pre>if ENV[‘NO_S3_ATTACHMENT’] || Rails.env.test?<br> Paperclip::Attachment.default_options.merge!(<br>   path: ‘:rails_root/tmp/paperclip/:filename’,<br>   url: ‘:rails_root/tmp/paperclip/:filename’<br> )<br>else<br> AWS.config(s3_signature_version: :v4)<br> Paperclip::Attachment.default_options.merge!(<br>   path: ‘/xxxx/:filename’,<br>   storage: :s3,<br>   bucket: &lt;bucket_name&gt;,<br>   s3_host_name: &lt;host_name&gt;,<br>   s3_permissions: :private,<br>   s3_credentials: {<br>     access_key_id: &lt;access_key&gt;,<br>     secret_access_key: &lt;secret_key&gt;<br>   }<br> )<br>end</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0c558d6f49b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to generate various codes in Rails]]></title>
            <link>https://medium.com/@ogin/how-to-generate-various-codes-in-rails-e75f93844591?source=rss-9915753605c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e75f93844591</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Hiroshi Ogino]]></dc:creator>
            <pubDate>Wed, 30 Mar 2016 13:43:43 GMT</pubDate>
            <atom:updated>2016-03-31T03:05:10.350Z</atom:updated>
            <content:encoded><![CDATA[<p>I am a Rails developer. In my experiences, I wanted various codes in the various situation. I’ll introduce <strong>3 methods</strong> to generate them.</p><h3>1. Random decimal code</h3><p>When we want random decimal code simply, it’s very easy. For example, when we want decimal code <strong>from 1 to 100</strong>, we can use following method.</p><pre>Random.rand(100) + 1</pre><p>or</p><pre>Random.rand(1..100)</pre><h3>2. Code which meets eyes of a user</h3><p>If we have to show a user some kind of codes, like an error code, it should be <strong>fixed length</strong> and <strong>non-semantic</strong>. In this case, we can use following method.</p><pre>((‘A’..’Z’).to_a + (0..9).to_a).sample(12).join</pre><p>In this method, the same code may be generated and it may not have good performance. However, I think it is not to worry because it is not executed frequently. We should design like that rather than it. If you worried about them, you might use <strong>next method</strong>.</p><h3>3. New code relevant to original code</h3><p>We sometimes have to use <strong>long-length-code</strong> and want to put index on it.<br>However, for example, if we use MySQL we may not put index because index max key length is <strong>767 byte</strong> in MySQL. In this case, we can generate the new code from the original code like following method, and put index on it. (Of course, we should add column for it.)</p><pre>Digest::MD5.hexdigest(original_code)</pre><p>If we manage original_codes, like 1, 2, 3, …, we might use this method in second case <strong>‘Code which meets eyes of a user’</strong>, because this generates the<strong> fixed length</strong> and <strong>non-semantic</strong> code, too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e75f93844591" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>