Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
arthuralvim / pytest.sublime-snippet
Created April 20, 2017 14:54
Just a snippet for Pytest files.
<snippet>
<content><![CDATA[
import pytest
@pytest.mark.parametrize('input, expected', [
('2 + 3', 5),
('6 - 4', 2),
pytest.mark.xfail(('5 + 2', 8))
])
@arthuralvim
arthuralvim / creating_modules.py
Created March 29, 2017 19:10
Creating modules with Python.
def import_code(code, name, add_to_sys_modules=0):
"""
Import dynamically generated code as a module. code is the
object containing the code (a string, a file handle or an
actual compiled code object, same types as accepted by an
exec statement). The name is the name to give to the module,
and the final argument says wheter to add it to sys.modules
or not. If it is added, a subsequent import statement using
name will return this module. If it is not added to sys.modules
import will try to load it in the normal fashion.
@arthuralvim
arthuralvim / cryptokids-polybius-grid.py
Created March 5, 2017 02:24
Decifrando em Python.
import string
alfabeto = string.ascii_uppercase
matriz_alfabeto = [alfabeto[x * 5:(x * 5) + 5] for x in range(0, 6)]
mensagem = ['14', '34', '42', '25', '11', '31', '42', '41', '11', '41', '51', '', '14', '11', '34', '11', '', '53', '44','', '12', '34', '11', '31', '53', '44', '', '54', '34', '11', '43', '44', '14', '11', '34', '51', '43', '31', '42', '11', '', '14', '11', '34', '11', '', '53', '44', '', '14', '53', '41', '51', '34', '53', '44', '53', '44']
for msg in mensagem:
if not msg:
print ' ',
continue
@arthuralvim
arthuralvim / mdb_keys.json
Created February 21, 2017 19:55
Get all keys for a MongoDB collection.
mr = db.runCommand({
"mapreduce" : "extracao_unimed",
"map" : function() {
for (var key in this) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "extracao_unimed" + "_keys"
})
db[mr.result].distinct("_id")
@arthuralvim
arthuralvim / slackpost
Created February 7, 2017 14:04 — forked from dopiaza/slackpost
Post a message to a Slack channel
#!/bin/bash
# Usage: slackpost <token> <channel> <message>
# Enter the name of your slack host here - the thing that appears in your URL:
# https://slackhost.slack.com/
slackhost=PUT_YOUR_HOST_HERE
token=$1
@arthuralvim
arthuralvim / github.pages.registro.br.md
Created January 25, 2017 14:06
Pequeno tutorial de como configurar o DNS do registro.br para seu projeto hospedado aqui no GitHub. https://github.com/orige/githubpages.registro.br

tutorial de referência orige/githubpages.registro.br

GitHub:Pages no Registro.br

Este é um pequeno e simples tutorial para a utilização de domínios personalizados registrados no registro.br com github:pages para seu projeto ou página pessoal.

O que é o GitHub:Pages

GitHub Pages é um sistema de hospedagem grátis e de fácil uso para algum projeto ou página pessoal com um repositório no GitHub.

@arthuralvim
arthuralvim / instafeedjsaccess.md
Created January 18, 2017 15:49 — forked from mojaray2k/instafeedjsaccess.md
Getting Instagram Access Token for http://intafeedjs.com

#Use this URL to get your client authorized for Instafeed.JS plugin for Instagram.

  1. First login into your Instargam account
  2. Then go to https://www.instagram.com/developer/
  3. At the top click on the Button that says "Manage Clients".
  4. If you have not Register a new client.
  5. Fill out everything and where it says redirect url put this url: http://instafeedjs.com
  6. Then on the security tab make sure you uncheck "Disable implicit OAuth"
  7. Finally use this link to authoruize Instafeed. Where it says "[Client ID]" replace that including the brackets with your clientID from instagram:
  8. https://instagram.com/oauth/authorize/?client_id=[Client ID]&redirect_uri=http://instafeedjs.com&amp;response_type=token
@arthuralvim
arthuralvim / 00-detect-virtualenv-sitepackages.py
Created January 13, 2017 18:49 — forked from henriquebastos/00-detect-virtualenv-sitepackages.py
IPython startup script to detect and inject VIRTUAL_ENV's site-packages dirs.
"""IPython startup script to detect and inject VIRTUAL_ENV's site-packages dirs.
IPython can detect virtualenv's path and injects it's site-packages dirs into sys.path.
But it can go wrong if IPython's python version differs from VIRTUAL_ENV's.
This module fixes it looking for the actual directories. We use only old stdlib
resources so it can work with as many Python versions as possible.
References:
http://stackoverflow.com/a/30650831/443564
@arthuralvim
arthuralvim / matplotlibfix.sh
Created October 31, 2016 14:49
Matplotlib Error
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
# Inside the directory that needs to be hashed
# recursive, show estimated time, relative paths
md5deep -rle -W /path/to/result.md5 *
# List files with the same hash, printing the hash-path of each file (remember to keep at least one of them)
sort result.md5 | uniq -D -w 32
# Count the number of duplicate files, path to first encountered file with that hash is shown only | sort by frequency
sort result.md5 | uniq -cd -w 32 | sort -nr