Skip to content

Instantly share code, notes, and snippets.

View leotada's full-sized avatar

Leonardo leotada

View GitHub Profile
@leotada
leotada / sorteio-amigo-secreto.cpp
Created November 22, 2019 19:45
Sorteio amigo secreto/oculto em C++ 11
// Autor Leonardo Antunes, 2019
#include <algorithm> // std::shuffle
#include <chrono> // std::chrono::system_clock
#include <iostream>
#include <random> // std::default_random_engine
#include <string>
#include <vector>
using namespace std;
@leotada
leotada / app.d
Created July 19, 2019 05:01
Fibonacci Vibe.d multithread benchmark
import core.thread;
import vibe.vibe;
import std.stdio;
int fib(int n)
{
if (n <= 1)
return n;
return fib(n - 1) + fib(n - 2);
}
@leotada
leotada / app.d
Last active July 18, 2019 03:10
Monty Hall problem simulation - written in D (Dlang)
import std.stdio;
import std.random;
import std.algorithm;
bool make_game(bool change)
{
static auto list = [1, 2, 3];
int car = list.choice();
@leotada
leotada / mock.py
Created June 26, 2019 19:23
Bottle Python example of dynamic mock
from bottle import run, request, get, post, response
@get('/<full_url:path>')
def index(full_url):
if full_url == 'test':
return 'cool'
elif full_url == 'double':
return 'triple'
else:
@leotada
leotada / sync_to_async_test.py
Created April 30, 2019 14:19
Using sync function in async loop in Python, with threads.
import time
import asyncio
import functools
import os
import threading
from concurrent.futures import ThreadPoolExecutor
contextvars = None
class SyncToAsync:
@leotada
leotada / async_request_aiohttp.py
Created April 1, 2019 19:41
Async request with aiohttp
import aiohttp
import asyncio
async def fetch(session, url):
async with session.get(url) as response:
print(response.status)
async def main():
@leotada
leotada / app.d
Last active December 19, 2018 03:09
Vibe.D Receive JSON Field
import vibe.vibe;
import vibe.core.log;
import std.conv;
void main()
{
listenHTTP("localhost:8080", &handleRequest);
runApplication();
}
@leotada
leotada / sqs_finder_cleaner.py
Created December 4, 2018 18:22
Find, show, and delete messages from AWS SQS Queue
# Each thread only read 10 messages,
# to read more use more threads or increase visibility (lock) time and run again
# Debug True only print, False delete
import boto3
import boto3.session
import threading
DEBUG = True
QUEUE_URL = 'https://sqs*.fifo'
# Delete remote tag
git push --delete origin tagname
# Delete local tag
git tag -d tagname
@leotada
leotada / theads.py
Last active August 13, 2018 14:07
Python Threading and Multiprocessing minimal examples (Single and multiple cores)
import time
# Method
def hello(name, t):
time.sleep(t)
print(f'Hello {name}')
# Parallel thread using a single processor core (use the same main core)
import threading
t = threading.Thread(target=hello, args=('Leo', 3))