Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
stevedoyle / pcie_bw_table
Created November 22, 2013 16:06
Simple utility script to generate a table of PCIe bandwidth for various link width configurations and for raw and 75% efficiency
#!/usr/bin/python
def divider():
print '-'*40
def width_str(width):
return "x%d" % (width)
gens = [1,2,3]
link_widths = [1,2,4,8,16,24,32]
@stevedoyle
stevedoyle / fileinput
Created July 8, 2013 13:44
Use fileinput to read input from files specified on the command line or stdin if no files specified. This allows something like: cat foo.txt | bar.py
import fileinput
for line in fileinput.input():
pass
@stevedoyle
stevedoyle / cleanup_whitespace.py
Last active December 14, 2015 05:58
Clean whitespace from source files. Remove trailing whitespace at the end of files and converts tabs to spaces.
#!/usr/bin/env python
#########################################################################
# Script to clean up whitespace in source files.
# - Removes trailing whitespace at the end of lines
# - Converts tabs to spaces (4 spaces = 1 tab)
#
# Copyright 2013 Stephen Doyle
#########################################################################
@stevedoyle
stevedoyle / duplicates.py
Created January 30, 2013 14:34
Removing duplicates from a list in python
data = [1,2,2,3,4,4,5,6,5,7]
no_dups = list(set(data))
@stevedoyle
stevedoyle / copy_file_list.py
Created December 11, 2012 14:33
Copy files from a file list
#!/usr/bin/python -d
import argparse
from subprocess import call
def copyfile(src, dst):
call(["cp", src, dst])
parser = argparse.ArgumentParser(description='Copy files from a list to a destination directory')
parser.add_argument('filelist', help="File containing list of filenames to copy")
@stevedoyle
stevedoyle / aes_example.py
Last active October 13, 2015 17:58
Python AES encryption code snippet
from Crypto.Cipher import AES
key='\x63\x5b\x76\xd1\x71\x5c\xdf\x2a\x69\x99\xc9\x0f\x3b\x23\x13\x02'
iv='\x4c\x84\x2e\x40\x8b\xb0\x73\x01\xe4\x64\x92\x94\xfa\x5b\x73\x0b'
obj = AES.new(key, AES.MODE_CBC, iv)
obj.decrypt(message)
@stevedoyle
stevedoyle / gist:1404781
Created November 29, 2011 13:18
A regex that test for prime numbers
# From: http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
def is_prime(n)
("1" * n) !~ /^1?$|^(11+?)\1+$/
end
@stevedoyle
stevedoyle / Vimrc
Last active September 27, 2015 22:08
vimrc
" indendentation specific to file types
:filetype plugin indent on
filetype plugin on
" spaces instead of tabs
"set expandtab
" show line numbers
"set number
@stevedoyle
stevedoyle / gist:1319089
Last active December 28, 2023 22:08
Reading a text file in C++
// Taken from http://www.cplusplus.com/doc/tutorial/files/
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
@stevedoyle
stevedoyle / gist:1319088
Created October 27, 2011 08:47
Writing a text file in C++
// Taken from: http://www.cplusplus.com/doc/tutorial/files/
// writing a text file
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile ("example.txt");
if (myfile.is_open())