Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Created January 25, 2017 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsfmc/a366245d832780cfcd861f3ebe923243 to your computer and use it in GitHub Desktop.
Save nsfmc/a366245d832780cfcd861f3ebe923243 to your computer and use it in GitHub Desktop.
returns the most common padding/margin values

assuming you got a list of margin/padding values from your css with

ack --css margin > margin.txt
ack --css padding > padding.txt

you can run

python scan.py

and get a list of the most popular padding and margin values

import os
import sys
import re
from collections import defaultdict, Counter
val_re = re.compile('(\d+(?:px|em|%)?|auto)')
def count_vals(filename):
with open(filename) as f:
db = defaultdict(int)
for line in f:
valstring = line.split(':')[-1].strip()
vals = re.findall(val_re, valstring)
for val in vals:
db[val] += 1
return Counter(db)
def main():
filenames = ['padding.txt', 'margin.txt']
for filename in filenames:
count = count_vals(filename)
print filename
print count.most_common(15)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment