Convert unix time to datetime in redshift

select (timestamp ‘epoch’ + unix_time_col * interval ‘1 second’)::datetime

https://stackoverflow.com/questions/39815425/how-to-convert-epoch-to-datetime-redshift

Daylight saving time

In the U.S., daylight saving time starts on the second Sunday in March and ends on the first Sunday in November, with the time changes taking place at 2:00 a.m. local time.

https://en.wikipedia.org/wiki/Daylight_saving_time_in_the_United_States

API Gateway and Lambda limits

For response body payload size limit, API Gateway is 10 MB, Lambda is 6MB.

Ref:
https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
https://docs.aws.amazon.com/lambda/latest/dg/limits.html

Solving Sudoku with a single sql query?

Unbelievable…

sudoku-problem

WITH solve_sudoku(sud_str,ind) AS
 (SELECT sud, INSTR(sud, ' ')
    FROM (SELECT '4 29 58 339     64  1   9     5 1    4 6 2 3    4 8     7   5  51     279 47 36 8' sud
            FROM dual)
  UNION ALL
  SELECT SUBSTR(sud_str, 1, ind - 1) || z || SUBSTR(sud_str, ind + 1),
         INSTR(sud_str, ' ', ind + 1)
    FROM solve_sudoku, (SELECT TO_CHAR(ROWNUM) z FROM dual CONNECT BY ROWNUM  0
     AND NOT EXISTS
   (SELECT NULL
            FROM (SELECT ROWNUM lp FROM dual CONNECT BY ROWNUM <= 9)
           WHERE z = SUBSTR(sud_str, TRUNC((ind - 1) / 9) * 9 + lp, 1)
              OR z = SUBSTR(sud_str, MOD(ind - 1, 9) - 8 + lp * 9, 1)
              OR z = SUBSTR(sud_str,
                            MOD(TRUNC((ind - 1) / 3), 3) * 3 +
                            TRUNC((ind - 1) / 27) * 27 + lp +
                            TRUNC((lp - 1) / 3) * 6,
                            1)))
SELECT sud_str FROM solve_sudoku WHERE ind = 0;

We will get the answer:

462915873395287164781364952279531486148692735653478291837126549516849327924753618

Ref:
http://oraclemine.com/sql-query-solved-sudoku-seconds/
https://technology.amis.nl/2009/10/13/oracle-rdbms-11gr2-solving-a-sudoku-using-recursive-subquery-factoring/

有空到五個地方走走

有空到五個地方走走,你會明白很多事情

1、書店:到裡面數一數自己沒讀過的書,你就會明白,自己知道的那點知識,只是皮毛。

2、奢侈品店:到裡面看看商品的標價,你會明白自己是個窮人,拼搏才是你的出路。

3、春耕的大地:頂著烈日,陪著農民朋友,從地的這邊走到那邊,走幾趟,你就會明白,自己的工作是多麼的優越。

4、醫院:這裡匯聚了人間痛苦,到裡面走走,你會明白健康有多麼的重要。

5、殯儀館:到了那裡你會明白,計較那麼多事有什麼用,活著比什麼都重要。

Go vs Python by examples

http://govspy.peterbe.com/

DRY is not always practical

This article says it well. I am glad I am not alone.
https://programmingisterrible.com/post/176657481103/repeat-yourself-do-more-than-one-thing-and

I have applied the DRY principle numerous times. Sometimes I found myself messing with the abstract class or common function again and again, introducing more and more switches to deal with various combinations of params. In those moments, I secretly hoped that there was no abstraction at all. May it be repeated code, coz at least when I tweak one thing I know that I am only tweaking one thing but not the rest of the dependent code. DRY is a good principle for sure, but I hope that we don’t just blindly follow it to write “good” code.