Skip to content

Instantly share code, notes, and snippets.

View arnauorriols's full-sized avatar

Arnau Orriols arnauorriols

View GitHub Profile
@arnauorriols
arnauorriols / Makefile
Created July 29, 2021 23:34
Rust one-stop Makefile
SHELL := /bin/bash -O globstar
# built-in targets
.PHONY: help run build build-dev test profile profile-build profiles-dir docs bench setup-bench open-bench save-bench format lint megalint typecheck check pre-commit all fix-vscode fix-perm todo
.DEFAULT_GOAL := help
# targets
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

Keybase proof

I hereby claim:

  • I am arnauorriols on github.
  • I am orriols (https://keybase.io/orriols) on keybase.
  • I have a public key ASD3cCEcmvyuoZofGntVu52GBfDvg4xcMNT9nixxA-caHAo

To claim this, I am signing this object:

from typing import NamedTuple
from mypy_extensions import TypedDict
A = TypedDict("A", { # error: Recursive types not fully supported yet, nested types replaced with "Any"
"b": B,
"c": C
})
B = TypedDict("B", {
@arnauorriols
arnauorriols / merge_sort.rs
Created October 23, 2015 19:11
Merge-sort implementation in Rust
fn mergesort(unsorted: &[u32]) -> Vec<u32> {
let n = unsorted.len();
if n < 2 {
return unsorted.to_vec();
}
let sorted_child1 = mergesort(&unsorted[..n/2]);
let sorted_child2 = mergesort(&unsorted[n/2..]);
let mut ptr1 = 0;
let mut ptr2 = 0;
let mut sorted = vec![];
@arnauorriols
arnauorriols / diamond_kata.js
Created February 2, 2015 09:47
Diamond kata with a TDD approach, in Javascript. Javascript noob, any feedback is most than welcome! Particularly looking for 'idiomatic' corrections.
// Diamond Kata with a TDD approach. First attempt
'use strict';
module.exports.Diamond = Diamond;
// Encapsulate line printing
function Letter(char, spaces) {
this._char = char;
this._spaces = spaces;
@arnauorriols
arnauorriols / coroutine_maker.py
Last active July 22, 2018 15:11
(Tornado) Convert a callback-based async function to a coroutine, configuring the position/keyword the callback is expected. This can be used, for example, to convert the callback-based interface of the pika.TornadoConnection to a coroutine-based one, which is the standard async pattern suggested by Tornado nowadays.
from functools import wraps
from tornado.concurrent import return_future
class CoroutineMaker(object):
""" Convert a callback-based async function to a coroutine.
The Tornado utility gen.Task is quite useful to convert callback-based
async functions to coroutines, but has an important drawback: it expects
the callback to be passed to the function in a keyword parameter
@arnauorriols
arnauorriols / Encode.py
Created February 18, 2014 15:33
Python replacement for Encode.java used in OpenAM
# Python replacement for Encode.java used in OpenAM
#
# Author: Arnau orriols
from hashlib import sha1
from base64 import b64encode
from sys import argv
def encode(string):
return b64encode(sha1(string).digest())