Skip to content

Instantly share code, notes, and snippets.

@pertsevds
pertsevds / PluralizeTask.cs
Last active April 17, 2021 15:39
Pluralize rubles C#
using System;
namespace Pluralize
{
public static class PluralizeTask
{
public static string PluralizeRubles(int count)
{
if (count % 10 == 1 && count % 100 != 11)
return "рубль";
@pertsevds
pertsevds / RectanglesTask.cs
Last active April 17, 2021 15:38
Rectangles intersection C#
using System;
namespace Rectangles
{
public static class RectanglesTask
{
// Пересекаются ли два прямоугольника (пересечение только по границе также считается пересечением)
public static bool AreIntersected(Rectangle r1, Rectangle r2)
{
return !(r1.Left > r2.Right || r2.Left > r1.Right || r1.Bottom < r2.Top || r2.Bottom < r1.Top);
@pertsevds
pertsevds / BilliardsTask.cs
Created April 17, 2021 15:42
Calculate the angle of the ball bouncing from the wall
namespace Billiards
{
public static class BilliardsTask
{
/// <summary>
///
/// </summary>
/// <param name="directionRadians">Угол направления движения шара</param>
/// <param name="wallInclinationRadians">Угол</param>
/// <returns></returns>
@pertsevds
pertsevds / atom.py
Created July 13, 2021 19:50 — forked from Morgul/atom.py
Atoms/Symbols in Python
class atom(object):
"""An implementation of the atom concept, inspired by Erlang.
Modified from here: http://www.me.net.nz/blog/atoms-slash-symbols-in-python/
"""
def __init__(self, a):
self._a = intern(a)
def __eq__(self, other):
@pertsevds
pertsevds / gist:723c27f42d2224db0ceaa69aa48d009b
Last active December 13, 2024 06:09
Fail2ban Cockpit filter and jail
Filter "/etc/fail2ban/filter.d/cockpit.conf":
# Fail2Ban filter for Cockpit
#
[Definition]
failregex = pam_unix\(cockpit:auth\): authentication failure;.*rhost=<HOST>
datepattern = ^%%b %%d %%H:%%M:%%S
# DEV Notes:
# Author: Dmitriy Pertsev
Jail "/etc/fail2ban/jail.local":
@pertsevds
pertsevds / tunnel.py
Created September 29, 2022 17:57 — forked from carlohamalainen/tunnel.py
check ssh tunnel from Python
"""
From the man page for ssh:
-f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask
for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way
to start X11 programs at a remote site is with something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to “yes”, then a client started with -f will wait
for all remote port forwards to be successfully established before placing itself in the background.
@pertsevds
pertsevds / git-use-main.md
Created October 28, 2022 15:03 — forked from clarkphp/git-use-main.md
Use default branch name of "main" instead of "master" in Git repositories

Set default branch name for new repositories to "main"

git version 2.28+

$ git config --global init.defaultBranch main

git version 2.27 or less

@pertsevds
pertsevds / README.md
Last active March 2, 2023 17:40 — forked from rubencaro/README.md
Python installation guide

Python installation guide

Install asdf and its python plugin, then install Python

asdf lives in https://github.com/asdf-vm/asdf

Follow its installation instructions, which at the moment of writing were:

cd
@pertsevds
pertsevds / upgrade.sh
Last active March 19, 2023 16:33
Upgrade Pnetlab from_any_to_5.3.11 with reboot without confirmation
#!/bin/bash
# Script designed to upgrade PNETLab from almost any version to NEW_PNETLAB_VERSION version
# Requirement: Not having PNETLab 6.x installed for being able to upgrade to NEW_PNETLAB_VERSION
# This script avoids to make this upgrade process twice
# CONSTANTS
NEW_PNETLAB_VERSION=5.3.11
GREEN='\033[32m'
NO_COLOR='\033[0m'
@pertsevds
pertsevds / compare_phoenix_versions.exs
Created May 29, 2023 09:49 — forked from aiwaiwa/compare_phoenix_versions.exs
Compare Phoenix Versions with extra custom steps like mix phx.gen.live Accounts User users name:string
#
# Usage:
# elixir <this_script_name.exs> 1.7.2
#
# The script grabs a Phoenix version and places it
# under `phoenix/<version>` subfolder. It attempts to call
# a diff GUI, if there's another version found in `phoenix`.
# It picks the closest older version, if more than one found.
#
# Feel free to modify PhoenixCompareConfig