Skip to content

Instantly share code, notes, and snippets.

View bityob's full-sized avatar

Yonatan Bitton bityob

View GitHub Profile
@bityob
bityob / README.md
Last active February 28, 2024 22:16
Postgres - Aggregate multiple rows to 1 row with removing duplicates, null, empty fields on text, array and 2D array types

What

We want to have 1 row by id, but not just aggregating all values with simple array_agg, but removing null and empty fields, removing duplicates, and doing it for array field and 2D array field too.

Table before agg logic

image

Table after agg logic

@bityob
bityob / torch-multi.ipynb
Created December 25, 2023 23:47
Run torch with multiprocessing on Jupyter Notebook (aka IPython, Jupyter Lab etc.)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bityob
bityob / async-smtp-test-server.py
Last active July 18, 2023 08:42
SMTP Debugging/QA/Testing Server, Simulate easily SMTP errors
from aiosmtpd.controller import Controller
import asyncio
class ExampleHandler:
async def handle_RCPT(self, server, session, envelope, address, rcpt_options):
print(f"handle_RCPT: {address}")
if address.endswith('@error.com'):
user_part = address.split("@")[0]
try:
@bityob
bityob / client.py
Last active November 12, 2022 19:49
TLS Client/Server with Client Certificate Autentication
import socket
import ssl
SERVER_PORT = 60000
HOST = "127.0.0.1"
tls_client_cert = "client.crt"
tls_client_key = "client-private-key.key"
tls_key_password = None
tls_ca_bundle = "ca_bundle.pem"
@bityob
bityob / get_longest_substring_of_two_chars.py
Created April 11, 2022 20:23
get_longest_substring_of_two_chars.py
def get_longest_substring_of_two_chars(string):
max_start = 0
max_end = 0
curr_start = 0
curr_second_char = 0
curr_end = 0
curr_chars = []
for index, ch in enumerate(string):
@bityob
bityob / $requests-latency-test-v2.26-vs-v.2.25.1.md
Last active July 29, 2021 12:25
Requests latency test v2.26 vs v.25.1

Run httpbin locally

docker pull kennethreitz/httpbin
docker run -d -p 8888:80 kennethreitz/httpbin

Clone this gist

git clone https://gist.github.com/02b1a823b478ad74a8440b86f95e13a6.git requests-latency-test
cd requests-latency-test
@bityob
bityob / Restart-Machine.ps1
Created July 11, 2019 09:53
Restart-Machine PS Script
$arguments=$args[0]
$command="Restart-Computer $arguments"
Write-Host "Command: '$command'"
iex $command
Write-Host "Done"
@bityob
bityob / Enable-OpenSSH-Client-Server-On-Windows.md
Last active April 10, 2024 18:50
Enable SSH Client/Server with OpenSSH on Windows

How to enable ssh on Windows?

Tested on Windows Version 10.0.17755.1

  • Run cmd as admin

  • Install OpenSSH.Client - dism /online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0

C:\WINDOWS\system32>dism /online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0
@bityob
bityob / Duplicate_dicts_in_list.ipynb
Last active October 14, 2021 07:10
Remove duplicates dicts from list (Python), #python #ipython. Source for solutions - https://stackoverflow.com/questions/9427163/remove-duplicate-dict-in-list-in-python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bityob
bityob / WSL-ssh-server.md
Last active April 23, 2024 21:08 — forked from dentechy/WSL-ssh-server.md
A step by step tutorial on how to automatically start ssh server when launching Windows Subsystem for Linux

How to automatically start ssh server when launching Windows Subsystem for Linux

Microsoft partnered with Canonical to create Bash on Ubuntu on Windows, running through a technology called the Windows Subsystem for Linux. Below are instructions on how to set up the ssh server to run automatically at boot.

  1. Uninstall and reinstall the ssh server using the following commands:
    1. sudo apt remove openssh-server
    2. sudo apt install openssh-server
  2. Edit the /etc/ssh/sshd_config file by running the command sudo vi /etc/ssh/sshd_config and do the following
    1. Change Port to 2222 (or any other port above 1000)
  3. Change UsePrivilegeSeparation to no