<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: fiona</title>
    <description>The latest articles on DEV Community by fiona (@chanyayun).</description>
    <link>https://dev.to/chanyayun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F203501%2F174fc7cf-fbbd-4f57-b0a9-796314009e27.jpg</url>
      <title>DEV Community: fiona</title>
      <link>https://dev.to/chanyayun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chanyayun"/>
    <language>en</language>
    <item>
      <title>Jaspersoft Studio: Using a new font in the report</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Sun, 19 May 2024 21:43:27 +0000</pubDate>
      <link>https://dev.to/chanyayun/jaspersoft-studio-using-a-new-font-in-the-report-45h0</link>
      <guid>https://dev.to/chanyayun/jaspersoft-studio-using-a-new-font-in-the-report-45h0</guid>
      <description>&lt;h2&gt;
  
  
  Problem (murmurs)
&lt;/h2&gt;

&lt;p&gt;This is my first time using Jaspersoft Studio. Once my coworkers downloaded a new font, the font would appear in the selection box automatically after restarting Jaspersoft Studio. However that is not my case. Neither restarting the application nor the computer works for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;I refer to the &lt;a href="https://community.jaspersoft.com/documentation/jaspersoft%C2%AE-studio/tibco-jaspersoft-studio-user-guide/v630/working-font-extensions/"&gt;documentation&lt;/a&gt; from Jaspersoft community.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;On the tool bar, select Window &amp;gt; Preferences. Then find Jaspersoft Studio &amp;gt; Fonts.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyq73jfzu8c7ctmj0tsk4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyq73jfzu8c7ctmj0tsk4.png" alt="Jaspersoft Studio &amp;gt; Fonts" width="725" height="738"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select Add From Path on the right and select the folder of the &lt;code&gt;.ttf&lt;/code&gt; file of the downloaded font. (Not from the &lt;em&gt;Fonts&lt;/em&gt; folder in Windows OS but the actual file path.) Select Finish and after the application analyzes the folder, the font would appear in Font List.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdznlaxilg3s8sotm7vj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdznlaxilg3s8sotm7vj2.png" alt="Add From Path" width="725" height="738"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply and close the Preferences window. Right click the project you are working on and select Properties. You can see the font in Font List of Workspace Settings. 🙌&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ms7oc1g48rq687ztj5m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ms7oc1g48rq687ztj5m.png" alt="query is my project name" width="725" height="798"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The font would now appear in the selection box as expected. 🎉🎉&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff0ce7f6bchjiz16dy92w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff0ce7f6bchjiz16dy92w.png" alt="New font would automatically appears" width="441" height="372"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>jaspersoft</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>replace the last comma to period in string</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Sat, 12 Mar 2022 08:37:11 +0000</pubDate>
      <link>https://dev.to/chanyayun/replace-the-last-comma-to-period-in-string-55p9</link>
      <guid>https://dev.to/chanyayun/replace-the-last-comma-to-period-in-string-55p9</guid>
      <description>&lt;p&gt;To slightly modify a string, like replacing its first character to capital or last character from comma to period, there are two ways to achieve.&lt;/p&gt;

&lt;h3&gt;
  
  
  use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace"&gt;&lt;code&gt;replace()&lt;/code&gt;&lt;/a&gt; with regex
&lt;/h3&gt;

&lt;p&gt;There are two things worth notice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;without using regular expression, only the first-matched substring will be replaced.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;replace()&lt;/code&gt; function returns a new string and left the old string unchanged.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// replace the last comma to period&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;anne, ben, carol, dennis, evans,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/,$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// anne, ben, carol, dennis, evans.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice"&gt;&lt;code&gt;slice()&lt;/code&gt;&lt;/a&gt; and append
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// replace the last comma to period&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;anne, ben, carol, dennis, evans,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// anne, ben, carol, dennis, evans.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;slice(indexStart, indexEnd)&lt;/code&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring"&gt;&lt;code&gt;substring(indexStart, indexEnd)&lt;/code&gt;&lt;/a&gt; are almost identical with some slight differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;indexEnd&lt;/code&gt; is optional in both functions, if not specified it would extract to the end of the string. Otherwise, it is the first character to &lt;em&gt;exclude&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;If value is less than 0 or &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;substring()&lt;/code&gt; would consider 0. &lt;code&gt;slice()&lt;/code&gt; would consider &lt;code&gt;NaN&lt;/code&gt; 0, and negative values count backwards from the end.&lt;/li&gt;
&lt;li&gt;If value is greater than &lt;code&gt;stringName.length&lt;/code&gt;, it would consider &lt;code&gt;stringName.length&lt;/code&gt; in both functions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;substring()&lt;/code&gt; swap the arguements if &lt;code&gt;indexStart&lt;/code&gt; is greater than &lt;code&gt;indexEnd&lt;/code&gt;, &lt;code&gt;slice()&lt;/code&gt; returns an empty string.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>set up keyboard shortcut to open terminal on mac</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Sat, 05 Mar 2022 07:03:20 +0000</pubDate>
      <link>https://dev.to/chanyayun/set-up-keyboard-shortcut-to-open-terminal-in-mac-47f5</link>
      <guid>https://dev.to/chanyayun/set-up-keyboard-shortcut-to-open-terminal-in-mac-47f5</guid>
      <description>&lt;p&gt;I am currently using Monterey. These are actually simple steps to set up the shortcut. (NO coding required! yay! 😌)&lt;/p&gt;

&lt;h2&gt;
  
  
  open Automator
&lt;/h2&gt;

&lt;p&gt;It is under &lt;strong&gt;Applications &amp;gt; Other &amp;gt; Automator&lt;/strong&gt;. Once open a new file, select &lt;strong&gt;Quick Action&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2932iwpoxddwjh0s9mx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc2932iwpoxddwjh0s9mx.png" alt="create a type for your document"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For convenience, if the window is blank like below, select &lt;strong&gt;View &amp;gt; Show Library&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqernnfhrvaplgrhqo2ui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqernnfhrvaplgrhqo2ui.png" alt="new file window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the search box to find &lt;strong&gt;Launch Application&lt;/strong&gt;. Then double-click or drag it to the right-hand side.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1feey86nvcpuolqu5umr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1feey86nvcpuolqu5umr.png" alt="search launch application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the application from the default &lt;strong&gt;Contact&lt;/strong&gt; to &lt;strong&gt;Terminal&lt;/strong&gt;. (Select &lt;strong&gt;Other...&lt;/strong&gt; and &lt;strong&gt;Terminal&lt;/strong&gt; can be found in the &lt;strong&gt;Utilities&lt;/strong&gt; folder)&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxrn6xk17vxkwe0xkch2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxrn6xk17vxkwe0xkch2.png" alt="change application to terminal"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Select &lt;strong&gt;Run&lt;/strong&gt; on the upper right of the window to make sure the terminal is launched as expected. Then save the file. I have my file named &lt;code&gt;open terminal&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  open System Preferences
&lt;/h2&gt;

&lt;p&gt;Under &lt;strong&gt;System Preferences &amp;gt; Keyboard &amp;gt; Shortcuts &amp;gt; Services&lt;/strong&gt;, find the file name. By clicking on it, select &lt;strong&gt;Add Shortcut&lt;/strong&gt; and set up the keyboard shortcut you prefer. I use &lt;code&gt;cmd+opt+T&lt;/code&gt; as linux command.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0821sma848bhf6q5e73.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0821sma848bhf6q5e73.png" alt="open terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now it is all set up! 😬&lt;/p&gt;

</description>
      <category>macos</category>
      <category>shortcut</category>
      <category>productivity</category>
    </item>
    <item>
      <title>problem: Java Date and Time</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Sun, 27 Feb 2022 19:15:16 +0000</pubDate>
      <link>https://dev.to/chanyayun/problem-java-date-and-time-4gp0</link>
      <guid>https://dev.to/chanyayun/problem-java-date-and-time-4gp0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.hackerrank.com/challenges/java-date-and-time/problem"&gt;Link to the problem&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Input would be &lt;code&gt;month day year&lt;/code&gt;, and output the day of week.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//sample input
08 05 2015

//sample output
WEDNESDAY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  proper solution
&lt;/h2&gt;

&lt;p&gt;DISCLAIMER: the solution referenced from the editorial&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;findDay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Calendar&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Calendar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Calendar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;DAY_OF_WEEK&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//error&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code would have error because &lt;code&gt;date.get(Calendar.DAY_OF_WEEK)&lt;/code&gt; returns &lt;em&gt;integer value&lt;/em&gt; of day of week. For example, returns 1 for SUNDAY, 2 for MONDAY, and 7 for SATURDAY.&lt;/p&gt;

&lt;p&gt;We need to create an additional array to reference day of week:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// outside main method&lt;/span&gt;
&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;dayOfWeek&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"SUNDAY"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"MONDAY"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"TUESDAY"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"WEDNESDAY"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"THURSDAY"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"FRIDAY"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"SATURDAY"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;findDay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Calendar&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Calendar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dayOfWeek&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Calendar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;DAY_OF_WEEK&lt;/span&gt;&lt;span class="o"&gt;)-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  use another class
&lt;/h2&gt;

&lt;p&gt;Instead of the class &lt;code&gt;java.util.Calendar&lt;/code&gt; it mentioned, &lt;code&gt;java.time.LocalDate&lt;/code&gt; (Java 8 and higher) actually finish all the work nice and neat.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;findDay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;LocalDate&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LocalDate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDayOfWeek&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//getDayOfWeek() returns a DayOfWeek object&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>hackerrank</category>
      <category>java</category>
    </item>
    <item>
      <title>android to mac file transfer</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Thu, 23 Dec 2021 09:52:37 +0000</pubDate>
      <link>https://dev.to/chanyayun/android-to-mac-file-transfer-1o6b</link>
      <guid>https://dev.to/chanyayun/android-to-mac-file-transfer-1o6b</guid>
      <description>&lt;p&gt;I simply want to transfer file from android to mac. Initially I use &lt;a href="https://www.android.com/filetransfer/"&gt;Android File Transfer&lt;/a&gt;, however it stucks at 4GB.&lt;/p&gt;

&lt;p&gt;By considering &lt;a href="https://android.stackexchange.com/questions/48812/bypass-4gb-limitation-of-android-file-transfer"&gt;this post&lt;/a&gt;, I install &lt;code&gt;android-platform-tools&lt;/code&gt; for file transfer.&lt;/p&gt;

&lt;h3&gt;
  
  
  step 1
&lt;/h3&gt;

&lt;p&gt;on mac, install &lt;code&gt;android-platform-tools&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install android-platform-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  step 2
&lt;/h3&gt;

&lt;p&gt;connect the android device with USB-C to mac.&lt;br&gt;
on the device, go to &lt;a href="https://developer.android.com/studio/run/device"&gt;settings &amp;gt; developer options &amp;gt; enable USB debugging&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE: on xiaomi 9, tap &lt;strong&gt;MIUI version&lt;/strong&gt; 7 times to enable developer options&lt;/p&gt;
&lt;h3&gt;
  
  
  step 3
&lt;/h3&gt;

&lt;p&gt;on mac, run &lt;code&gt;adb devices&lt;/code&gt; to confirm that android is connected to mac.&lt;/p&gt;
&lt;h3&gt;
  
  
  step 4
&lt;/h3&gt;

&lt;p&gt;to copy file to mac, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adb pull &amp;lt;device_file_location&amp;gt; &amp;lt;mac_location&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to copy file to device, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adb push &amp;lt;mac_file_location&amp;gt; &amp;lt;device_location&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;please let me know if there is any other way more straightforward! 😬&lt;/p&gt;

</description>
      <category>android</category>
    </item>
    <item>
      <title>Heroku: deploy with an existing git repo</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Tue, 27 Oct 2020 19:55:58 +0000</pubDate>
      <link>https://dev.to/chanyayun/heroku-deploy-with-an-existing-git-repo-3m5k</link>
      <guid>https://dev.to/chanyayun/heroku-deploy-with-an-existing-git-repo-3m5k</guid>
      <description>&lt;p&gt;This is my first time using Heroku. Most tutorials I found on the internet deploy their app while creating a new git repository. However, I already have an existing git repository. After trial and error, I realize the &lt;a href="https://devcenter.heroku.com/articles/git#creating-a-heroku-remote"&gt;documentation&lt;/a&gt; is brief and clear all the time but I wasn't able to understand at first. 😧&lt;/p&gt;




&lt;p&gt;With an existing git repository currently working on &lt;code&gt;origin develop&lt;/code&gt; branch, in order not to let heroku settings affect &lt;code&gt;develop&lt;/code&gt; branch, there is NO need to create a new origin branch then push it there. (&amp;lt;-- it wouldn't affect at all...a silly thing I did at first)&lt;/p&gt;

&lt;h3&gt;
  
  
  Required packages (pip install)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gunicorn
whitenoise
django-heroku
psycopg2 # not sure if preinstalled from prior
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Django settings for Heroku
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;create &lt;code&gt;Procfile&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;do not add extension after file name!&lt;/li&gt;
&lt;li&gt;most tutorials write &lt;code&gt;web: gunicorn mysite.wsgi&lt;/code&gt; in Procfile, use &lt;code&gt;web: gunicorn --pythonpath mysite mysite.wsgi&lt;/code&gt; instead. (&amp;lt;-- repository location reseaon)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;create &lt;code&gt;requirements.txt&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pip freeze &amp;gt; requirements.txt&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;in order for heroku to detect python buildpack&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;modify &lt;code&gt;settings.py&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;add &lt;code&gt;import django_heroku&lt;/code&gt; on the top of the file&lt;/li&gt;
&lt;li&gt;add &lt;code&gt;django_heroku.settings(locals())&lt;/code&gt; in the file&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's important to notice the working directory. Normally, the django &lt;code&gt;mysite&lt;/code&gt; project folder will also be the github repository folder. But I have my github folder outside &lt;code&gt;mysite&lt;/code&gt; project folder.&lt;/p&gt;

&lt;p&gt;Below is how I locate my required files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# my local github repository folder
.
├── Procfile
├── README.md
├── data
├── mysite
│   ├── mysite
│   │   ├── __init__.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── prediction
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── models.py
│   │   └── views
│   ├── static
└── requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. Create a Heroku account
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://devcenter.heroku.com/articles/heroku-cli"&gt;Install&lt;/a&gt; &lt;strong&gt;Heroku CLI&lt;/strong&gt; in order to use &lt;code&gt;heroku&lt;/code&gt; command in the command line.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create an app
&lt;/h3&gt;

&lt;p&gt;Under the working directory (for my case, my local repository), run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku create &amp;lt;app_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Heroku generates a random name if &lt;code&gt;&amp;lt;app_name&amp;gt;&lt;/code&gt; left blank.&lt;br&gt;
Or create an app from the website &amp;gt; dashboard &amp;gt; create an app.&lt;br&gt;
(Most settings can actually be done from the website as well.)&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Create a Heroku remote
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku git:remote -a &amp;lt;app_name&amp;gt;

# to check if remote is added
git remote -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Deploy the app
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# either one is fine
git push heroku master
git push heroku main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the local branch name can only be &lt;code&gt;master&lt;/code&gt; or &lt;code&gt;main&lt;/code&gt;. If the local branch is neither, run &lt;code&gt;git push heroku &amp;lt;local_branch_name&amp;gt;:master&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Visit the app
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku open

#if required login
heroku login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>heroku</category>
      <category>django</category>
    </item>
    <item>
      <title>Git: push to a new remote branch</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Tue, 27 Oct 2020 17:19:13 +0000</pubDate>
      <link>https://dev.to/chanyayun/git-push-to-a-new-remote-branch-2gm5</link>
      <guid>https://dev.to/chanyayun/git-push-to-a-new-remote-branch-2gm5</guid>
      <description>&lt;p&gt;It is important to specify &lt;code&gt;&amp;lt;remote&amp;gt; &amp;lt;branch&amp;gt;&lt;/code&gt; in every pull and push in the scenario. If not specified, would be default master.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;branch
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# list all branches, including local and remote
git branch -a

# create new local branch
git branch &amp;lt;new_branch_name&amp;gt;

# switch to another branch
git checkout &amp;lt;another_branch&amp;gt;

# switch no to new local branch (combine the steps above)
git checkout -b &amp;lt;new_branch_name&amp;gt;

# delete a branch, use -D for force delete
# need to checkout to another branch before delete
git branch -d &amp;lt;branch&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;clone
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# clone a repository in specific remote branch
git clone --branch &amp;lt;branch_name&amp;gt; &amp;lt;remote_repo_url&amp;gt;
git clone -b &amp;lt;branch_name&amp;gt; &amp;lt;remote_repo_url&amp;gt;

# clone a specific remote branch 
# and does not track other remote branch
git clone -b &amp;lt;branch_name&amp;gt; --single-branch &amp;lt;remote_repo_url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;pull (fetch+merge)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull origin &amp;lt;branch&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;push
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# push to a new remote branch not yet created
git push --set-upstream &amp;lt;remote&amp;gt; &amp;lt;branch_name&amp;gt;
git push -u &amp;lt;remote&amp;gt; &amp;lt;branch_name&amp;gt;

# push to remote branch
git push &amp;lt;remote&amp;gt; &amp;lt;branch_name&amp;gt;

# delete a remote branch
git push &amp;lt;remote&amp;gt; --delete &amp;lt;remote_branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usually &lt;code&gt;&amp;lt;remote&amp;gt;&lt;/code&gt; would be &lt;code&gt;origin&lt;/code&gt; unless working with another repository (eg. deploying app to heroku)&lt;br&gt;
&lt;code&gt;origin&lt;/code&gt; stands for the remote repository that a project was originally cloned from.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;overwrite local repository
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git fetch --all
git reset --hard origin/master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replace master with whatever branch originally wanted&lt;/p&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>git lfs</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Mon, 24 Aug 2020 08:28:24 +0000</pubDate>
      <link>https://dev.to/chanyayun/git-lfs-1fgo</link>
      <guid>https://dev.to/chanyayun/git-lfs-1fgo</guid>
      <description>&lt;p&gt;I encounter an error when I push my database to Github, and git suggest to checkout &lt;strong&gt;git lfs (large files storage)&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;Quoted from &lt;a href="https://www.atlassian.com/git/tutorials/git-lfs#installing-git-lfs"&gt;the article&lt;/a&gt; by Atlassian, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Git LFS does this by replacing large files in your repository with tiny pointer files. During normal usage, you'll never see these pointer files as they are handled automatically by Git LFS&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's so easy to apply even with an existing large file, for the case, my database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# for the very first time, run install
git lfs install

# add the large files you want to track
git lfs track '*.sqlite3'

# without argument, you can see the patterns being tracked
git lfs track

# show the files being tracked
git lfs ls-files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that after running &lt;code&gt;git lfs track '*.sqlite3'&lt;/code&gt;, it will auto create a file &lt;code&gt;.gitattributes&lt;/code&gt; record the patterns.&lt;/p&gt;

&lt;p&gt;Then commit your large file and .gitattributes to github, done.&lt;/p&gt;

&lt;p&gt;When others trying to git pull the remote repo, after running &lt;code&gt;git lfs install&lt;/code&gt; (only the very first time), they can &lt;code&gt;git pull&lt;/code&gt; as usual.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
reference:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/git-lfs/git-lfs/wiki/Tutorial"&gt;git-lfs/wiki/Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials/git-lfs#installing-git-lfs"&gt;Git LFS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;UPDATE:&lt;br&gt;
After adding more data to the database, github reaches its limit even with lfs.😓&lt;br&gt;
Let's just keep the database in local file.&lt;br&gt;
(^._.^)ﾉ&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OAZdDBj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w2e7oyj283394jj1ka5x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OAZdDBj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w2e7oyj283394jj1ka5x.jpg" alt="repo over data quota"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Django: set default value for datetime field</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Sat, 15 Aug 2020 16:42:47 +0000</pubDate>
      <link>https://dev.to/chanyayun/django-set-default-value-for-datetime-field-1clc</link>
      <guid>https://dev.to/chanyayun/django-set-default-value-for-datetime-field-1clc</guid>
      <description>&lt;p&gt;When running &lt;code&gt;makemigrations&lt;/code&gt; after adding new fields to the current model, django would ask for a default value in order to save in the datebase when fields created.&lt;/p&gt;

&lt;p&gt;However, I do not set default value to fields I know it is not nullable and would have a certain value assigned already before saving in the database.&lt;/p&gt;

&lt;p&gt;The way I compromise is to give a default value when django asks me to in the terminal. For numeric fields I go with 0, and an empty string for character fields.&lt;/p&gt;

&lt;p&gt;I find it quite confusing when I first encounter the issue of setting a default value for datetime field since I do not often encounter this problem if I set the field in the first place as the model initially created.&lt;/p&gt;

&lt;p&gt;The terminal gives a useful tip suggest that you can use &lt;code&gt;timezone.now()&lt;/code&gt; as default. But I still kind of prefer a more generic datetime. And &lt;code&gt;datetime.datetime(1900,1,1)&lt;/code&gt; works.&lt;/p&gt;

&lt;p&gt;PS. I am referring to both date and datetime field when mentioning datetime field.&lt;/p&gt;

&lt;p&gt;2020/8/17 edit: It is rather dumb to not set default in field argument, cause later giving default values in terminal would be such a pain when there are many fields.&lt;/p&gt;

</description>
      <category>django</category>
    </item>
    <item>
      <title>Django: reset auto-increment id to 1</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Tue, 04 Aug 2020 08:32:13 +0000</pubDate>
      <link>https://dev.to/chanyayun/django-reset-auto-increment-id-to-1-2j2g</link>
      <guid>https://dev.to/chanyayun/django-reset-auto-increment-id-to-1-2j2g</guid>
      <description>&lt;p&gt;The discussion in stackoverflow &lt;a href="https://stackoverflow.com/questions/27735375/django-model-instances-primary-keys-do-not-reset-to-1-after-all-instances-are-de/27735430"&gt;here&lt;/a&gt; gave a clear view of how to handle the problem, which many argue and I do agree that the id should not be reset since it is unique and should not be recreated.&lt;/p&gt;

&lt;p&gt;Anyway, for the clarity of my database id, I still tend to do so. Simply erase table data from SQLiteStudio, or run &lt;code&gt;objects.all().delete()&lt;/code&gt; does not reset the id. The answer provided in the above stackoverflow for sqlite is to run a sql command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- reset index

DELETE FROM &amp;lt;table_name&amp;gt;; 
DELETE FROM SQLite_sequence WHERE name='&amp;lt;table_name&amp;gt;';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;UPDATE:&lt;br&gt;
It also works when adding data to table with existing data.&lt;br&gt;
In a senario where you import the wrong data, you can remove the data by the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- delete certain rows (only keep rows that are between)

DELETE FROM &amp;lt;table_name&amp;gt;
WHERE id NOT IN (SELECT id FROM &amp;lt;table_name&amp;gt; WHERE id BETWEEN &amp;lt;int&amp;gt; AND &amp;lt;int&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the previous reset index command to let the index remain consistent before import another data.&lt;/p&gt;

</description>
      <category>django</category>
    </item>
    <item>
      <title>Django: switch from sqlite3 to mysql</title>
      <dc:creator>fiona</dc:creator>
      <pubDate>Mon, 02 Dec 2019 19:05:43 +0000</pubDate>
      <link>https://dev.to/chanyayun/django-switch-from-sqlite3-to-mysql-2i6o</link>
      <guid>https://dev.to/chanyayun/django-switch-from-sqlite3-to-mysql-2i6o</guid>
      <description>&lt;p&gt;assume there is an existing sqlite3 db with data in django app&lt;/p&gt;

&lt;p&gt;in command prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py dumpdata &amp;gt; datadump.json
# to export existing data into a json file
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;create a new schema in mysql server&lt;br&gt;
(mysql should have been installed already)&lt;br&gt;
&lt;em&gt;for my own information:&lt;/em&gt; &lt;a href="https://stackoverflow.com/questions/11618277/difference-between-schema-database-in-mysql"&gt;Difference Between Schema / Database in MySQL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;in settings.py:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;'default'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;'ENGINE'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'django.db.backends.mysql'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'NAME'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'&amp;lt;schema_name&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'USER'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'root'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'PASSWORD'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'*****'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'HOST'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'localhost'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'PORT'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'&amp;lt;port_num&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;in command prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install mysqlclient
# mysqlclient is a fork from MySQLdb1 which supports python3
# both are MySQL database connector for Python
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;more info: &lt;a href="https://stackoverflow.com/questions/43102442/whats-the-difference-between-mysqldb-mysqlclient-and-mysql-connector-python"&gt;What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;then &lt;code&gt;makemigrations&lt;/code&gt;, &lt;code&gt;migrate&lt;/code&gt; and finally,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py loaddata datadump.json
# should return sth like "Installed 59 object(s) from 1 fixture(s)"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;done.&lt;/p&gt;

&lt;h4&gt;
  
  
  problem shooting (not ideal but smh works)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;delete the files in 'migrations' folder (except for __init__)&lt;/li&gt;
&lt;li&gt;"duplicate entry" -&amp;gt; drop the schema in mysql and create a new one&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  reference
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;stackoverflow: &lt;a href="https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql"&gt;What's the best way to migrate a Django DB from SQLite to MySQL?&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;pythonanywhere forums: &lt;a href="https://www.pythonanywhere.com/forums/topic/13850/"&gt;Switch from SQLite to MySQL&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;a post from Nicolas Kuttler: &lt;a href="https://kuttler.eu/en/post/django-db-utils-IntegrityError-duplicate-entry/"&gt;Migrating Django projects with fixtures&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>django</category>
    </item>
  </channel>
</rss>
