Skip to content

Instantly share code, notes, and snippets.

View mauricioabreu's full-sized avatar
🇧🇷
always learning

Mauricio Antunes mauricioabreu

🇧🇷
always learning
View GitHub Profile
@mauricioabreu
mauricioabreu / invert_binary_tree.py
Last active November 3, 2023 18:14
Invert binary tree
class Node:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def invert_binary_tree(root):
if root:
stack = [root]
@mauricioabreu
mauricioabreu / select.lua
Created February 24, 2022 11:01
Lua DSL for select func without parentheses
local function select(key)
return function(m)
return m[key]
end
end
local name = select "brand_name" {
year = 1992,
brand = "VW",
name = "Beatle",
@mauricioabreu
mauricioabreu / even_length.ex
Created July 25, 2018 03:31
Using Elixir pattern matching to check if a list has an event length of elements
// Write a function even_length? that uses pattern matching only to return false
// if the list you pass it has an odd number of elements, true otherwise.
def even_length?([_, _ | t]) do
even_length?(t)
end
def even_length?([_ | []]) do
false
end
@mauricioabreu
mauricioabreu / import_lib_example.py
Last active July 25, 2018 14:12
importlib module example
import importlib
# Dynamic input
my_class = "Ping"
my_module = "projeto.challenges.{dynamic_module}".format(dynamic_module=my_class.lower())
# Dynamic import
module = importlib.import_module(my_module)
class_i_want = getattr(module, my_class)