Skip to content

Instantly share code, notes, and snippets.

View danielgoncalves's full-sized avatar

Daniel Gonçalves danielgoncalves

View GitHub Profile
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 October 15, 2020 03:54
Lazy sorter - an iterator that yields items in sorted order, lazily
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 June 30, 2021 06:30
Add C# += / -= event subscriptions to Python using the Events package
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
@luzfcb
luzfcb / installing_pyenv_on_ubuntu_based_distros.md
Last active May 2, 2024 17:51
Quick install pyenv and Python

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

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 may 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 September 13, 2017 02:34
Generate a git patch for a specific commit

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

@wojteklu
wojteklu / clean_code.md
Last active May 6, 2024 20:41
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@henriquebastos
henriquebastos / secret_gen.py
Created December 23, 2015 13:50
SECRET_KEY generator.
#!/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 July 5, 2023 10:56
Use of __main__.py

The use of __main__.py to create executables

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

Being __main__.py:

print("Hello")

@nicolaiarocci
nicolaiarocci / validate_objects.py
Created January 5, 2015 10:09
Validating complex user objects with Cerberus
import copy
from cerberus import Validator
from cerberus import errors
from collections import Mapping, Sequence
class ObjectValidator(Validator):
def __init__(self, *args, **kwargs):