<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>nickczj.com</title>
 <link href="https://nickczj.com/atom.xml" rel="self"/>
 <link href="https://nickczj.com/"/>
 <updated>2023-03-11T13:00:06+00:00</updated>
 <id>https://nickczj.com</id>
 <author>
   <name></name>
   <email></email>
 </author>

 
 <entry>
   <title>Physx 3: Calculus Homework, Part 2</title>
   <link href="https://nickczj.com/2021/11/12/calculus-homework-2"/>
   <updated>2021-11-12T00:00:00+00:00</updated>
   <id>https://nickczj.com/2021/11/12/calculus-homework-2</id>
   <content type="html">&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3.0.1/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Continuing my &lt;a href=&quot;/2021/11/12/calculus-homework-1&quot;&gt;series on calculus&lt;/a&gt;, I am doing the Practice Quiz on functions &lt;a href=&quot;https://www.coursera.org/learn/single-variable-calculus/home/week/2&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2021-11-12-calculus/challenge-hw-q1.png&quot; alt=&quot;Q1.&quot; /&gt;
Firstly, we need to understand the function of \(ln\) whose domain is \((0, +∞)\) and range \((-∞, +∞)\).
That means we need to restrict \(\sin x\) to \((0, +∞)\), which is it’s range.
i.e. What domain of \(\sin x\) would we have to restrict to produce a range of \((0, +∞)\)?&lt;/p&gt;

&lt;p&gt;Taking a look at the domain &amp;amp; range of sin, we have this:&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;
\begin{gather*}
D = (-∞, +∞)\\
\Bbb R = (-1, 1)
\end{gather*}
&lt;/p&gt;

&lt;p&gt;It is now clear that sine values between -1 and 0 inclusive is invalid. Hence, the answer is the domain of sine of which it produces values of range (0, 1). &lt;a href=&quot;https://i.stack.imgur.com/OBSn1.gif&quot;&gt;Recapping some common sine values&lt;/a&gt;, we can see that x can be between 0 and π. But not between π and 2π. This represents 1 oscillation of the sine wave. In the next oscillation, x is valid between 2π and 3π but invalid between 3π and 4π.&lt;/p&gt;

&lt;p&gt;Hence, coming back to the question, n needs to be even to satisfy the above pattern. Back to the restriction we need with ln, 0 is not inclusive, so our range for x cannot include 0 as well. 
Therefore, the answer is the 3rd option: \(\big( n\pi, (n+1)\pi \big)\).&lt;br /&gt;&lt;/p&gt;
&lt;p class=&quot;linebreak&quot;&gt;▬▬ι══════════════ι▬▬&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2021-11-12-calculus/challenge-hw-q2.png&quot; alt=&quot;Q2.&quot; /&gt;
&lt;img src=&quot;/assets/2021-11-12-calculus/q2-ans.jpg&quot; alt=&quot;Q2-ans&quot; /&gt;&lt;/p&gt;
&lt;p class=&quot;linebreak&quot;&gt;▬▬ι══════════════ι▬▬&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2021-11-12-calculus/challenge-hw-q3.png&quot; alt=&quot;Q3.&quot; /&gt;
&lt;img src=&quot;/assets/2021-11-12-calculus/q3-ans.jpg&quot; alt=&quot;Q3-ans&quot; /&gt;&lt;/p&gt;
&lt;p class=&quot;linebreak&quot;&gt;▬▬ι══════════════ι▬▬&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/2021-11-12-calculus/challenge-hw-q4.png&quot; alt=&quot;Q4.&quot; /&gt;
&lt;img src=&quot;/assets/2021-11-12-calculus/q4-ans.jpg&quot; alt=&quot;Q4-ans&quot; /&gt;&lt;/p&gt;

&lt;!-- Q1. &lt;b&gt;What is the domain of the function $$ \ln\sin x$$?&lt;/b&gt;
- The union of all intervals of the form $$\big( n\pi, (n+1)\pi \big)$$ for $$n$$ an odd integer.
- The union of all intervals of the form $$\big[ n\pi, (n+1)\pi \big]$$ for $$n$$ an odd integer.
- The union of all intervals of the form $$\big( n\pi, (n+1)\pi \big)$$ for $$n$$ an even integer.
- The union of all intervals of the form $$\big[ n\pi, (n+1)\pi \big]$$ for $$n$$ an even integer. --&gt;

&lt;!-- Q2. Let $$f(x) = \frac{1}{x+2}$$​. Determine $$ f \circ f $$.
* $$(f \circ f)(x) = \frac{2}{x+2}$$
* $$(f \circ f)(x) = \frac{1}{(x+2)^2}$$
* $$(f \circ f)(x) = \frac{x+2}{2x+5}$$
* $$(f \circ f)(x) = \frac{2x+5}{x+2}$$
* $$(f \circ f)(x) = x+2$$
* $$(f \circ f)(x) = 1$$  --&gt;

&lt;!-- ![Q1.](/assets/2021-11-12-calculus/challenge-hw-q4.png)&lt;br&gt; --&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>Physx 2: Calculus Homework, Part 1</title>
   <link href="https://nickczj.com/2021/11/12/calculus-homework-1"/>
   <updated>2021-11-12T00:00:00+00:00</updated>
   <id>https://nickczj.com/2021/11/12/calculus-homework-1</id>
   <content type="html">&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3.0.1/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Oops, I haven’t wrote this blog finished yet, come back for updates :)&lt;/p&gt;

&lt;!-- As a pre-requisite for studying Mechanics, I am starting a [calculus course on Coursera](https://www.coursera.org/learn/single-variable-calculus/home/welcome) by Robert Ghrist.

Today, I am doing the homework for functions [here](https://www.coursera.org/learn/single-variable-calculus/home/week/2), Practice Quiz on Functions.&lt;br&gt;

![Q1.](/assets/2021-11-12-calculus/challenge-hw-q1.png)
&lt;p class=&quot;linebreak&quot;&gt;▬▬ι══════════════ι▬▬&lt;/p&gt;

![Q2.](/assets/2021-11-12-calculus/challenge-hw-q2.png)
![Q2-ans](/assets/2021-11-12-calculus/q2-ans.jpg)
&lt;p class=&quot;linebreak&quot;&gt;▬▬ι══════════════ι▬▬&lt;/p&gt;

![Q3.](/assets/2021-11-12-calculus/challenge-hw-q3.png)
![Q3-ans](/assets/2021-11-12-calculus/q3-ans.jpg)
&lt;p class=&quot;linebreak&quot;&gt;▬▬ι══════════════ι▬▬&lt;/p&gt;

![Q4.](/assets/2021-11-12-calculus/challenge-hw-q4.png)
![Q4-ans](/assets/2021-11-12-calculus/q4-ans.jpg) --&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>Java ThreadLocals</title>
   <link href="https://nickczj.com/2021/10/10/java-thread-local"/>
   <updated>2021-10-10T00:00:00+00:00</updated>
   <id>https://nickczj.com/2021/10/10/java-thread-local</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/lang/ThreadLocal.html&quot;&gt;ThreadLocals&lt;/a&gt; in Java provide an easy way to store variables in a thread. It can be especially convenient when developing a web API — to access a variable anywhere in your code without passing them as arguments. It is used extensively in many java libraries, from logback’s &lt;a href=&quot;http://logback.qos.ch/manual/mdc.html&quot;&gt;MDC&lt;/a&gt; to Spring’s &lt;a href=&quot;https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/context/request/RequestContextHolder.html&quot;&gt;RequestContextHolder&lt;/a&gt;, making it easy to access any HTTP request parameters.&lt;/p&gt;

&lt;p&gt;However, in a multithreaded environment when using &lt;a href=&quot;https://www.geeksforgeeks.org/thread-pools-java/&quot;&gt;Thread Pools&lt;/a&gt;, it can especially be challening to set it up correctly. As you would have to make sure the ThreadLocal object set is inherited by child threads, we also have to ensure to clear the ThreadLocal object after execution of those threads. If a variable in the ThreadLocal is not cleared, another API request could reuse the same thread, taken from the threadpool and access the value from the previous request.&lt;/p&gt;

&lt;p&gt;While Spring’s SecurityContextHolder uses InheritableThreadLocal to solve this, there is no fully built in implementation for MDC. Although there are built in functions to make it easy for inheritence, you would have to copy the MDC instance to child threads through the executor via implementing ExecutorService or via &lt;a href=&quot;https://moelholm.com/blog/2017/07/24/spring-43-using-a-taskdecorator-to-copy-mdc-data-to-async-threads&quot;&gt;other methods&lt;/a&gt; that adds this function to your executor.&lt;/p&gt;

&lt;p&gt;In the end, if you decide to use ThreadLocals with Thread Pools, &lt;a href=&quot;https://stackoverflow.com/a/13870612/6260894&quot;&gt;extreme care&lt;/a&gt; is demanded to avoid unintented side effects.&lt;/p&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>An update - On web hosting</title>
   <link href="https://nickczj.com/2021/07/21/hosting"/>
   <updated>2021-07-21T00:00:00+00:00</updated>
   <id>https://nickczj.com/2021/07/21/hosting</id>
   <content type="html">&lt;p&gt;If you’ve read my first post, I mentioned that this site was hosted with github pages. But that has now been migrated to &lt;a href=&quot;https://www.netlify.com&quot;&gt;netlify&lt;/a&gt;! When I was writing my previous post, I realised that the post tags weren’t working - the clickable link beside the date at the bottom. I spent a few hours debugging a myraid of what I thought could have been the cause, which ultimately ended up being a compatiability issue with github pages.&lt;/p&gt;

&lt;p&gt;What this website is, is a static site generated with &lt;a href=&quot;https://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt;. The tagging system is a ruby plugin for Jekyll, &lt;a href=&quot;https://github.com/jekyll/jekyll-seo-tag&quot;&gt;jekyll-seo-tag&lt;/a&gt;. Naturally, I went through my code and once I ruled out any issues there, googled for all the permutations of the tools that were being used, searching through github issues with the plugin, googling compatiability issues with github pages, and the plugin gem (yes, ruby libraries are called &lt;a href=&quot;https://guides.rubygems.org/what-is-a-gem/&quot;&gt;gems&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Ultimately, I almost gave up. But with a little more persistence, I found the cause of the bug - github pages &lt;a href=&quot;https://github.com/ronv/sidey/issues/4&quot;&gt;do not support&lt;/a&gt; ruby plugins.&lt;/p&gt;

&lt;p&gt;Naturally, I first cursed out loud, then looked at seeing if this could be hosted on netlify (what the author in the issue suggested). And my oh my, it was perfectly seamless. Just clicking a few buttons, as I already had github integration with my netlify account, it was deployed in minutes, with the tagging working!&lt;/p&gt;

&lt;p&gt;However, I didn’t think using a custom domain was gonna be easy, so I left it for the night. When I tried it out today, it was amazingly easy and smooth to configure. Easier than github pages! No wonder netlify is so popular.
All I had to do was to setup my DNS settings with my hosting provider - &lt;a href=&quot;https://www.namecheap.com/support/knowledgebase/article.aspx/579/2237/which-record-type-option-should-i-choose-for-the-information-im-about-to-enter/&quot;&gt;CNAME record&lt;/a&gt; to point to my netlify app url &amp;amp; A record to point to netlify’s servers. 
After that, I had to only click a button to generate a SSL cert to enable HTTPS, and I was done :)&lt;/p&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>Physx 1: Project Euler, Problem 1</title>
   <link href="https://nickczj.com/2021/07/20/euler1"/>
   <updated>2021-07-20T00:00:00+00:00</updated>
   <id>https://nickczj.com/2021/07/20/euler1</id>
   <content type="html">&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=es6&quot;&gt;&lt;/script&gt;

&lt;script id=&quot;MathJax-script&quot; async=&quot;&quot; src=&quot;https://cdn.jsdelivr.net/npm/mathjax@3.0.1/es5/tex-mml-chtml.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;Hello! And welcome to the first in my series of notes on math &amp;amp; physics. Here, I pen down any interesting problem I’m currently looking at, and try to break it down into the basics.&lt;/p&gt;

&lt;p&gt;Today, we are looking at Project Euler’s &lt;a href=&quot;https://projecteuler.net/problem=1&quot;&gt;first&lt;/a&gt; of many interesting math problems:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you want to try it out yourself, then pause here as I dive straight into the solution.&lt;/p&gt;

&lt;p&gt;From a programming perspective, you would think it’s an easy solution and solve it in O(n) time. But it can be solved in O(1).&lt;/p&gt;

&lt;p&gt;The problem first needs to be split into the individial numbers, 3 &amp;amp; 5. Now, what is the formula for solving this?
The answer is the summation of the multiples of 3 &amp;amp; 5, until 1000. i.e.&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[ \sum_{i=1}^{333} 3i + \sum_{i=1}^{199} 5i \]&lt;/p&gt;

&lt;p&gt;where summation is the sum of a series of numbers of a pre-defined limit, in this case, i is the starting point and n is the limit.&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[ \sum_{i=1}^{n} x_i = x_1 + x_2 + ... + x_n \]&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[ \sum_{i=1}^{4} 3i = (3\times{1}) + (3\times{2}) + (3\times{3}) + (3\times{4}) \]&lt;/p&gt;

&lt;p&gt;Here, you may be wondering, why 333 &amp;amp; 199? We have to divide 1000 over 3 &amp;amp; 5 respectively to get the number of multiples of the 3 &amp;amp; 5 until 1000. However, since the question asks for multiples less than 1000, we cannot use exactly 1000, but the next closest integer, 999. If you spot this, congratulations! The 1000/5 would have felt off somehow.&lt;/p&gt;

&lt;p&gt;The other part to this problem is, how to you actually calculate summation? It may not be inherently obvious, but there is a formula to it. Looking at an example, there is a pattern somewhere that can be extracted.&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[1 + 2 + 3 + 4 + 5 + 6\]&lt;/p&gt;

&lt;p&gt;You’d first notice that there is a symmetry to the numbers - you can add it up like so:&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[(1 + 6) + (2 + 5) + (3 + 4) = 7 + 7 + 7 = 7 * 3 \]&lt;/p&gt;

&lt;p&gt;Now, we must be getting close to cracking it! But how to you generify this?
From the result, you can see that 7 is n + 1, and 3 would be n / 2 because you are basically dividing the sequence into 2 parts.
And so we have a formula:&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[ \frac{n}{2}(n + 1) \]&lt;/p&gt;

&lt;p&gt;But it doesn’t feel right. What if there is an even numbered sequence? e.g. 1 + 2 + 3 + 4 + 5 + 6 + 7
Somehow, this formula still holds up.&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[ \frac{7}{2}(7 + 1) = 28 \text{ - this is correct}\]&lt;/p&gt;

&lt;p&gt;Why does this work? Because if we had a single middle number or 2 middle numbers, we only care about the mean. Since the 2 numbers would be summed and divided by 2, having the single number doesn’t make a difference.&lt;/p&gt;

&lt;p&gt;Now finally, we have a solution.&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;\[ \sum_{i=1}^{333} 3i + \sum_{i=1}^{199} 5i = 3\times\frac{333}{2}(333 + 1) + 5\times\frac{199}{2}(199 + 1) \]&lt;/p&gt;

&lt;p&gt;Unfortunately, life is not perfect and this is still not yet complete. Since we will have the same multiples of 3 &amp;amp; 5, there will be duplicates. But the good thing is the fix is easy! We just have to remove all the common multiples. But how? If it were a different pair of numbers that were divisible by each other, it would have been a lot harder, but in our case, all the common multiples are just multiples of 3 * 5, i.e. we can just subtract this sum with the summation of 15.&lt;/p&gt;

&lt;p&gt;And hence, we have our final solution here:&lt;/p&gt;
&lt;p class=&quot;equation&quot;&gt;
\begin{gather*}
\sum_{i=1}^{333} 3i + \sum_{i=1}^{199} 5i - \sum_{i=1}^{66} 15i\\
= 3\times\frac{333}{2}(333 + 1) + 5\times\frac{199}{2}(199 + 1) - 15\times\frac{66}{2}(66 + 1)\\
= 233168
\end{gather*}
&lt;/p&gt;

&lt;hr /&gt;
</content>
 </entry>
 
 <entry>
   <title>Welp</title>
   <link href="https://nickczj.com/2021/04/19/welp"/>
   <updated>2021-04-19T00:00:00+00:00</updated>
   <id>https://nickczj.com/2021/04/19/welp</id>
   <content type="html">&lt;p&gt;So I finally decided to start my website again after a two year hiatus. I originally started this &lt;a href=&quot;https://github.com/nickczj/nickczj-web1&quot;&gt;website&lt;/a&gt; in 2017 with Python + &lt;a href=&quot;https://flask.palletsprojects.com/en/1.1.x/&quot;&gt;Flask&lt;/a&gt;. It was my gateway to web development - writing code with a web framework I barely understood, following guides to host my app on a server with my own domain. It was all very overwhelming, yet exciting.&lt;/p&gt;

&lt;p&gt;Eventually it died because I couldn’t fix an issue with my SSL certificate. I got busy and lazy, but gave up mostly because I had no clue how to fix it. Looking back, I’m actually quite astonished at how little I understood my own code back then. Using tools you don’t understand is dangerous, but nowadays there is a balance between understanding and getting things done.&lt;/p&gt;

&lt;p&gt;I originally wanted to develop this website with Vue + Go/Java but I’ve decided otherwise because I realised I was more interested in the tech than the product - I didn’t even have any design in mind. Eventually I decided, I mostly wanted a personal online presence. Hence, this&lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; is just a static web page built with Jekyll, hosted on github pages.&lt;/p&gt;

&lt;p&gt;I still want to play around with Vue + Go/Java, but that’s for another day :)&lt;/p&gt;

&lt;hr /&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://github.com/nickczj/nickczj.github.io&quot;&gt;https://github.com/nickczj/nickczj.github.io&lt;/a&gt; &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</content>
 </entry>
 

</feed>
