Skip to content

Instantly share code, notes, and snippets.

View aalexren's full-sized avatar
🏴‍☠️
Savvy?

Artyom Chernitsa aalexren

🏴‍☠️
Savvy?
View GitHub Profile
@aalexren
aalexren / README.md
Created May 29, 2023 09:33
Deal with PDF on macOS using ghostscript

To use it, install it using homebrew:
brew install ghostscript

Then use one of theese commands for your needs:

  1. Compress PDF:
    gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/screen -dCompatibilityLevel=1.4 -sOutputFile=output.pdf input.pdf
  2. Merge PDF:
    gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf source1.pdf source2.pdf source3.pdf
@aalexren
aalexren / solutions.py
Created May 3, 2023 11:09
Simple tasks on python algorithms to warm up. Some classics.
from collections import Counter
from queue import Queue
def custom_sort(nums: list[int]) -> list[int]:
"""Task 1
Sort the odd numbers in ascending order,
and leave the even ones in their places.
"""
@aalexren
aalexren / main.cpp
Created April 27, 2023 11:46
Gaussian-Seidel method to solve a system of linear equations. [Innopolis University] Linear Algebra 2023
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <stdlib.h>
using namespace std;
typedef long long ll;
@aalexren
aalexren / vmstat-macos.md
Created April 1, 2023 12:54
Show utilization of RAM memory on macOS using vm_stat and top

To inspect RAM memory on macOS there are alternatives to vmstat or free on Linux: vm_stat and top (actually it's exists on both systems).

To check free RAM on macOS:
$> top -l 1 -s 0 | grep PhysMem
It will show you occupied physical memory and available once.

Either you can run this:
$> vm_stat | perl -ne '/page size of (\d+)/ and $size=$1; /Pages\s+([^:]+)[^\d]+(\d+)/ and printf("%-16s % 16.2f Mi\n", "$1:", $2 * $size / 1048576);'
It will show information in pages by default, but perl script provide output in human readable format.

@aalexren
aalexren / psql-error-fix.md
Created March 31, 2023 18:40 — forked from AtulKsol/psql-error-fix.md
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from

@aalexren
aalexren / LC_COLORS.md
Created October 3, 2022 09:49 — forked from thomd/LC_COLORS.md
LSCOLORS & LS_COLORS

alternatively use: http://geoff.greer.fm/lscolors/

LSCOLORS

The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.

The color designators are as follows:

a black

@aalexren
aalexren / -py_elementary-basics.ipynb
Last active September 18, 2022 18:46
[py_elementary]basics.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.