Skip to content

Instantly share code, notes, and snippets.

@solomon081
solomon081 / hangingindent.py
Created April 2, 2012 03:15
Hanging Indent
import textwrap
stext = input("Enter your text: ")
dedented = textwrap.dedent(stext).strip()
cwidth = input("Enter your column width: ")
try:
cwidth = int(cwidth)
except:
print("Invalid width")
exit()
print(textwrap.fill(dedented,
import re
tex = input("Enter your text: ")
patt = input("Enter what you would like to match it to: ")
match = re.search(patt, tex)
if match == None:
print("No Match")
else:
start = int(match.start()) + 1
end = int(match.end()) + 1
if start == end:
@solomon081
solomon081 / listfiles.rb
Created April 2, 2012 22:40
Print Files
puts "Drag this file to your preferred directory"
print("Press ENTER")
gets
list = `ls`.split
puts "Files and Folders"
puts "-----------------"
puts "\n"
list.each {|x| puts x}
@solomon081
solomon081 / re_match_multiple.py
Created April 3, 2012 02:45
ReMatch Multiple
import re
text = input("Enter your text: ")
pattern = input("Enter your pattern: ")
for match in re.finditer(pattern, text):
s = match.start()
e = match.end()
print("Found: ", pattern, "at:", s, "-", e)
import re
text = input("Enter your text: ")
pattern = input("Enter your pattern: ")
for match in re.finditer(pattern, text):
s = match.start()
e = match.end()
print("Found: ", pattern, "at:", s, "-", e)
@solomon081
solomon081 / diff.py
Created April 4, 2012 03:20
Differences
import difflib
import os
text1 = input("Enter text: \n")
os.system('clear')
text2 = input("Enter a second text: \n")
os.system('clear')
print("Differences Below:")
print("------------------")
text1 = text1.splitlines()
text2 = text2.splitlines()
@solomon081
solomon081 / diff2.py
Created April 4, 2012 21:13
Differences 2
from difflib import unified_diff
from os import system
system('clear')
text1 = input("Enter your text: ")
text2 = input("Enter a second text: ")
text1 = text1.splitlines()
text2 = text2.splitlines()
diff = unified_diff(text1, text2, lineterm='')
print('\n'.join(diff))
@solomon081
solomon081 / flit.py
Created April 5, 2012 23:49
Find Letter In Text
import collections
fORt = input("Would you like to open a file or enter your own text?(file/text)\\
n")
if fORt == 'text':
import collections
buffer = ''
print("Enter in your text below")
while True:
line = input()
if not line: break
@solomon081
solomon081 / cli.rb
Created April 6, 2012 14:43
Ruby CLI
while true
print(">>> ")
command = gets
`#{command}`
end
class Matcher
include Enumerable
def initialize(string, match)
@string = string
@match = match
end
def each
@string.scan(/[#@match]/) do |pattern|
yield pattern