Git Commands

These are the Git commands that I used a lot in my job. Stash all the files including untracked new files. git stash save -u "stash_name" Undo merge or rebase. git merge --abort git rebase --abort Remove all the files which are not in git (untracked new files). git clean -xfd Discard all the local changes. git checkout -f Reset to previous steps like undo the commit. git reflog git reset --hard <hash-or-ref> Undo pushed commits.

Read More

Running SQL Server on Mac using Docker

It is time to practice T-SQL but how can I do that with my Macbook Pro? Thanks to Docker, it is never mission impossible. References Running SQL Server 2019 CTP in a Docker container – DBA From The Cold Running SQL Server with Docker on the Mac – SQL passion Steps Follow the post to install docker and create a container with SQL Server 2019 CTP. Install Azure Data Studio and read the post Download Wide World Importers sample database (WideWorldImporters-Full.

Read More

Fourier Series and Fourier Transform

References http://www.math.psu.edu/wysocki/M412/Notes412_8.pdf https://zhuanlan.zhihu.com/p/19763358 https://www.math.psu.edu/tseng/class/Math251/Notes-PDE%20pt2.pdf http://www.oulu.fi/sites/default/files/content/files/series.pdf http://www.engr.uconn.edu/~lanbo/G377FFTYC.pdf Fourier Series Theorem (references: Second Order Linear Partial Differential Equations, 复数形式傅立叶变换的物理意义,相位究竟指的是什么?) \(\text{Suppose } f(x) \text{ is a periodic function with period } T \text{ and is an integrable function on } [0, T]. \\ \text{Then, the Fourier Series of } f(x) \text{ can be written as }\) \[ \begin{align} f(x) & = \frac{c_0}{2} + \sum_{n=1}^{\infty} c_ncos(n \cdot \frac{2\pi}{T} \cdot x + \varphi_n) \\ &= \frac{c_0}{2} + \sum_{n=1}^{\infty} c_ncos(\varphi _n)cos(n \cdot \frac{2\pi}{T} \cdot x)+ (-c_n)sin(\varphi _n)sin(n \cdot \frac{2\pi}{T} \cdot x) \\ &\text{( let } a_0 = c_0, \;a_n = c_ncos(\varphi _n) \text{ and } b_n = (-c_n)sin(\varphi _n) \;) \\ &= \frac{a_0}{2} + \sum_{n=1}^{\infty} a_ncos(n \cdot \frac{2\pi}{T} \cdot x)+ b_nsin(n \cdot \frac{2\pi}{T} \cdot x) \\ \\ \text{where } c_n &= \sqrt{a_n^2 + b_n^2} = \sqrt{c_n^2(cos^2(\varphi _n) + sin^2(\varphi _n))} = \sqrt{c_n^2} \;\; (Amplitude)\\ \varphi_n &= tan^{-1}(-\frac{b_n}{a_n}) \;\; (Phase)\\ a_0 &= \frac{1}{T}\int_{0}^{T}f(x)dx \\ a_n &= \frac{1}{T}\int_{0}^{T}f(x) \cdot cos(n \cdot \frac{2\pi}{T} \cdot x)dx \\ b_n &= \frac{1}{T}\int_{0}^{T}f(x) \cdot sin(n \cdot \frac{2\pi}{T} \cdot x)dx \end{align} \]

Read More

Parallel Computing in R

In my work, I usually deal with dataset of products from different customers across different market places. Basically, each product has its own time series dataset. The size of each dataset is not big but we have millions of them. Before finding any convincing reasons to combine dataset from different products, now we just treat them all as independent dataset. And, since they are all independent, it is definitely a good idea to use parallel computing to push the limit of our machine and to make code executed efficiently.

Read More

Connect SQL Server Database to R

When I am working on my personal projects, all the data I have can be easily saved as .csv or .txt files. Things are not complicated. However, when things are in scale, it is hard to not to talk about database. In my company, all the data are stored in SQL Server database. So, it is important for me to know how to connect R with SQL Server. And, also good to know how to interact with database in R by passing variables in R environment to database and then return the desired dataset.

Read More

Learning Microsoft SQL Server

This page is about the SQL Server commands. All of the contents are based on the code in w3schools - SQL with the sample database, Northwind. To make myself easier to look up the commands I want in the future, I picked out the ones I have been used a lot in my work and add some notes on it. I also borrowed some materials from the course LinkdedIn Learning - Microsoft SQL Server 2016: Query Data.

Read More