Skip to content

Instantly share code, notes, and snippets.

🔥
add-commit-push

Rafael Broseghini RafaelBroseghini

🔥
add-commit-push
Block or report user

Report or block RafaelBroseghini

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@RafaelBroseghini
RafaelBroseghini / reverse_integer.py
Last active Feb 13, 2019
Reverse an integer without casting as a string
View reverse_integer.py
def reverse_int(n: int) -> int:
num, reverse_num, size_of_num = n, 0, -1
copy = num
while copy >= 1:
copy //= 10
size_of_num += 1
while num >= 1:
@RafaelBroseghini
RafaelBroseghini / asterik-pyramids.py
Created Dec 15, 2018
Draw Asteriks Pyramids in any direction
View asterik-pyramids.py
"""
This short script allows to draw a asteriks pyramid
in any direction desired. 'Left' is the default direction.
A 'middle' pyramid has n steps with (n*2-1) asteriks.
"""
def draw_pyramid(steps: int, direction: str = "left") -> None:
possible_directions = set(["left", "right", "middle"])
@RafaelBroseghini
RafaelBroseghini / udpate-upgrade-clean-remove.sh
Last active Nov 26, 2018
Update, Upgrade, Clean, Remove
View udpate-upgrade-clean-remove.sh
#!/bin/bash
sudo apt update
sudo apt upgrade
sudo apt autoremove
sudo apt autoclean
@RafaelBroseghini
RafaelBroseghini / pull-from-all-repos.sh
Created Nov 26, 2018
Pull from all your git repos (run from home)
View pull-from-all-repos.sh
#!/bin/bash
for d in ./*/
do (cd "$d" &&
if [[ -d .git ]]; then
echo "Pulling from $d"
git pull
fi;
)
done;
@RafaelBroseghini
RafaelBroseghini / path-between-employees.py
Created Nov 26, 2018
Find the path between an employee to its highest manager
View path-between-employees.py
"""
Given a source and a destination, let us
find the path (if existing) between the two.
"""
company = {
"Bill":"Ada",
"Monty":"Alan",
"Ada":"Bob",
"John":"Linus",
@RafaelBroseghini
RafaelBroseghini / queue-as-two-stacks.py
Created Nov 21, 2018
Implement a Queue using Two Stacks
View queue-as-two-stacks.py
"""
Stack and Queue being implemented with Python List.
Both structures follow the design below:
Bottom -> [...] -> Top.
"""
def dequeue(array: list) -> int:
return array.pop()
@RafaelBroseghini
RafaelBroseghini / find-middle-spot-in-matrix.py
Created Nov 21, 2018
Find the exact middle of a given matrix
View find-middle-spot-in-matrix.py
"""
This program will find the element at the exact
middle of any columns (N) x rows (Y < N) matrix where
the number of columns and rows are odd.
# xxxxx | # xxxxx | # xxxx | # xxx
# xx(x)xx | # xxxxx | # xxxx | # x(x)x
# xxxxx | # No middle | # xxxx # No middle | # xxx
"""
@RafaelBroseghini
RafaelBroseghini / binary-search-tree-find-successor.py
Created Nov 20, 2018
Find the successor to a node in a Binary Search Tree before deleting from the tree
View binary-search-tree-find-successor.py
"""
Assume we have defined a BST class:
class BST(object):
class __Node(object):
def __init__(self, data, right=None, left=None):
self.data = data
self.right = right
self.left = left
def __init__(self, root=None):
@RafaelBroseghini
RafaelBroseghini / add-to-ordered-linked-list-recursively.py
Created Nov 19, 2018
Adding a node to a Ordered Linked List, recursively
View add-to-ordered-linked-list-recursively.py
import sys
class LinkedList(object):
class __Node(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
def setNext(self, newNext):
self.next = newNext
@RafaelBroseghini
RafaelBroseghini / add-to-linked-list-recursively.py
Created Nov 18, 2018
Add a node to a Linked List, recursively
View add-to-linked-list-recursively.py
class LinkedList(object):
class __Node(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
def __init__(self, head):
self.head = LinkedList.__Node(head)
def add(self, val):
You can’t perform that action at this time.