How to start and stop PostgreSQL server?

1. On MacOS:

If you installed PostgreSQL via Homebrew:

  • To start manually: pg_ctl -D /usr/local/var/postgres start
  • To stop manually: pg_ctl -D /usr/local/var/postgres stop
  • To start PostgreSQL server now and relaunch at login:
    brew services start postgresql
  • And stop PostgreSQL: brew services stop postgresql

2. On Windows:

First, you need to find the PostgreSQL database directory, it can be something like C:\Program Files\PostgreSQL\10.4\data. Then open Command Prompt and execute this command:

  • To start the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" start
  • To stop the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" stop
  • To restart the server: pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart

3. On Linux:

  • Start the PostgreSQL server: sudo service postgresql start
  • Stop the PostgreSQL server: sudo service postgresql stop

Link reference:

Comparison Time Attacks

Using == to compare sensitive hashes leaves you vulnerable to timing attacks. This is because == returns false as soon as it finds two characters that don’t match. An attacker can make many requests with different values and compare times to figure out how many characters were correct (the shorter the response, the fewer correct characters).

Solution: use a constant-time comparison algorithm.

  • Ruby: Rack::Utils.secure_compare or ActiveSupport::SecurityUtils.secure_compare
  • NodeJS: crypto.timingSafeEqual


Memory layout of OS processes


  • Text: The executable code (source code compiled to binary)
  • Data: initialized or uninitialized data
  • Heap: Dynamic allocated memory during program run time
  • Stack: Temporary data storage when invoking functions (local variables, function parameters, return addresses)

The sizes of text and data are fixed.

However, heap and stack can grow and shrink during run time. Each time a function is called, a record contains local variables, function parameters, return addresses is pushed to the stack. When the function finished, that record will be popped from the stack.

Similarly, the heap will grow as memory is dynamically allocated, and shrink when the memory is returned to the system. Notice that stack and heap size can grow toward each other but the OS has to make sure that they won’t overlap one another.


COPY results will be faster than INSERT due to they don’t have to do round trip, PostgreSQL doesn’t have to do planning and executing multiple INSERT statements.

COPY table_name [ ( column_name [, ...] ) ]
    FROM { 'filename' | STDIN }
    [ [ WITH ] ( option [, ...] ) ]

COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
    TO { 'filename' | STDOUT }
    [ [ WITH ] ( option [, ...] ) ]

where option can be one of:

    FORMAT format_name
    OIDS [ boolean ]
    DELIMITER 'delimiter_character'
    NULL 'null_string'
    HEADER [ boolean ]
    QUOTE 'quote_character'
    ESCAPE 'escape_character'
    FORCE_QUOTE { ( column_name [, ...] ) | * }
    FORCE_NOT_NULL ( column_name [, ...] )
    ENCODING 'encoding_name'

Smoother & sharper shadows in CSS

Default box-shadow

.box {
 box-shadow: 0 3px 3px rgba(0,0,0,0.2);

Create smoother box-shadows by layering multiple

.shadow-5 {
 box-shadow:  0 1px 1px rgba(0,0,0,0.12), 
              0 2px 2px rgba(0,0,0,0.12), 
              0 4px 4px rgba(0,0,0,0.12), 
              0 8px 8px rgba(0,0,0,0.12),
              0 16px 16px rgba(0,0,0,0.12);

Shadows with decreasing alpha

.blog-shadow-sharp {
 box-shadow: 0 1px 1px rgba(0,0,0,0.25), 
             0 2px 2px rgba(0,0,0,0.20), 
             0 4px 4px rgba(0,0,0,0.15), 
             0 8px 8px rgba(0,0,0,0.10),
             0 16px 16px rgba(0,0,0,0.05);


Elixir ETS table

ETS tables are in-memory storage that stores tuples as rows.

ETS is a common way of sharing states between processes/GenServers. But keep in mind that ETS is a datastore, not a database. So the support for transactions is very limited.

Working with ETS tables is done via erlang :ets module

Reference: link