Skip to content

Instantly share code, notes, and snippets.

View ramalho's full-sized avatar
🏠
Working from home

Luciano Ramalho ramalho

🏠
Working from home
View GitHub Profile
@ramalho
ramalho / coro_life.py
Last active October 23, 2023 07:21
John Conway's Game of Life implemented with coroutines, by Brett Slatkin
#!/usr/bin/env python3
# Copyright 2014 Brett Slatkin, Pearson Education Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@ramalho
ramalho / norvigs-lispy-pybr.ipynb
Last active July 26, 2023 02:17
O lis.py de Norvig
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ramalho
ramalho / dispatch_openai_requests.py
Created April 21, 2023 20:30 — forked from neubig/dispatch_openai_requests.py
A simple script to get results from the OpenAI Asynchronous API
import openai
import asyncio
from typing import Any
async def dispatch_openai_requests(
messages_list: list[list[dict[str,Any]]],
model: str,
temperature: float,
max_tokens: int,
top_p: float,
@ramalho
ramalho / pycon-pc-irc-report.py
Created November 10, 2011 03:04
Generate report from pycon-pc JSON
import sys
import json
from itertools import dropwhile
LINE_FORMAT = '{id:>3} {mark} {yay:>2} {nay:>2} {abstain:>2} {name}'
with open(sys.argv[1]) as json_in:
talks = json.load(json_in)
for talk in dropwhile(lambda x:x['id']<264, talks):
@ramalho
ramalho / RethinkDB-why-we-failed.md
Created January 19, 2017 14:46
RethinkDB: why we failed
layout title
post
RethinkDB: why we failed

Posted on Github by Slava Akhmechet

When we [announced][shutdown-announcement] that RethinkDB is shutting down, I promised to write a post-mortem. I took some time to process the experience, and I can now write about it clearly.

Q: Who were the founders of modern physics?

A: Albert Einstein, Max Planck, and Niels Bohr are considered the founders of modern physics.


Q: How about Heisenberg?

A: Werner Heisenberg was a major contributor to the development of quantum mechanics, which is a key part of modern physics.


@ramalho
ramalho / relogio.py
Last active April 17, 2022 22:21
Um relógio bem simples feito em Python com Tkinter. Vídeo de demonstração: http://www.youtube.com/watch?v=xCiPshN9nOs
#!/usr/bin/env python3
import tkinter
from time import strftime
def tic():
rel['text'] = strftime('%H:%M:%S')
def tac():
tic()
rel.after(1000, tac)
@ramalho
ramalho / timeslice.py
Last active September 25, 2021 11:22
Abusing Python's T[4:20] syntax to make Time objects
"""
Could this be valid Python?
if now >= T[4:20:PM]: sextou()
>>> t = T[4:20]
>>> t
T[4:20]
@ramalho
ramalho / output.txt
Last active August 1, 2021 01:27
Checking if an infinite series converges on π
$ python3 pi_series.py
1 3.000000000000000000000000000000 -0.14159265358979312
2 3.122498999199199154475081741111 -0.01909365439059396
3 3.138470965295042880427445197711 -0.0031216882947502356
4 3.141030313220715797228876908775 -0.0005623403690773188
5 3.141485090117183798241740078083 -0.00010756347260931776
6 3.141571214690141999881234369241 -2.1438899651116117e-05
7 3.141588250040259211459670041222 -4.403549533904538e-06
8 3.141591728079553114127975277370 -9.2551024000187e-07
9 3.141592455512121073724074449274 -1.980776720422739e-07
from typing import TypeVar, TYPE_CHECKING
BT = TypeVar('BT', bound=float)
def triple2(a: BT) -> BT:
return a * 3
res2 = triple2(2)
if TYPE_CHECKING: