Skip to content

Instantly share code, notes, and snippets.

View tudormunteanu's full-sized avatar
👨‍💻
Crafting and leading. Mostly Web3 these days. 🛠️🚀 #TechLeader

Tudor Munteanu tudormunteanu

👨‍💻
Crafting and leading. Mostly Web3 these days. 🛠️🚀 #TechLeader
View GitHub Profile

Robot Warehouse

We have installed a robot in our warehouse and now we need to be able to send it commands to control it. We need you to implement the control mechanism.

For convenience the robot moves along a grid in the roof of the warehouse and we have made sure that all of our warehouses are built so that the dimensions of the grid are 10 by 10. We've also made sure that all our warehouses are aligned along north-south and east-west axes.

All of the commands to the robot consist of a single capital letter and different commands are dilineated by whitespace.

Part One

@tudormunteanu
tudormunteanu / timer.py
Created July 16, 2021 15:23
Simple class useful for timing Python code.
class Timer:
"""Measure time used.
# Setup timer
>>> timer = Timer()
# Access as a string
>>> timer.print()
Time elapsed is 0:00:03.
>>> timer.print()
@tudormunteanu
tudormunteanu / ch4.md
Last active April 6, 2021 19:55
Scala For the Impatient 2nd Edition - Excercises
  1. Set up a map of prices for a number of gizmos that you covet. Then produce a second map with the same keys and the prices at a 10 percent discount.

  2. Write a program that reads words from a file. Use a mutable map to count how often each word appears. To read the words, simplyy use a java.utils.Scanner:

val in = new java.util.Scanner(new java.io.File("myFile.txt"))
while (in.hasNext()) *process* in.next()

Or look at Chapter 9 for a Scalesque way.

@tudormunteanu
tudormunteanu / async.py
Created December 15, 2020 17:33
Asyncio + aiohttp DevCru sample.
"""
IO-bound concurrency with asyncio and aiohttp.
Rewritten from the previous approach that was using gevent, due to
http://www.gevent.org/api/gevent.monkey.html which conflicted with
`google.cloud` libs.
`gevent` allows to create pools to manage greenlets.
What are greenlets?
@tudormunteanu
tudormunteanu / sample.sql
Created November 2, 2020 11:26
Batch delete database rows with transactions
begin;
\timing on
DELETE FROM
account AS a
USING
member AS m
WHERE
m.territory='XY' AND
m.member_id >= (:v1 + 0) * 1000 AND
class SpainComparisonQuery(StrictSchema):
tariff_code = fields.Str(
description=(
"Only in Spain. Three digit version of the "
"tariff type. Example: 001 or 004."
)
)
meter_type = fields.Str(
description=(
"Only in Spain. Represents the meter type "
@tudormunteanu
tudormunteanu / requirements.txt
Created August 7, 2020 12:15
Graphene Enums vs Python Enums
_________________________________________________________________________________ test_enum _________________________________________________________________________________
def test_enum():
client = Client(schema)
executed = client.execute(
"""
{
episode
}
"""
@tudormunteanu
tudormunteanu / prepare-commit-msg
Last active February 17, 2024 16:15
git pre-commit hook to automatically prefix the commit message with the branch name
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
# Works for branch names like: XXXX-1111-longer-description
# For other patterns, please alter the regex in sed
#
PREFIX=$(git branch | grep '*' | sed 's/\(\*\ \)\([A-Z0-9\-]*\)-\([a-z\-]*\)/\2/')
@tudormunteanu
tudormunteanu / .bash_profile
Last active April 4, 2019 11:21
Example of .bash_profile config
[[ -f ~/.bashrc ]] && source ~/.bashrc
alias docker_stop_all='docker stop $(docker ps -a -q) ; docker rm $(docker ps -a -q) --force'
alias docker_rm_all='docker_stop_all ; docker rmi --force $(docker images -q -a) ; docker volume rm $(docker volume ls -qf dangling=true) ; docker network rm $(docker network ls -q)'
if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fi
export CLICOLOR=1
@tudormunteanu
tudormunteanu / router.py
Created November 9, 2018 11:44
Sanic Header Based Versioning Router
import re
import uuid
from collections import defaultdict, namedtuple
from collections.abc import Iterable
from functools import lru_cache
from urllib.parse import unquote
from sanic.constants import HTTP_METHODS
from sanic.exceptions import InvalidUsage
from sanic.exceptions import MethodNotSupported, NotFound