Skip to content

Instantly share code, notes, and snippets.

Avatar

Santiago Basulto santiagobasulto

View GitHub Profile
@santiagobasulto
santiagobasulto / gist:3056999
Created Jul 5, 2012
Mocking private methods in python
View gist:3056999
""" 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 / parse_timedeltas.py
Last active Nov 6, 2020
A simple script to parse human readable time deltas into Python datetime.timedeltas
View parse_timedeltas.py
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):
View Hawking.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Substack Analysis.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@santiagobasulto
santiagobasulto / README.md
Last active Sep 11, 2020
Download HumbleBundle books in batch with a simple Python script.
View README.md

Download HumbleBundle books

This is a quick Python script I wrote to download HumbleBundle books in batch. I bought the amazing Machine Learning by O'Reilly bundle. There were 15 books to download, with 3 different file formats per book. So I scratched a quick script to download all of them in batch.

(Final Result: books downloaded)

@santiagobasulto
santiagobasulto / relative_to_absolute.py
Last active Aug 28, 2020
A quick script to transform a Markdown file's relative images to absolute by uploading them to a plugin-based service (S3, Imgur)
View relative_to_absolute.py
import re
import mimetypes
from pathlib import Path
import requests
import boto3
from botocore.exceptions import ClientError
@santiagobasulto
santiagobasulto / README.md
Last active Jul 7, 2020
A simple calculator from file inputs
View README.md

Example Gist as exercise.

This is the description, and THIS FILE IS MANDATORY.

You can include your markdown description here.

View README.md

In this exercise you will read in a delimited data file as a list of records. Each record will be an instance of InventoryItem. The format of the delimited file is unusual, but can be handled by the Python csv module with appropriate configuration.

For example, the first few lines of data/Inventory.txt contain:

Name|Price|Quantity
/Wankle rotary engine/|555.55|527
/Sousaphone w%/ stand/|333.33|123

Feather Duster|22.22|900
You can’t perform that action at this time.