Skip to content

Instantly share code, notes, and snippets.

View fhpriamo's full-sized avatar
👋
Hello!

Fábio Priamo fhpriamo

👋
Hello!
View GitHub Profile
@fhpriamo
fhpriamo / profiling.py
Created September 22, 2021 02:05
Some simple profiling.
import cProfile, pstats
import operator
import contextlib
from functools import reduce
from itertools import accumulate
import sys
def cumsum(num=0):
"""Loop based"""
total = 0
@fhpriamo
fhpriamo / README.md
Created January 28, 2021 16:51 — forked from rubencaro/README.md
Python installation guide

Python installation guide

These are my notes, not a generic solution. They are not meant to work anywhere outside my machines. Update version numbers to whatever are the current ones while you do this.

Install asdf and its python plugin, then install Python

asdf lives in https://github.com/asdf-vm/asdf

Follow its installation instructions, which at the moment of writing were:

#!/usr/bin/env python3
import sys
import re
import requests
uri_regex = re.compile(
r'^(?:http|ftp)s?://'
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
r'localhost|'
class LinkedList():
"""A singly general purpose linked list implementation."""
class _Node():
"""A singly linked node."""
def __init__(self, value, next=None):
self.next = next
self.value = value
const { MyVeryUsefulProject } = require('../index');
const { getFooOfId, saveFoo } = require('../infrastructure/inMemory');
describe('Feature: updating bar', () => {
describe('scenario: updating bar with a value not containing a "?"', () => {
describe('given a foo object in database with the id foo1 and a bar value of "initial bar value"', () => {
describe('when updating the bar value to "some new value"', async (done) => {
test('then the foo object with id foo1 should have its bar value set to "some new value"', () => {
const inMemoryDatabase = {
foo1: {
@fhpriamo
fhpriamo / nanotest.js
Created October 7, 2020 17:13
Ultra minimalistic testing utility for JS
const assert = require("assert");
function red(text) {
return `\x1b[30m\x1b[101m${text}\x1b[0m`;
}
function green(text) {
return `\x1b[30m\x1b[102m${text}\x1b[0m`;
}
@fhpriamo
fhpriamo / composition-properties.js
Last active October 7, 2020 17:29
Tests for basic composition properties in JS (with Jest)
function compose (...fns) {
function _compose(fnA, fnB) {
if (fnA === undefined) {
throw new Error('compose needs at least one argument')
}
return (...args) => {
return fnA(fnB(...args));
}
}
K --- Y // K e Y são opcionais; K e Y NÃO possuem quaisquer relações.
K === Y // K e Y são necessários; K e Y NÃO possuem quaisquer relações.
K --> Y // K e Y são opcionais; A presença de K demanda que Y esteja presente.
K --x Y // K e Y são opcionais; A presença de K demanda que Y NÃO esteja presente.
K ==x Y // K é necessário; A presença de K demanda que Y NÃO esteja presente (Y é proibido).
K ==> Y // K é necessário; A presença de K demanda que Y esteja presente (Y é necessário)
K <=> Y // K e Y são necessários; A presença de K demanda que Y esteja presente; A presença de Y demanda que K esteja presente.
K <-> Y // K e Y são opcionais; A presença de K demanda que Y esteja presente; A presença de Y demanda que K esteja presente.
K x-x Y // K e Y são opcionais; A presença de K demanda que Y NÃO esteja presente; A presença de Y demanda que K NÃO esteja presente.
K x=x Y // K e Y são proibidos; A presença de K demanda que Y NÃO esteja presente; A presença de Y demanda que K NÃO esteja presente.
@fhpriamo
fhpriamo / Every possible TypeScript type.md
Created September 1, 2020 18:04 — forked from laughinghan/Every possible TypeScript type.md
Diagram of every possible TypeScript type

Hasse diagram of every possible TypeScript type

  • any: magic, ill-behaved type that acts like a combination of never (the proper [bottom type]) and unknown (the proper [top type])
    • Anything at all is assignable to any, and any is assignable to anything at all.
    • Identities: any & AnyTypeExpression = any, any | AnyTypeExpression = any
    • Key TypeScript feature that allows for [gradual typing].
  • unknown: proper, well-behaved [top type]
    • Anything at all is assignable to unknown. unknown is only assignable to itself (unknown) and any.
    • Identities: unknown & AnyTypeExpression = AnyTypeExpression, unknown | AnyTypeExpression = unknown
  • Prefer over any whenever possible. Anywhere in well-typed code you're tempted to use any, you probably want unknown.