This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import email.utils | |
from email.mime.text import MIMEText | |
from collections import namedtuple | |
Prankee = namedtuple('Prankee', 'name id email') | |
colleague = Prankee('Colleague', 'colleague_id', '[email protected]') | |
subject = '[IT Information] %s we detect unauthorized actions from your account' % colleague.name | |
body = '''Dear user %s (%s), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
import webbrowser | |
import os | |
destination = os.environ.get('HOME_ADDR') | |
destination = '+'.join(destination.split()) | |
origin = os.environ.get('OFFICE_ADDR') | |
origin = '+'.join(origin.split()) | |
url = 'https://www.google.com/maps/dir/%s/%s' % (origin, destination) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
app_id = os.environ['APP_ID'] | |
app_secret = os.environ['APP_SECRET'] | |
data = {'grant_type': 'client_credentials', | |
'client_id': app_id, | |
'client_secret': app_secret} | |
token = requests.post('https://api.yelp.com/oauth2/token', data=data) | |
access_token = token.json()['access_token'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
def total_payment(principal, monthly_rate, payment_months): | |
return principal * (1 + monthly_rate) ** payment_months | |
def monthly_payment(principal, monthly_rate, payment_months): | |
weighted_month = ((1 + monthly_rate) ** payment_months - 1) / monthly_rate | |
return total_payment(principal, monthly_rate, payment_months) / weighted_month | |
print('--------------------------------------------') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, v): | |
self.v = v | |
self.l = None | |
self.r = None | |
def __repr__(self): | |
return '<Node %d>' % self.v | |
def children(node): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Utilities to help solving problems." | |
import itertools | |
import functools | |
from collections import Counter | |
from operator import mul, pow | |
def prime_factors(num): | |
""" Yield the factors of a given number.""" | |
i = 2 | |
while i * i <= num: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def ping(host, port): | |
"""A generator to ping a particular application. | |
Return True if the destination port is occupied | |
Example: | |
>>> # ping application at port 99 | |
>>> pinger = ping('127.0.0.1', 99) | |
>>> # When there's no application ruuning |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import perf_counter | |
from array import array | |
from contextlib import contextmanager | |
@contextmanager | |
def timing(label: str): | |
t0 = perf_counter() | |
yield lambda: (label, t1 - t0) | |
t1 = perf_counter() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> range | |
#object[clojure.core$range xxxxxxxx] | |
;; Don't do this in your repl! | |
;; (range) | |
;; Do this instead | |
user=> (take 4 (range)) | |
(0 1 2 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (range 10) | |
(0 1 2 3 4 5 6 7 8 9) |
OlderNewer