Skip to content

Instantly share code, notes, and snippets.

View morivitalii's full-sized avatar
👌

Mori Vitalii morivitalii

👌
View GitHub Profile
@morivitalii
morivitalii / gist:b0f66ce35791d2c4c8e5ac646984cd32
Created November 23, 2023 15:18 — forked from ericmathison/gist:1d53b3f53fe68b0c351046df3422a4e0
Deploy instructions for Rails using Puma, Nginx, and Ubuntu 18.04.

Deploy instructions for Rails using Puma, Nginx, and Ubuntu 18.04.

Sign up at www.atlantic.net (Select the Ubuntu 18.04 LTS operating system option). I was grandfathered in on Atlantic.net's $1 a month virtual private server (VPS) hosting. Unlike Heroku, you will have full control over the server. At some point in your application's lifetime this may become important to you for making customizations Heroku isn't capable of. Unless future limitations aren't a concern AND you don't want to learn how to set up a virtual private server, I wouldn't suggest using Heroku. The setup process below would be very similar for any of the other big hosting options like Amazon's EC2, DigitalOcean, etc.

Confirmation email will have log in instructions with IP, password and username.

Some of the commands below are run on the remote machine and others on your local development machine. I will prefix each command with one of the following:

remote-root#
remote$
@morivitalii
morivitalii / README.md
Created October 20, 2023 13:00 — forked from valyala/README.md
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@morivitalii
morivitalii / gist:325f6c1993ab8eeea9060c778d802397
Created September 23, 2023 18:19 — forked from dstagner/gist:193207fed46acf5b5bae
Ruby ISO8601 time in milliseconds

So you want to generate ISO8601 formatted timestamps in Ruby, but need resolution finer than a second?

First, make sure to require 'time' in order to get ISO8601 formatting. But that gets you this:

2.1.0 :001 > require 'time'
 => true 
2.1.0 :002 > Time.now.utc.iso8601
 => "2015-11-12T04:46:43Z" 
@morivitalii
morivitalii / gist:58465810ba1f751becc102ccffbbedcf
Created August 14, 2022 23:54 — forked from bsnape/gist:edff869d5b7dc0b0d7c2
Rubymine find & replace string hash rockets with new syntax
find:
\'(\w+)\'\s*=>
replace:
$1:
replace symbol hash rockets with new syntax
find: