Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
arthuralvim / use_pfx_with_requests.py
Created Apr 17, 2019 — forked from erikbern/use_pfx_with_requests.py
How to use a .pfx file with Python requests – also works with .p12 files
View use_pfx_with_requests.py
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 Feb 21, 2019
Example of python queues and multithreading.
View queue_threading.py
import queue
import threading
num_worker_threads = 1
def do_work(item):
print(item)
View pytest-fixture-modularization.md

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
View ansible_commands.md

Install

$ pip install ansible

Basic

$ ansible-playbook -i inventory <playbook.yml> -l <host_scope>
@arthuralvim
arthuralvim / files_info.py
Created Dec 8, 2018
Just a script to get some information about my files.
View files_info.py
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 Dec 6, 2018
Just a script to work and sync heroku backups with s3.
View heroku-backups.sh
# 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 Jan 16, 2019
GNU Screen Commands
View screen.md

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 Oct 22, 2018 — forked from jonasgeiregat/generate_fixtures.py
Management command for django to dump database data (fixtures) on a per model base.
View generate_fixtures.py
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 Oct 1, 2018
Sobre chaves SSH
View about_keys.md
You can’t perform that action at this time.