Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gonçalves danielgoncalves

  • Base4 Sistemas
  • Catanduva/SP
  • Twitter @spanazzi
View GitHub Profile
View dl-tqdm.py
import concurrent.futures
import os
import re
from timeit import timeit
import requests
from tqdm import tqdm
URLS = 'urls'
@jsbueno
jsbueno / lazyquicksort.py
Last active Oct 15, 2020
Lazy sorter - an iterator that yields items in sorted order, lazily
View lazyquicksort.py
from itertools import tee
def lazy_sort(v, key=lambda x: x):
v = iter(v)
try:
pivot = next(v)
except StopIteration:
return
v_pre, v_pos = tee(v)
yield from lazy_sort((item for item in v_pre if key(item) < key(pivot)), key)
@mikeckennedy
mikeckennedy / watch_this.py
Last active Jun 30, 2021
Add C# += / -= event subscriptions to Python using the Events package
View watch_this.py
from events import Events # Note you must pip install events
class Person:
def __init__(self, name: str, age: int, city: str):
self.__events = Events(('on_name_changed', 'on_age_changed', 'on_location_changed'))
self.on_name_changed = self.__events.on_name_changed
self.on_age_changed = self.__events.on_age_changed
self.on_location_changed = self.__events.on_location_changed
View installing_pyenv_on_ubuntu_based_distros.md

Tested only on Ubuntu 20.04, KDE Neon User Edition (based on Ubuntu 20.04) and OSX Mojave.

will probably work on other newer versions, with no changes, or with few changes in non-python dependencies (apt-get packages)

NOTE: Don't create a .sh file and run it all at once. It will not work. Copy, paste, and execute each command below manually. :-)

Ubuntu

# DO NOT RUN THIS AS A ROOT USER
@emmanueltissera
emmanueltissera / git-apply-patch.md
Created Sep 13, 2017
Generate a git patch for a specific commit
View git-apply-patch.md

Creating the patch

git format-patch -1 <sha>
OR
git format-patch -1 HEAD

Applying the patch

git apply --stat file.patch # show stats.
git apply --check file.patch # check for error before applying

@henriquebastos
henriquebastos / secret_gen.py
Created Dec 23, 2015
SECRET_KEY generator.
View secret_gen.py
#!/usr/bin/env python
"""
Django SECRET_KEY generator.
"""
from django.utils.crypto import get_random_string
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
print(get_random_string(50, chars))
@rochacbruno
rochacbruno / mainpython.md
Last active May 8, 2021
Use of __main__.py
View mainpython.md

The use of __main__.py to create executables

myprojectfolder/
    |_ __main__.py
    |_ __init__.py

Being __main__.py:

print("Hello")
@nicolaiarocci
nicolaiarocci / validate_objects.py
Created Jan 5, 2015
Validating complex user objects with Cerberus
View validate_objects.py
import copy
from cerberus import Validator
from cerberus import errors
from collections import Mapping, Sequence
class ObjectValidator(Validator):
def __init__(self, *args, **kwargs):
@Kartones
Kartones / postgres-cheatsheet.md
Last active Jan 25, 2022
PostgreSQL command line cheatsheet
View postgres-cheatsheet.md

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)