Skip to content

Instantly share code, notes, and snippets.

View urkh's full-sized avatar
🚀
Working from home

Gustavo León Tramontin urkh

🚀
Working from home
View GitHub Profile
@awesomebytes
awesomebytes / threaded_function_python.md
Last active February 7, 2024 11:51
Make a function or method threaded in python with a decorator

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"""
@aisayko
aisayko / bulk_upsert.py
Last active May 8, 2022 23:53
Postgresql bulk upsert in Python (Django)
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)
@amoilanen
amoilanen / webcrawler.js
Last active March 24, 2022 03:14
Simple PhantomJS-based web crawler library
//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 = {};
};
@takluyver
takluyver / 2to3_nb.py
Last active November 5, 2021 02:45
Run 2to3 on IPython notebooks
#!/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
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:
@slogsdon
slogsdon / 01_readme.md
Last active April 2, 2016 22:19
Erlang: User authentication with bcrypt and ChicagoBoss