Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Working from home

Gustavo León Tramontin urkh

🚀
Working from home
View GitHub Profile
@aisayko
aisayko / bulk_upsert.py
Last active Jul 12, 2021
Postgresql bulk upsert in Python (Django)
View bulk_upsert.py
def bulk_upsert(model, fields, values, by):
"""
Return the tuple of (inserted, updated) ids
"""
result = (None, None)
if values:
stmt = """
WITH data_set AS (
INSERT INTO %s (%s)
@awesomebytes
awesomebytes / threaded_function_python.md
Last active Nov 25, 2021
Make a function or method threaded in python with a decorator
View threaded_function_python.md

How to make a python function or class method threaded

From this stack overflow question I got this great snippet.

# Threaded function snippet
def threaded(fn):
    """To use as decorator to make a function call threaded.
    Needs import
    from threading import Thread"""
View serializers.py
from rest_framework.serializers import ModelSerializer
AVAILABLE_CONFIGS_FIELD = ('fields', 'read_only_fields', 'exclude', 'write_only_fields')
class BaseModelSerializer(ModelSerializer):
"""
Clase abstracta serializadora donde se pueden configurar campos para cada acciones genéricas de
las vistas ModelViewSet que provee DjangoRestFramework y acciones personalizadas
Serializer Ex:
@takluyver
takluyver / 2to3_nb.py
Last active Nov 5, 2021
Run 2to3 on IPython notebooks
View 2to3_nb.py
#!/usr/bin/env python3
"""
To run: python3 nb2to3.py notebook-or-directory
"""
# Authors: Thomas Kluyver, Fernando Perez
# See: https://gist.github.com/takluyver/c8839593c615bb2f6e80
import argparse
import pathlib
from nbformat import read, write
@slogsdon
slogsdon / 01_readme.md
Last active Apr 2, 2016
Erlang: User authentication with bcrypt and ChicagoBoss
@antivanov
antivanov / webcrawler.js
Last active Dec 18, 2021
Simple PhantomJS-based web crawler library
View webcrawler.js
//PhantomJS http://phantomjs.org/ based web crawler Anton Ivanov anton.al.ivanov@gmail.com 2012
//UPDATE: This gist has been made into a Node.js module and now can be installed with "npm install js-crawler"
//the Node.js version does not use Phantom.JS, but the API available to the client is similar to the present gist
(function(host) {
function Crawler() {
this.visitedURLs = {};
};