Skip to content

Instantly share code, notes, and snippets.

View rodoufu's full-sized avatar

Rodolfo P A rodoufu

View GitHub Profile
@rodoufu
rodoufu / udp_socket.py
Created February 4, 2021 17:39
Python UDP
import socket
import sys
def socket_client(host: str, port: int):
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as udp_client:
dest = (host, port)
print(f"Connected to: {host}:{port}")
msg = input()
while msg != '\x18':
@rodoufu
rodoufu / lib.rs
Last active February 5, 2021 20:41
Rust UDP and TCP
use chrono::{
Timelike,
Utc,
};
use std::{
io::{
self,
Read,
Error as IoError,
ErrorKind,
# https://leetcode.com/problems/find-median-from-data-stream/
# Work in progress
class MedianFinder:
def __init__(self):
"""
initialize your data structure here.
"""
self.number_count: Dict[int, int] = {}
self.size = 0
self.sorted_keys = None
namespace multi {
using System;
using System.Linq;
public class MultiEntryPointSmartContract : SmartContract {
public object Main (string name, params object[] parameters) {
if (name == null || name.Trim().Length == 0) {
throw new ArgumentNullException("The method name parameter can not be empty");
}
var methods = this.GetType().GetMethods().Where(x => x.Name == name && x.GetParameters().Length == parameters.Length);
if (methods.Count() == 0) {
@rodoufu
rodoufu / new-year-chaos.py
Created August 22, 2018 20:04
New Year Chaos
# Complete the minimumBribes function below.
def minimumBribes(q):
soma = 0
for i in xrange(len(q) - 1, -1, -1):
if q[i] - (i + 1) > 2:
print("Too chaotic")
return
for j in xrange(max(0, q[i] - 2), i):
soma += q[j] > q[i]
print soma
@rodoufu
rodoufu / new-year-chaos
Last active August 22, 2018 20:04
New Year Chaos
# Complete the minimumBribes function below.
def minimumBribes(q):
soma = 0
for i in xrange(len(q) - 1, -1, -1):
if q[i] - (i + 1) > 2:
print("Too chaotic")
return
for j in xrange(max(0, q[i] - 2), i):
soma += q[j] > q[i]
print soma