Skip to content

Instantly share code, notes, and snippets.

View cgarciae's full-sized avatar

Cristian Garcia cgarciae

View GitHub Profile
@cgarciae
cgarciae / async_stream.ex
Created February 13, 2016 19:31
Async Stream Colltaz Stream Elixir
defmodule Streamer do
def async(enum) do
Stream.resource(
#Start
fn ->
origin = self
spawn fn ->
for x <- enum do
send origin, {:elem, x}
end
@cgarciae
cgarciae / README.md
Created November 6, 2016 17:30
nvidia-docker + docker-compose hello world

nvidia-docker with docker-compose

Setup

  1. Install nvidia-docker-plugin
  2. Reboot (for some reason)
  3. On the folder with this docker-compose.yml file do
docker-compose up
@cgarciae
cgarciae / REAME.md
Last active April 19, 2018 01:26
cudnn-install-tensorflow

cudnn install ubuntu + tensorflow

  1. Install cuda
  2. Export variables in ~/.bashrc or ~/.zshrc.
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda
  1. Download cudnn. Note: check TensorFlow install guide for the correct version.
  2. Extract cudnn, this extracts a folder named cuda, cd into it.
@cgarciae
cgarciae / rsync-watch.sh
Created August 30, 2018 04:48
rsync project to server
rsync --exclude-from=.gitignore -avz -e ssh . $1
while inotifywait -r -e modify,create,delete . ; do
rsync --exclude-from=.gitignore -avz --delete -e ssh . $1
done
from aiohttp import ClientSession
from pypeln import io
import asyncio
import sys
async def fetch(url, session):
async with session.get(url) as response:
return await response.read()
async def main():
@cgarciae
cgarciae / server.py
Last active September 23, 2018 15:22
server.py
# server.py
from aiohttp import web
import asyncio
import random
async def handle(request):
await asyncio.sleep(random.randint(0, 3))
return web.Response(text="Hello, World!")
@cgarciae
cgarciae / timed.sh
Last active May 9, 2022 00:27
timed.sh
# timed.sh
ulimit -n 3000 # increase to avoid "out of file descriptors" error
python server.py &
sleep 1 # Wait for server to start
/usr/bin/time --format "Memory usage: %MKB\tTime: %e seconds\tCPU usage: %P" "$@"
@cgarciae
cgarciae / client-async-sem.py
Last active May 9, 2022 00:28
client-async-sem.py
# client-async-sem.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
limit = 1000
async def fetch(url, session):
async with session.get(url) as response:
@cgarciae
cgarciae / client-async-as-completed.py
Last active September 23, 2018 15:21
client-async-as-completed.py
# client-async-as-completed.py
from aiohttp import ClientSession, TCPConnector
import asyncio
from itertools import islice
import sys
def limited_as_completed(coros, limit):
futures = [
asyncio.ensure_future(c)
@cgarciae
cgarciae / task_pool.py
Last active June 6, 2019 18:57
task_pool.py
import asyncio
class TaskPool(object):
def __init__(self, workers):
self._semaphore = asyncio.Semaphore(workers)
self._tasks = set()
async def put(self, coro):