Skip to content

Instantly share code, notes, and snippets.

View diegoquintanav's full-sized avatar
🐢
Working from home

Diego Quintana diegoquintanav

🐢
Working from home
View GitHub Profile
@diegoquintanav
diegoquintanav / test_stuff.md
Created October 9, 2018 20:35
migrate unittests to pytest in Flask

Migrate from python.unittest to pytest

Check http://flask.pocoo.org/docs/1.0/testing/

# test_stuff.py

class StuffTestCase(unittest.TestCase):
    def setUp(self):
        self.app = create_app('testing') # app factory
@diegoquintanav
diegoquintanav / extra_dependencies_gitlab.md
Last active January 16, 2019 23:27
installing `extra_requires` dependencies from private git repositories

The struggle is real: Basically this bit in a setup.py worked for me.

extras_require={
        'extrapackage':  ["git@git+ssh://git@gitlab.com/<user>/<repository_name>.git"],
        },

then it's possible to do pip install -e .[extrapackage] given you have proper ssh access

@diegoquintanav
diegoquintanav / git-events.md
Last active August 30, 2019 16:23
events describing error using an interactive rebase, and going back

So I messed up with git

TL;DR

  1. Everything is under control
  2. Did an interactive rebase to move a commit to the base of my branch, forgot to include merge commits
  3. Lost my merge commits
  4. Tried to go back with git reset --hard and reflog
  5. Ended up at the base of my branch, with my unrebased commits dangling after it
  6. Want to move back to step 0, and hopefully do step 1 again, but including merge commits.
@diegoquintanav
diegoquintanav / palindromes_with_jutge.md
Last active September 21, 2019 10:32
working around Jutge's evaluation method

Given the requirements.txt file

pytest
jutge

Consider the palindrome problem in palindrome.py

@diegoquintanav
diegoquintanav / mssql_pyodbc_sqlalchemy_flask.py
Last active March 25, 2020 09:24
Build connection string of MSSQL Azure Databases
from flask_sqlalchemy import make_url
from urllib.parse import quote_plus
def build_connection_string(**params):
"""
Return the url for MSSQL Azure DB Instances
"""
connection_string = quote_plus(
("DRIVER={driver};"
@diegoquintanav
diegoquintanav / fizzbuzz.py
Last active March 25, 2020 09:24
fizzbuzz
import sys [0/6141]
"""A simple python implementation of the FizzBuzz problem.
*caveat*: It considers zero as divisible by three and five
see https://www.google.com/search?client=ubuntu&channel=fs&q=fizzbuzz+problem&ie=utf-8&oe=utf-8
and http://wiki.c2.com/?FizzBuzzInManyProgrammingLanguages
"""
@diegoquintanav
diegoquintanav / rename_files.py
Last active March 25, 2020 09:25
rename files using python
# basic renaming of files, to enforce a minimum consistency
from pathlib import Path
for ix, file in enumerate(sorted(Path.cwd().glob('*'))):
new_filename = f'{ix:02}_' + file.name.lower().replace(' ','_')
print(f'{file.name} > {new_filename}')
file.rename(new_filename)
@diegoquintanav
diegoquintanav / metaclasses.md
Last active March 25, 2020 09:26
metaclasses

Some examples of metaclasses definitions

Raw, implicit definition

class MetaClass(type): 

    def get_foo(self):
        return self._foo
    
@diegoquintanav
diegoquintanav / config.py
Last active March 25, 2020 09:26
instance configuration in Flask
## instance/config.py
HELLO_ENABLED = False
@diegoquintanav
diegoquintanav / .gitconfig
Last active March 26, 2020 15:04
git config file
[user]
email = daquintanav@gmail.com
name = Diego Quintana
[alias]
a = add
co = checkout
st = status
ci = commit
br = branch
unstage = reset HEAD --