Skip to content

Instantly share code, notes, and snippets.

View B1Z0N's full-sized avatar
🐢
contemplating

Mykola Fedurko B1Z0N

🐢
contemplating
View GitHub Profile
@B1Z0N
B1Z0N / telegram_reactor.py
Last active August 23, 2023 16:53
A piece of code that will allow you to spam with reactions on a new message in a chat. Requires telethon installed.
from telethon import TelegramClient, events, types
from telethon.tl.functions.messages import SendReactionRequest
from telethon.errors.rpcerrorlist import ReactionInvalidError
import random
# Config from https://my.telegram.org/auth
api_id = 123456 # your api id here
api_hash = 'aajwjwjwjwjwiwiwisdjsdjsddsk' # you api hash here
@B1Z0N
B1Z0N / All.cs
Last active August 23, 2022 12:24
using System.Runtime.CompilerServices;
using System;
public static class Program
{
public static Logger logger = new Logger { EnabledLevel = LogLevel.Error };
public static void Main()
{
@B1Z0N
B1Z0N / setup.md
Last active February 20, 2022 15:32
Postgres setup
  1. Install postgres.
  2. Setup password for postgres linux user: sudo passwd postgres
  3. Switch to this user: su - postgres
  4. Run psql -U postgres
  5. Create user with your name as in linux. Grant it some privileges. For all privileges:
CREATE USER {your_username} WITH ENCRYPTED PASSWORD '{your_password}';
ALTER USER {your_username} WITH SUPERUSER;
@B1Z0N
B1Z0N / EqualsAndGetHashCode.md
Last active December 12, 2021 13:02
Equals and GetHashCode in C#

Equals

If you need to define equality:

  1. Override object.Equals to define logical, human desirable equality in case of classes and in case of structs a lot more efficient equality.
    • For classes default Object.Equals compares references to memory(e.g. only the same object will be equal to itself, so it's not always as human would expect).
    • For structs default ValueType.Equals calls Equals on every field using reflection(which is very slow).
  2. Implement IEquatable to optimize for value types and just to declare intent in any case.
@B1Z0N
B1Z0N / Notify-Job.ps1
Created September 3, 2021 23:48
Powershell function(cmdlet) to set notification for job completion.
function Notify-Job {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[scriptblock]$Job,
[Parameter()]
[string]$Name,
[Parameter()]
[scriptblock]$Continuation
)
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class NoneDict(dict, metaclass=Singleton):
def __getitem__(self, key):
return NoneDict()
using System.Linq.Expressions;
using System;
public static class Program
{
public static void Main()
{
Console.WriteLine(Program.ConstantOne<double>.Value);
Console.WriteLine(Program.ConstantOne<int>.Value);
@B1Z0N
B1Z0N / BigDecimal.cs
Created July 23, 2020 22:40 — forked from nberardi/BigDecimal.cs
BigDecimal type in .NET
using System;
using System.Linq;
namespace System.Numerics
{
public struct BigDecimal : IConvertible, IFormattable, IComparable, IComparable<BigDecimal>, IEquatable<BigDecimal>
{
public static readonly BigDecimal MinusOne = new BigDecimal(BigInteger.MinusOne, 0);
public static readonly BigDecimal Zero = new BigDecimal(BigInteger.Zero, 0);
public static readonly BigDecimal One = new BigDecimal(BigInteger.One, 0);
@B1Z0N
B1Z0N / ls.cpp
Last active May 17, 2020 17:06
List directories using cpp(Linux only, waiting for c++20 to handle subtle moments)
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <filesystem>
#include <sstream>
#include <chrono>
#include <type_traits>
@B1Z0N
B1Z0N / gist:028d1667f4f576dac79b4453f07cd065
Created April 14, 2020 10:21 — forked from prathe/gist:2439752
Python Regular Expression: double-quoted string literals that allows for escaped double quotes
# Tricky REs with ^ and \
# Assign to regexp a regular expression for double-quoted string literals that
# allows for escaped double quotes.
# Hint: Escape " and \
# Hint: (?: (?: ) )
import re