View python_typings_are_a_joke.py
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", { |
View merge_sort.rs
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![]; |
View diamond_kata.js
// 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; |
View coroutine_maker.py
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 |
View Encode.py
# 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()) |