<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Dinh</title>
    <description>on learning and programming</description>
    <link>https://dinhvle.com/</link>
    <atom:link href="https://dinhvle.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Fri, 24 Sep 2021 02:25:02 +0000</pubDate>
    <lastBuildDate>Fri, 24 Sep 2021 02:25:02 +0000</lastBuildDate>
    <generator>Jekyll v3.9.0</generator>
    
      <item>
        <title>Upgrading PostgreSQL on macOS</title>
        <description>&lt;p&gt;Follow these easy steps to upgrade your PostgreSQL without losing your data. For this post, I’m upgrading from 9.6.2 to 10.4!&lt;/p&gt;

&lt;h4 id=&quot;1-shut-down-postgresql-server&quot;&gt;1. Shut down PostgreSQL server&lt;/h4&gt;

&lt;p&gt;Assuming you are using Homebrew.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;brew services stop postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-update-postgresql&quot;&gt;2. Update PostgreSQL&lt;/h4&gt;

&lt;p&gt;Use Homebrew to upgrade your PostgreSQL.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;brew update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; brew upgrade postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;3-initialize-a-new-data-directory&quot;&gt;3. Initialize a new data directory&lt;/h4&gt;

&lt;p&gt;To upgrade PostgreSQL and keep our old data, we need to migrate data from the old data directory to a new one. In order to do that, we need to create a new data directory first.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;initdb /usr/local/var/postgres10.4 &lt;span class=&quot;nt&quot;&gt;-E&lt;/span&gt; utf8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;4-migrate-old-data-from-old-directory-to-new-one&quot;&gt;4. Migrate old data from old directory to new one&lt;/h4&gt;

&lt;p&gt;This can be done using &lt;code class=&quot;language-shell highlighter-rouge&quot;&gt;pg_upgrade&lt;/code&gt;, we just need to specify the old data and executable directory (-d and -b), the new data and executable directory (-D and -B). Read more on &lt;code class=&quot;language-shell highlighter-rouge&quot;&gt;pg_upgrade&lt;/code&gt; &lt;a href=&quot;https://www.postgresql.org/docs/9.6/static/pgupgrade.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pg_upgrade &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; /usr/local/var/postgres &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; /usr/local/var/postgres10.4 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; /usr/local/Cellar/postgresql/9.6.2/bin/ &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;-B&lt;/span&gt; /usr/local/Cellar/postgresql/10.4/bin/ &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;5-rename-the-data-directory&quot;&gt;5. Rename the data directory&lt;/h4&gt;

&lt;p&gt;PostgreSQL will look for postgres directory, so we just need to rename our new directory.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /usr/local/var
&lt;span class=&quot;c&quot;&gt;# rename the old postgres to postgres9.6.2 as back up&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;mv &lt;/span&gt;postgres postgres9.6.2
&lt;span class=&quot;c&quot;&gt;# rename our new data directory to postgres&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;mv &lt;/span&gt;postgres10.4 postgres
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;6-start-postgresql-back-up&quot;&gt;6. Start PostgreSQL back up&lt;/h4&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;brew services start postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With that, our PostgreSQL server should be live with all of our old data.&lt;/p&gt;
</description>
        <pubDate>Tue, 22 May 2018 00:00:00 +0000</pubDate>
        <link>https://dinhvle.com/2018/05/22/upgrading-postgresql-on-macos.html</link>
        <guid isPermaLink="true">https://dinhvle.com/2018/05/22/upgrading-postgresql-on-macos.html</guid>
        
        
      </item>
    
      <item>
        <title>Find the parity outlier</title>
        <description>&lt;p&gt;To practice and sharpen my Javascript skill, I’ve been trying to do challenges at &lt;a href=&quot;https://www.codewars.com&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Codewars&lt;/a&gt; whenever I have time. Here is a challenge I’ve done recently, and how I solved it.&lt;/p&gt;

&lt;h4 id=&quot;challenge&quot;&gt;Challenge&lt;/h4&gt;

&lt;p&gt;You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns N.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;[2, 4, 0, 100, 4, 11, 2602, 36]&lt;/p&gt;

&lt;p&gt;Should return: 11&lt;/p&gt;

&lt;p&gt;[160, 3, 1719, 19, 11, 13, -21]&lt;/p&gt;

&lt;p&gt;Should return: 160&lt;/p&gt;

&lt;h4 id=&quot;solution&quot;&gt;Solution&lt;/h4&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;findOutlier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;integers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;odds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;evens&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[];&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;integers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;integers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;evens&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;integers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;odds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;integers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;odds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;evens&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;evens&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;odds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;   
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To get to the correct solution, first I need to split the array of integers into two arrays, an odds and evens array. Then I just compare the arrays’ length and return the first item of the shorter array. (You can also return the first item of the array with length equal to one since there is only one odd or one even integer).&lt;/p&gt;
</description>
        <pubDate>Mon, 19 Sep 2016 00:00:00 +0000</pubDate>
        <link>https://dinhvle.com/2016/09/19/find-the-parity-outlier.html</link>
        <guid isPermaLink="true">https://dinhvle.com/2016/09/19/find-the-parity-outlier.html</guid>
        
        
      </item>
    
      <item>
        <title>Grails 3 setup on Mac OS X</title>
        <description>&lt;amp-img width=&quot;800&quot; height=&quot;210&quot; layout=&quot;responsive&quot; src=&quot;/assets/images/grails-logo.png&quot;&gt;&lt;/amp-img&gt;

&lt;p&gt;I had to install &lt;a href=&quot;https://grails.org/&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Grails&lt;/a&gt; recently to work on one of my projects. This is the easiest way I’ve found to install Grails on your OS X.&lt;/p&gt;

&lt;h4 id=&quot;installing-jdk&quot;&gt;Installing JDK&lt;/h4&gt;

&lt;p&gt;For Grails 3 you will need Java Development Kit (JDK) version 1.7 or above. Although &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u80-oth-JPR&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Java SE Development Kit 7&lt;/a&gt; is no longer getting an update from Oracle, you should install this kit since most Grails version work with it. Just download and run the installer.&lt;/p&gt;

&lt;p&gt;After installation, you can verify by running:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;java &lt;span class=&quot;nt&quot;&gt;-version&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# java version &quot;1.7.*_*&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;installing-grails&quot;&gt;Installing Grails&lt;/h4&gt;

&lt;p&gt;The easiest way to install Grails on OS X is with &lt;a href=&quot;http://sdkman.io/index.html&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;SDKMAN!&lt;/a&gt;. Just run:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; get.sdkman.io | bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Follow the instructions on-screen to complete the installation.
Open terminal and type the command:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/.sdkman/bin/sdkman-init.sh&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then install the latest stable Grails:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sdk &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;grails
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After installation is complete, check version with:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;grails &lt;span class=&quot;nt&quot;&gt;-version&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Grails version: 3.*.*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s it. Unless you are working on a project that needs an older version of Grails, in that case, just install that version and use it by:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sdk &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;grails 2.4.4
sdk use grails 2.4.4
&lt;span class=&quot;c&quot;&gt;# For example, if you want to use Grails 2.4.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Sat, 17 Sep 2016 00:00:00 +0000</pubDate>
        <link>https://dinhvle.com/2016/09/17/grails-3-setup-on-mac-os-x.html</link>
        <guid isPermaLink="true">https://dinhvle.com/2016/09/17/grails-3-setup-on-mac-os-x.html</guid>
        
        
      </item>
    
      <item>
        <title>My first post</title>
        <description>&lt;p&gt;My plan for this website is to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Write down things that I find interesting or helpful.&lt;/li&gt;
  &lt;li&gt;Showcase my projects.&lt;/li&gt;
  &lt;li&gt;Experiment with ruby, jekyll and google’s amp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am currently in a full-stack web-dev program at &lt;a href=&quot;http://www.galvanize.com&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;galvanize&lt;/a&gt;, so I’m pretty busy, but I’ll try to post at least once a week.&lt;/p&gt;
</description>
        <pubDate>Sun, 12 Jun 2016 00:00:00 +0000</pubDate>
        <link>https://dinhvle.com/2016/06/12/my-first-post.html</link>
        <guid isPermaLink="true">https://dinhvle.com/2016/06/12/my-first-post.html</guid>
        
        
      </item>
    
  </channel>
</rss>
