Skip to content

Instantly share code, notes, and snippets.

from flask import Flask, request
app = Flask(__name__)
app.debug = False
@app.route('/')
def get_ip_address():
style = """
<style>
body { text-align: center; font-size: 8em; color: rgb(176, 204, 105); font-family: Courier; letter-spacing:-0.05em; margin-top: 25px; font-weight: bold; background: rgb(58, 58, 58); }
@chadgh
chadgh / interpolation.py
Last active September 1, 2015 19:40
Function to create an interpolate function.
def make_interpolation(from_range, to_range):
from_min, from_max = from_range
to_min, to_max = to_range
scale = float(to_max - to_min) / float(from_max - from_min)
def interpolate(value):
return to_min + (value - from_min) * scale
return interpolate
change = make_interpolation((0, 100), (0, 200))
print(change(50)) # will print 100.0
from os import environ
from fabric.api import run, env
import requests
env.hosts.append('mydomain.com')
LINODE_API_KEY = 'mylinodeapikey' # noqa
DOMAIN_ID = 'mylinodedomainid' # for mydomain.com
IPv4 = 'mylinodeipv4address'
IPv6 = 'mylinodeipv6address'
def calc_sale(price, realtor=True, closing=0.03, mortgage=148000):
if realtor:
realtor = 0.05
else:
realtor = 0.00
cost = price * (closing + realtor) + 450
rtn = price - cost - mortgage
return rtn
@chadgh
chadgh / simulation.py
Created March 31, 2017 15:18
Simulation of the Monty Hall / Game show problem
from abc import ABCMeta, abstractmethod
from random import choice
def game(player):
# determine winning and loosing doors for this round
doors = [1, 2, 3]
winning_door = choice(doors)
loosing_doors = [d for d in doors if d != winning_door]