Skip to content

Instantly share code, notes, and snippets.

View santiagobasulto's full-sized avatar

Santiago Basulto santiagobasulto

View GitHub Profile
@santiagobasulto
santiagobasulto / parse_timedeltas.py
Last active March 7, 2024 14:57
A simple script to parse human readable time deltas into Python datetime.timedeltas
import re
TIMEDELTA_REGEX = (r'((?P<days>-?\d+)d)?'
r'((?P<hours>-?\d+)h)?'
r'((?P<minutes>-?\d+)m)?')
TIMEDELTA_PATTERN = re.compile(TIMEDELTA_REGEX, re.IGNORECASE)
def parse_delta(delta):
@santiagobasulto
santiagobasulto / server.py
Created April 4, 2021 13:21
A Python 3 debugging server based on http.server that logs every request. Use it to inspect incoming connections.
import time
from functools import partialmethod
from http.server import BaseHTTPRequestHandler, HTTPServer
import utils
class Request:
def __init__(self, method, path, headers, stream):
self.path = path
self.method = method.upper()
# views.py
from myproject.myfunctions import upload_profile_picture
def profile_picture(request):
# setup (checking for post, checking if the
# user is authenticated, etc.)
user = request.user
pic_file = request.FILES['profile_picture']
result_url = upload_profile_picture(pic_file)
from django.http import HttpResponseForbidden
from django.http import JsonResponse
from pusher import Pusher
class PusherAuthStrategy:
def __init__(self, namespace):
self.namespace = namespace
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@santiagobasulto
santiagobasulto / gist:3056999
Created July 5, 2012 23:05
Mocking private methods in python
""" This is a simple gist to show how to mock
private methods. I've got lots of questions
regarding this topic. Most people seems confused.
Hope it helps.
"""
import unittest
import mock
@santiagobasulto
santiagobasulto / Python time complexity wiki page.md
Last active March 28, 2023 05:12
Time complexity document from the python wiki is gone. I got the last cached copy from Internet Archive and recreated it here. Thanks Internet archive! Original source: http://wiki.python.org/moin/TimeComplexity Last copy from Internet archive: http://web.archive.org/web/20121023182950/http://wiki.python.org/moin/TimeComplexity

Time complexity

This page documents the time-complexity (aka "Big O" or "Big Oh") of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than a factor of O(log n).

Generally, 'n' is the number of elements currently in the container. 'k' is either the value of a parameter or the number of elements in the parameter.

list

The Average Case assumes parameters generated uniformly at random.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@santiagobasulto
santiagobasulto / gulpfile.js
Created December 2, 2014 20:01
expressjs + nodemon + browser-sync
'use strict';
var gulp = require('gulp');
var browserSync = require('browser-sync');
var nodemon = require('gulp-nodemon');
// we'd need a slight delay to reload browsers
// connected to browser-sync after restarting nodemon
var BROWSER_SYNC_RELOAD_DELAY = 500;