Skip to content

fattredd/usepy

Repository files navigation

################
# Useful Funcs #
################
This is a compilation of scripts that I've written/collected
that I've used more than once. Some are just for fun, some
are just plain useful.

Please note that I didn't write all of these scripts.
I mearly assembled them. If you have a problem with
your script being used/want credit, you can always
email me at fattredd@gmail.com

If you have anything to add, you can also email me,
or just send a pull request. Do whatcha gotta do.


**************
** usepy.py ** A bunch of functions that are sometimes useful
**************

randInts()
	prints a series of numbers between 0 and 9 using stdout.
	To stop, press Ctrl+C

spin()
	creates a spinning icon. Useful for indicating loading.
	Should be modified for any real use.

fonetic(pword):
	pword is a string. returns the phonetically spelled out
	version of the string.

colors
	a dictionary containing some of the useful colors that
	stdout can utilize. These are all strings, so you can use
	them like this:
		sys.stdout.write(colors['red']+'This is red '+colors['black']\
			+'This is black')

showColors()
	This prints out all of the colors that stdout can use.
	It shows the effect, as well as the escape character to
	use it. See colors for usage of these strings.

opt(text, key, encrypting=True)
	A one time pad. text is a string that will be en/decrypted.
	key is a list of integers. encrypting is True if encoding,
	false if decoding. Please note that this shouldn't be used
	in production.

cdh(dir)
	Change the working directory relative to /home. This function
	works on Windows (cygwin64) and Linux.
	Shortcuts:
		'.books':'jack/txt/books'
		'.txt':'jack/txt'
		'.jack':'jack'
		'.py':'jack/py'
		'.':''
		'/':'..'
		'':'jack'

analyze(txt [, dict={}])
	Analyze the letter distribution in a text. Returns a dict of
			the used letters in the form; dict[\'letter\']=amount
		txt - The string to be analyzed
		dict - The dictionary to add to. Not required.

disp(dict [, **kwargs])
	Create a graph from a dictionary that associates a key with an amount
		Accepted kwargs:
		color - default 'r'
		width - default 0.25
		ylabel - default 'amount'
		title - default 'Letter Breakdown'

dirAnalyze([dir='.'])
	Analyze all .txt files in a directory

dir2(thing)
	Returns the same as dir(thing), but without the leading
	vars like __class__, __add__, or any other entries with '__'


****************
** shuffle.py ** Analyze the shuffle pattern of a hard shuffle
****************
Usage:
$ python shuffle.py [-h] LANDS INSTANT SORCERY CREATURE PILES TIMES
	Create a deck, then create a shuffled version.
	Use stdout to print both resulting decks

def createDeck(**kwargs):
	Create a deck
	Accepts numbers for the following types of cards:
	-land
	-instant
	-sorcery
	-creature

shuffle(deck, piles=5, times=1, disp=False)
	Hard shuffle your deck
		deck - list of cards
		piles=5 - piles to hard shuffle into
		times=1 - repeat how many times
		disp=False - if True, print result, otherwise return It

joinLists(l)
	Join a list of lists into a single list
		l - a list of lists

ppDeck(deck)
	Use stdout to return the deck, line by line
		deck - a list of cards


*******************
** mandelbrot.py ** Create an image of a Mandelbrot Set
*******************
Usage:
$ python mandelbrot.py
	Generates and saves a Mandelbrot Set as M.bmp


****************
** weather.py ** Use openweathermap.org's API for weather
****************
Usage:
$ python weather.py LOCATION
	Uses stdout to return the following:
		- Temp
			- Current
			- Min
			- Max
		- Sunrise time
		- Sunset time

curWeather(location)
	Returns a custom object the includes the current
	temp, max temp, min temp, sunrise, and sunset
		location - a location (string) in the form of a
			zip code, City,State, or coordinates


***************
** newban.py ** Generate banners from strings, encode 'em,
*************** decode 'em, (un)pickle 'em, and save 'em
Usage:
$ python newban.py newban.py [-h] [--text TEXT] [--filein READFILE]
		[--fileout default=stdout] [--inputType {r,p}]
		[--outputType {r,b,l,p}] [--pprint]
	Generate a banner, pickle/unpickle it, output to a file
	or stdout, do all kinds of other banner-related junk
	optional arguments:
		-h, --help		show this help message and exit
		--text (default source)
		--filein (alternate source)
		--fileout (default=stdout)
		--inputType {r,p}
		--outputType {r,b,l,p}
		--pprint
	r = raw text
	b = banner
	l = list
	p = pickle

horizontal(text)
	return a horizontal banner string
		text - the string to convert

vertical(text)
	return a vertical banner string
		text - the string to convert

pLoad(filename)
	return data from a pickled file
		filename - the name of the file to load from

pBan(data)
	return data from a banner-style list
		data - banner-style list. generated by


bannerToList(banner)
	return a list generated from a banner
	the form is a list of tuples, ('#',2), where the
	'#' is the character, and the 2 is the number of
	consecutive characters
		banner - a banner, generated by vertical() or
			horizontal(), or any other string or
			whatever


****************
** master.py  ** Create a pickle from a banner
** DEPRICATED ** Use newban.py instead
****************
Usage:
$ python master.py READFILE [WRITEFILE]
	Read a banner from READFILE, then output to
	WRITEFILE if assigned. If not, use stdout to
	print the pickled data


****************
** banner.py  ** Create a banner from a string.
** DEPRICATED ** Use newban.py instead
****************
Usage:
$ python banner.py TEXT
	Create a banner of the given TEXT and return it
	with stdout

horizontal(text)
	uses stdout to return a horizontal banner
		text - the string to convert

vertical(text)
	uses stdout to return a vertical banner
		text - the string to convert


*****************
** printBan.py ** Prints a banner from a file generated by master.py
** DEPRICATED  **  Use newban.py instead
*****************
Usage:
$ python printBan.py FILE
	Unpickles FILE, then converts and prints the contained banner

pLoad(filename)
	return data from a pickled file
		filename - the name of the file to load from

pBan(data)
	use stdout to print data from a banner-style list. See banner.py for
	creating one from a string.
		data - a list of tuples in the form 


About

A collection of useful python functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages