Skip to content

Instantly share code, notes, and snippets.

@jchysk
jchysk / cryptography_helpers.py
Created May 10, 2016 05:03
A number of helper functions for common cryptography uses
"""
from helpers import generate_RSA, encrypt_RSA, generate_password, decrypt_RSA, generate_AES, decrypt_AES, pad
priv, pub = generate_RSA()
encrypted = encrypt_RSA(pub, generate_password())
key, iv, encryptor = generate_AES()
aes_encrypted = encryptor.encrypt(pad("this is a very long string " * 25))
decrypt_AES(key, iv, aes_encrypted)
"""
BS = 16
@jchysk
jchysk / totp to QR.py
Created August 26, 2015 23:20
Secret to QR Code
"""
Function that takes two values to generate a QR Code that can be scanned with LaunchKey or TOTP holder
@param identity: Name and place. E.g. username/Gmail
@param secret: The actual TOTP code
Saves the image locally as a png
Requires PIL (pillow) and qrcode
"""
def convert(self, identity, secret):
import re
@jchysk
jchysk / require at least one.py
Created August 26, 2015 22:40
Formencode validator that will require a minimum of one field
from formencode import Schema, validators, Invalid
from formencode.validators import FormValidator
class RequireAtLeastOne(FormValidator):
choices = []
__unpackargs__ = ('choices',)
def _convert_to_python(self, value_dict, state):
for each in self.choices:
if value_dict.get(each) is not None:
@jchysk
jchysk / pick_winner.py
Created April 7, 2015 19:34
Winner Picker using Blockchain
"""
Pick a random winner
"""
if __name__ == '__main__':
import sys
entries = sys.argv[1]
import requests
# Grab the latest hash
latest_hash = requests.get("https://blockchain.info/q/latesthash")
@jchysk
jchysk / keybase.md
Created February 13, 2015 08:07
Keybase Proof

Keybase proof

I hereby claim:

  • I am jchysk on github.
  • I am jchysk (https://keybase.io/jchysk) on keybase.
  • I have a public key whose fingerprint is 4697 5E88 C723 4E13 57E0 E88D BC7F C851 B93C C464

To claim this, I am signing this object:

@jchysk
jchysk / email_verifier.py
Created February 9, 2015 23:57
Check that domain of email addresses can be resolved
#!/usr/bin/python
"""
Takes a csv of email addresses and gives back a csv of the email addresses that have a resolvable domain.
"""
domains = list()
checked = []
checked_bad = []
import socket
@jchysk
jchysk / jpeg to pdf
Created July 24, 2014 00:07
Convert jpegs to PDFs and then resize to ebook size
#!/bin/bash
for f in *.jpeg; do convert ./"$f" ./"${f%.jpeg}.pdf"; done
for f in *.pdf; do gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -sOutputFile="${f%.pdf}.compressed.pdf" "$f"; done
@jchysk
jchysk / fabfile.py
Last active August 29, 2015 14:04
Fabfile that can interact with Dockers from any OS
# Docker controller
# example usage
# fab local_os restart_env
from fabric.api import *
def _vagrant():
env.user = "vagrant"
@jchysk
jchysk / gist:7582c7618f9a35b9b5bd
Created May 27, 2014 03:09
Secretary problem; Daut version towards optimizing average instead
#Daut's edited secretary problem
#function which randomizes a list
def randomize_rankings(sec):
import random
random.shuffle(sec)
return sec
#function which returns a secretary based on Daut's algorithm
def chooseSecretary(sec):
@jchysk
jchysk / gist:2ea832c30f4a2d475079
Created May 27, 2014 03:08
Secretary problem
#Original secretary problem solution based on 100 secretaries and just on the ranking of secretaries from 1-100
#want to figure out both average ranking chosen and how often the best candidate is chosen
#function which randomizes a list
def randomize_rankings(sec):
import random
random.shuffle(sec)
return sec