Skip to content

Instantly share code, notes, and snippets.

@insanity54
Last active July 4, 2017 02:58
Show Gist options
  • Save insanity54/f78d44ae64e46b02e57e6ac061d91231 to your computer and use it in GitHub Desktop.
Save insanity54/f78d44ae64e46b02e57e6ac061d91231 to your computer and use it in GitHub Desktop.
ascii-truncator.py
, ,_
|`\ `;;, ,;;'
| `\ \ '. .'.'
| `\ \ '-""""-' /
`. `\ / |`
`> /; _ _ \
/ / | . ;
< (`";\ () ~~~ (/_
';;\ `, __ _.-'` )
>;\ ` _.'
`;;\ \-'
;/ \ _
| ,"". .` \
| _| ' /
; /") .;-,
\ / __ .-'
\,_/-"` `-'
, ,_
|`\ `;;, ,;;'
| `\ \ '. .'.'
| `\ \ '-""""-' /
`. `\ / |`
`> /; _ _ \
/ / | . ;
< (`";\ () ~~~ (/_
';;\ `, __ _.-'` )
>;\ ` _.'
`;;\ \-'
;/ \ _
| ,"". .` \
| _| ' /
; /") .;-,
\ / __ .-'
\,_/-"` `-'
#!/usr/bin/env python
import sys
def getMinLineIndent(line):
count = 0
for col in line:
count += 1
if col != ' ':
return count
def removeBlankLines(lines):
newLines = []
for line in lines:
goodLine = False
for col in line.rstrip():
if col != ' ':
# if all columns are spaces, this line will be ignored
goodLine = True
if goodLine:
newLines.append(line)
return newLines
def getMinIndent(lines):
indents = []
for line in lines:
indents.append(getMinLineIndent(line))
return min(indents)-1
def process(f):
f = removeBlankLines(f)
wc = getMinIndent(f)
#print "whitespace count is {0}".format(wc)
for line in f:
print line.rstrip()[wc:]
if not sys.argv[1:]:
print "USAGE: ./truncate.py ./pika.txt"
exit(2)
ifile = open(sys.argv[1], 'r')
process(ifile.readlines())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment