Skip to content

Instantly share code, notes, and snippets.

View cdgriffith's full-sized avatar

Chris Griffith cdgriffith

View GitHub Profile
from Xlib.display import Display
from Xlib import X
from Xlib.ext import record
from Xlib.protocol import rq
import time
disp = None
keysym_map = {
32: "SPACE",
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
import json, sys; json.dump(json.load(open(sys.argv[1])), open(sys.argv[1], "w"), indent=4)
import random
try:
raw_input("Symptoms: ")
except NameError:
input("Symptoms: ")
print("Diagnosis: {0}".format(random.choice(["Pregnant", "Cancer"])))
@cdgriffith
cdgriffith / factorio_setup.sh
Created June 12, 2016 04:22
Factorio setup
cd /opt
sudo wget https://www.factorio.com/get-download/0.12.35/headless/linux64
sudo tar xzf linux64
sudo groupadd factorio
sudo useradd -g factorio factorio
sudo passwd factorio
sudo chown -R factorio:factorio factorio/
sudo mkdir factorio_data
sudo git clone https://github.com/Bisa/factorio-init.git
@cdgriffith
cdgriffith / Makefile
Last active December 15, 2016 22:46
Python deployer makefile (debian only)
HOME ?= $HOME
CWD = $(shell pwd)
VENVS ?= $(HOME)/.virtualenvs
PYTHON2 = $(VENVS)/builder2.7/bin/python2.7
PYTHON3 = $(VENVS)/builder3.5/bin/python3.5
PYTHONS = $(VENVS)/builder2.6/bin/python2.6 $(VENVS)/builder2.7/bin/python2.7 $(VENVS)/builder3.5/bin/python3.5 $(VENVS)/builder3.3/bin/python3.3 $(VENVS)/builder3.4/bin/python3.4
PYPY = $(VENVS)/builderpypy/bin/python
.PHONY: all test clean help register build
@cdgriffith
cdgriffith / gen_cert.py
Last active February 22, 2017 19:38
OpenSSL certificate creation
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import logging
from OpenSSL import crypto
log = logging.getLogger("x509_cert")
@cdgriffith
cdgriffith / .pythonrc.py
Last active November 21, 2020 04:56
Python RC file
# In .bashrc and .profile
# export PYTHONSTARTUP="$HOME/.pythonrc.py"
# pip install python-box reusables pdir2
from __future__ import print_function, with_statement, absolute_import
try:
from box import Box, BoxList
except ImportError:
print("Box not available")
@cdgriffith
cdgriffith / eafp_vs_lbyl.py
Created June 22, 2017 22:21
Python EAFP vs LBYL speeds
import reusables
@reusables.time_it()
def test_lbyl(messages):
out = []
for _ in range(10000):
if messages and messages[0] and len(messages[0]) >= 3:
out.append(messages[0][2])
return out
import reusables
import os
# to be fair, start out at same state for both tests
os.makedirs("folder", exist_ok=True)
@reusables.time_it()
def test_lbyl(remove_folder=False):