Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import json
import base64
import argparse
from enum import Enum
"""
Usage:
@mcdallas
mcdallas / pwned.py
Created May 29, 2018 12:26
Check if password is pwned
import requests
import hashlib
def is_password_pwned(password):
"""Securely check if a password has been part of a known breach by transmiting only
the first 5 digits of it's hash to api.pwnedpasswords.com """
phash = hashlib.sha1(password.encode()).hexdigest().upper()
url = f"https://api.pwnedpasswords.com/range/{phash[:5]}"
from itertools import cycle
cipher = [int(i) for i in input('Enter ciphertext:\n').split()]
splits = [cipher[::3], cipher[1::3], cipher[2::3]]
def distance_mod_256(x, y):
return min((x - y) % 256, (y - x) % 256)
@mcdallas
mcdallas / install_python3-6-5.sh
Created April 25, 2018 13:37
Build and install Python 3.6.5 in a fresh ubuntu ec2 instance
sudo apt-get install libssl-dev
sudo apt-get install gcc
sudo apt-get install zlib1g-dev
cd /opt
sudo wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
sudo tar -xvf Python-3.6.5.tgz
cd Python-3.6.5
@mcdallas
mcdallas / daemon.py
Created April 24, 2018 08:57
A simple unix/linux daemon in Python
"""Generic linux daemon base class for python 3.x."""
import sys, os, time, atexit, signal
class Daemon:
"""A generic daemon class.
Usage: subclass the daemon class and override the run() method."""
def __init__(self, pidfile):

Keybase proof

I hereby claim:

  • I am mcdallas on github.
  • I am mcdallas (https://keybase.io/mcdallas) on keybase.
  • I have a public key ASAzVnWReYKh-qPba_e25kweyoGMr6GI-fdXdgr1Uywh8wo

To claim this, I am signing this object:

import hashlib
from datetime import datetime
import pprint
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
04c74c268f5d9335e687cf7186f482564ce1f514e92af1ea5b4fb8f878783caad38e5b11660db81e366faaf0829c3a170a9495e6964244659bf7e6dffac00c7950;k0nstantin0s
extern crate num;
use num::bigint::BigInt;
use num::FromPrimitive;
use num::Integer;
use num::One;
use num::Zero;
#[derive(PartialEq, Clone)]
struct Point {
@mcdallas
mcdallas / pi_monte_carlo.py
Last active November 1, 2017 17:21
Estimate pi by repeatedly drawing from a uniform distribution
import numpy as np
def estimate_pi(z):
x = np.random.uniform(low=-1, high=1, size=z)
y = np.random.uniform(low=-1, high=1, size=z)
return (x**2 + y**2 < 1).sum()/z*4