Skip to content

Instantly share code, notes, and snippets.

View vyspiansky's full-sized avatar

Ihor Vyspiansky vyspiansky

View GitHub Profile
@vyspiansky
vyspiansky / javascript-html-entities.md
Created January 26, 2023 21:02
HTML entities in JavaScript
// Simplified implementation
String(str).replace(/&/g, '&')
  .replace(/</g, '&lt;')
  .replace(/>/g, '&gt;')
  .replace(/"/g, '&quot;');
@vyspiansky
vyspiansky / macos-terminal-specific-php-version-first.md
Created January 26, 2023 20:54
Use a specific PHP version first in macOS Terminal
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
@vyspiansky
vyspiansky / winston-disable-logging.md
Created January 26, 2023 20:38
Disable Winston's logging

Disable Winston's logging when running unit tests

import { logger } from './logger'; 
logger.silent = true;
@vyspiansky
vyspiansky / knex-js-multiple-order-by-columns.md
Last active January 11, 2023 15:13
Knex.js multiple orderBy() columns
knex
  .select()
  .table('products')
  .orderBy('name', 'desc')
  .orderBy('id', 'asc')
@vyspiansky
vyspiansky / postgresql-connection-string.md
Created January 11, 2023 15:06
PostgreSQL connection string / URL format

PostgreSQL connection string / URL format

postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
@vyspiansky
vyspiansky / react-tips-and-tricks.md
Created January 11, 2023 08:46
React Tips and Tricks (draft)

React: assign a key to its children

React.Children.toArray(/*...*/)
@vyspiansky
vyspiansky / check-preflight-request.sh
Created November 14, 2022 09:27
Bash: check preflight request
curl -v -i -X OPTIONS -H "Origin: <WEBSIDE_URL>" \
-H 'Access-Control-Request-Method: POST' \
-H 'Access-Control-Request-Headers: Accept, Content-Type, Origin, Referer, User-Agent, X-YOUR-CUSTOM-HEADER' \
"<XHR_URL>"
@vyspiansky
vyspiansky / postgres-generate-test-data.sql
Last active September 28, 2022 10:15
PostgreSQL: Generate test data
do $$
begin
for i in 1000001..11000000 loop
INSERT INTO table_name(
field_id
field_2,
field_3
) values(
i,
'<field 2 value>',
@vyspiansky
vyspiansky / ssl-postgres-connect-using-sequelize.md
Last active January 31, 2023 21:19
How to connect to Postgres via SSL using Sequelize
const sequelize = new Sequelize(DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, {
  host: DATABASE_HOST,
  dialect: 'postgres',
  port: DATABASE_PORT,
  ssl: {
    ca: fs.readFileSync(DATABASE_TLS_CERT).toString(),
    rejectUnauthorized: true,
    servername: DATABASE_HOST
 }
@vyspiansky
vyspiansky / dummy-text-file.txt
Last active August 23, 2022 08:22
Dummy text files (Lorem Ipsum)
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discov