Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
arthuralvim / use_pfx_with_requests.py
Created April 17, 2019 18:35 — forked from erikbern/use_pfx_with_requests.py
How to use a .pfx file with Python requests – also works with .p12 files
import contextlib
import OpenSSL.crypto
import os
import requests
import ssl
import tempfile
@contextlib.contextmanager
def pfx_to_pem(pfx_path, pfx_password):
''' Decrypts the .pfx file to be used with requests. '''
@arthuralvim
arthuralvim / queue_threading.py
Created February 21, 2019 17:18
Example of python queues and multithreading.
import queue
import threading
num_worker_threads = 1
def do_work(item):
print(item)
@arthuralvim
arthuralvim / pytest-fixture-modularization.md
Created February 11, 2019 21:50 — forked from peterhurford/pytest-fixture-modularization.md
How to modularize your py.test fixtures

Using py.test is great and the support for test fixtures is pretty awesome. However, in order to share your fixtures across your entire module, py.test suggests you define all your fixtures within one single conftest.py file. This is impractical if you have a large quantity of fixtures -- for better organization and readibility, you would much rather define your fixtures across multiple, well-named files. But how do you do that? ...No one on the internet seemed to know.

Turns out, however, you can define fixtures in individual files like this:

tests/fixtures/add.py

import pytest

@pytest.fixture
@arthuralvim
arthuralvim / ansible_commands.md
Created January 30, 2019 13:14
Ansible Commands

Install

$ pip install ansible

Basic

$ ansible-playbook -i inventory  -l 
@arthuralvim
arthuralvim / files_info.py
Created December 8, 2018 21:41
Just a script to get some information about my files.
import os
import sys
import json
import datetime
from collections import namedtuple
from pathlib import Path
_timestamp_convert = datetime.datetime.fromtimestamp
@arthuralvim
arthuralvim / heroku-backups.sh
Created December 6, 2018 20:31
Just a script to work and sync heroku backups with s3.
# install awscli and heroku cli before.
# sudo pip install awscli
#
sudo su
curl https://cli-assets.heroku.com/install.sh | sh
exit
heroku login --interactive
heroku apps
@arthuralvim
arthuralvim / screen.md
Last active March 24, 2020 11:48
GNU Screen Commands

Screen Commands

On the command prompt, type screen. Run the desired program. Use the key sequence ctrl-a + ctrl-d to detach from the screen session. Reattach to the screen session by typing screen -r.

List running screen sessions

$ screen -list

or

@arthuralvim
arthuralvim / generate_fixtures.py
Created October 22, 2018 21:09 — forked from jonas-grgt/generate_fixtures.py
Management command for django to dump database data (fixtures) on a per model base.
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
from optparse import make_option
class Command(BaseCommand):
"""
Generate a fixture file for a specific model.
Useage: ./manage.py generate_fixtures app.models.MyModel --file=MyModelsOutputFile.json
"""
@arthuralvim
arthuralvim / about_keys.md
Last active October 1, 2018 18:59
Sobre chaves SSH