Skip to content

Instantly share code, notes, and snippets.

View bityob's full-sized avatar

Yonatan Bitton bityob

View GitHub Profile
@bityob
bityob / DictWithMaxKeys.py
Created December 25, 2017 19:09
Dictionary with maximun length, keep last N keys on dictionary, using deque object
from collections import deque
class DictWithMaxKeys:
def __init__(self, maxlen, init=None):
self.maxlen = maxlen
self._deque = deque()
self._dict = {}
if init is not None:
self._dict.update(init)
@bityob
bityob / DictWithMaxKeys.cs
Last active December 25, 2017 20:25
Dictionary with maximun length, keep last N keys on dictionary, using Queue object (C#)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace DictMaxLength
{
@bityob
bityob / WSL-ssh-server.md
Last active July 18, 2024 15:41 — 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
@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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bityob
bityob / Enable-OpenSSH-Client-Server-On-Windows.md
Last active March 11, 2025 22:23
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 / 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 / $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 / 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 / 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 / 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: