Skip to content

Instantly share code, notes, and snippets.

View akkefa's full-sized avatar
💻
Grit

Ikram Ali akkefa

💻
Grit
View GitHub Profile
@akkefa
akkefa / 1. Install python3.6 & pip3.md
Created February 23, 2018 13:25 — forked from alyssaq/1. Install python3.7 & pip3.md
python3.6 setup on Mac 10.13 (High Sierra)
  1. Install Python 3.6.x from https://www.python.org/downloads/ or via homebrew
    Check that python3 has been installed by running it at the terminal:
$ python3
>>> Python 3.6.4
  1. Download get-pip.py from https://bootstrap.pypa.io/get-pip.py and install (this should already be installed if python was installed from python.org or homebrew):
$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
@akkefa
akkefa / gist:a0827f12b67873de15543bd0c5a0f01f
Created February 28, 2018 08:11 — forked from miohtama/gist:5389146
Decoding emails in Python e.g. for GMail and imapclient lib
import email
def get_decoded_email_body(message_body):
""" Decode email body.
Detect character set if the header is not set.
We try to get text/plain, but if there is not one then fallback to text/html.
:param message_body: Raw 7-bit message body input e.g. from imaplib. Double encoded in quoted-printable and latin-1
@akkefa
akkefa / Makefile
Created March 6, 2018 13:32 — forked from rochacbruno/Makefile
Python Setup Tips and Tricks http://j.mp/setup_py
.PHONY: test install pep8 release clean
test: pep8
py.test --cov -l --tb=short --maxfail=1 program/
install:
python setup.py develop
pep8:
@flake8 program --ignore=F403 --exclude=junk
"""Downloading mp3"""
from bs4 import BeautifulSoup
import re
import requests
import urllib
from os import system
r = requests.get("http://")
@akkefa
akkefa / README-Template.md
Created March 15, 2018 05:50 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@akkefa
akkefa / json-utf8.py
Created April 10, 2018 06:44
Python 3: Save unicode(Urdu) string to file not using '\uXXXX' but using UTF-8.
# -*- coding: utf-8 -*-
import json
from codecs import open
o = { 'text': 'پنجاب' }
with open('foo.json', 'w', encoding= 'utf-8') as fp:
json.dump(o, fp, ensure_ascii= False)
@akkefa
akkefa / Python unicode Handling
Last active April 21, 2018 10:03
Python unicode Handling
# Encode: unicode code point to bytes
>>> s = u'Café'
>>> type(s.encode('utf-8'))
<class 'bytes'>
Decode: bytes to unicode code point
>>> s = bytes('Café', encoding='utf-8')
>>> s.decode('utf-8')
'Café'
Get unicode code point
@akkefa
akkefa / scp file tranfer
Created May 10, 2018 11:46
Transferring files over SSH
# copy from local machine to remote machine
scp localfile user@host:/path/to/whereyouwant/thefile
# copy from remote machine to local machine
scp user@host:/path/to/remotefile localfile
@akkefa
akkefa / pytest.sh
Created May 23, 2018 10:03 — forked from amatellanes/pytest.sh
Useful py.test commands.
py.test test_sample.py --collect-only # collects information test suite
py.test test_sample.py -v # outputs verbose messages
py.test -q test_sample.py # omit filename output
python -m pytest -q test_sample.py # calling pytest through python
py.test --markers # show available markers
@akkefa
akkefa / python Rot13 cipher
Created June 10, 2018 16:00
Rot13 is a cipher: it rotates characters forward 13 places. This makes text unreadable. But as a cipher, it is reversible by applying the translation a second time. We write rot13 with maketrans and translate.
# Create translation table.
trans = str.maketrans("abcdefghijklmnopqrstuvwxyz",
"nopqrstuvwxyzabcdefghijklm")
# Apply rot13 translation.
print("gandalf".translate(trans))
print("gandalf".translate(trans).translate(trans))