Skip to content

Instantly share code, notes, and snippets.

"""
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 61
model name : Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
stepping : 4
microcode : 0x1f
cpu MHz : 905.705
@b1r3k
b1r3k / aiohttp_awaitables.py
Created July 3, 2019 12:57
Awaitables within aiohttp HTTP server
import asyncio
from aiohttp import web
async def long_running_task(req):
await asyncio.sleep(10)
print('%s Done' % req)
async def long_running_with_future(req, fut):
def solution(H):
"""
:param H:
:return:
H[0] = 8 H[1] = 8 H[2] = 5
H[3] = 7 H[4] = 9 H[5] = 8
H[6] = 7 H[7] = 4 H[8] = 8
def solution(S, P, Q):
"""
:param S:
:param P:
:param Q:
:return:
>>> solution('CAGCCTA', [2, 5, 0], [4, 5, 6])
[2, 4, 1]
'''
A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has an impact factor, which is an integer. Nucleotides of types A, C, G and T have impact factors of 1, 2, 3 and 4, respectively. You are going to answer several queries of the form: What is the minimal impact factor of nucleotides contained in a particular part of the given DNA sequence?
The DNA sequence is given as a non-empty string S = S[0]S[1]...S[N-1] consisting of N characters. There are M queries, which are given in non-empty arrays P and Q, each consisting of M integers. The K-th query (0 ≤ K < M) requires you to find the minimal impact factor of nucleotides contained in the DNA sequence between positions P[K] and Q[K] (inclusive).
For example, consider string S = CAGCCTA and arrays P, Q such that:
P[0] = 2 Q[0] = 4
P[1] = 5 Q[1] = 5
P[2] = 0 Q[2] = 6

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@b1r3k
b1r3k / 4steps.md
Created June 15, 2012 14:28 — forked from timothy1ee/4steps.md
Notes on Four Steps to the Epiphany

Notes on Four Steps to the Epiphany

The Hero's Journey

A startup is not unlike a hero's journey; there's a vision or goal, and a journey filled with obstacles. Just as the hero's story has archetypal patterns, successful startups share the same outline. I.e., there is a true and repeatable path that eliminates or mitigates the most egregious risks and allows the company to grow into a large, successful enterprise. Not only that, but the successful path is nearly completely different from traditional "Product Development" processes and methodologies; Steve Blank calls this path "Customer Development". This book describes the "Customer Development" model.

Winners and Losers

Essentially, the criteria for success is simple: products developed with constant contact with customers win; products that aren't, lose.