View timezones.sql
SHOW TIMEZONE;
CREATE TEMP TABLE tz_test_table (t timestamp with time zone); -- if change to "without time zone", all timezones will be ignored and every single row will have the exact same value (i.e. "2018-03-03 10:00:00").
INSERT INTO tz_test_table (t) VALUES ('2018-03-03 10:00:00'); -- will read datetime based on whatever session timezone is and store as UTC
INSERT INTO tz_test_table (t) VALUES ('2018-03-03 10:00:00 America/Los_Angeles'); -- read as LA time and store as UTC
INSERT INTO tz_test_table (t) VALUES ('2018-03-03 10:00:00 UTC'); -- read as UTC time and store as UTC
SET SESSION timezone TO 'America/New_York';
INSERT INTO tz_test_table (t) VALUES ('2018-03-03 10:00:00'); -- New York
View DeepReadonly.ts
type DeepReadonly<T> =
T extends [infer A] ? DeepReadonlyObject<[A]> :
T extends [infer A, infer B] ? DeepReadonlyObject<[A, B]> :
T extends [infer A, infer B, infer C] ? DeepReadonlyObject<[A, B, C]> :
T extends [infer A, infer B, infer C, infer D] ? DeepReadonlyObject<[A, B, C, D]> :
T extends [infer A, infer B, infer C, infer D, infer E] ? DeepReadonlyObject<[A, B, C, D, E]> :
T extends [infer A, infer B, infer C, infer D, infer E, infer F] ? DeepReadonlyObject<[A, B, C, D, E, F]> :
T extends [infer A, infer B, infer C, infer D, infer E, infer F, infer G] ? DeepReadonlyObject<[A, B, C, D, E, F, G]> :
T extends (infer A)[] ? DeepReadonlyArray<A> :
T extends Function ? T : // can change to never to forbid functions
View file.ts
// TL;DR - string enums are the easiest and most readable way to go (if you need numbers, use number sum type)
// number enum
enum ShapeNumberEnum {
Circle = 1,
Square = 2,
}
const a: ShapeNumberEnum = ShapeNumberEnum.Circle
const b: ShapeNumberEnum = 1 // passes type check = bad (any number will pass type checking)
View redux-analysis.md

Redux analysis

This was written in the context of using TypeScript since that's my preference.

Why Redux makes sense

  • store.subscribe makes sense in react world with virtual DOM and smart diffing.

Why I like Redux

  • All components are mapped to one state tree.
  • The concept of container/presentation components and immutability are useful.
View scala-js-tutorial.md

How to create a node library with scala.js

Assumes you have scala, sbt and IntelliJ installed with scala plugin

  1. Create new Scala > SBT project. Name it tutorial-lib.
  2. Add line to project/plugins.sbt:
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")
  1. Add lines to built.sbt:
View classes.ts
class A {
v1: string
v2: number
constructor() {
this.v1 = `Test ${this.v2}`
}
}
class B extends A {
View ONE.ts
import { TWO } from './constants'
export const ONE = TWO - 1 // i.e. this evaluates undefined - 1
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.country {
fill: #C0D9AF;
stroke: #fff;
stroke-width: 1px;
stroke-linejoin: round;
}
View generators.js
Array.prototype.toIterator = function*() {
for (var i = 0, l = this.length; i < l; i++) {
yield this[i]
}
}
Object.prototype.map = function*(lambda) {
for (var value of this) {
yield lambda(value)
}