Skip to content

Instantly share code, notes, and snippets.

View uttamg911's full-sized avatar
🏠
Working from home

Uttam uttamg911

🏠
Working from home
View GitHub Profile
# imports image module from the PIL libary
from PIL import Image
# opens the favicon as an object to read the pixel values
im = Image.open('Favicons/InNOut.png')
# alphabet string to make the keys of the dictionary
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# gets the frequencies of all the pixel values as an RGB tuple and stores them as a list
# Imports Natual Language Tool Kit
import nltk
# Imports CMU Pronunciation Dictionary from NLTK Corpus
from nltk.corpus import cmudict
# Imports Random
import random
full_dict = cmudict.entries()[:]
#The file python.txt contains the raw html lines that contain the word 'Python' ( scrapped from rwet.decontextualize.com )
#imports the regular expression libraries
import re
file = open("python.txt","r"); #opens the text file in read mode
f = file.read(); #reads the text file into a string
t = re.sub('<[^<]+?>', '', f).replace("Python","Monty Python"); #strips the html code and replaces the word "Python" with "Monty Python"
t = t.replace('e','ing'); #this code replaces all occurrences of "e" with "ing" #Adds more fun when impersonated as a non-native english speaker
print t #prints the lines
# This is a comment in Python
import sys #imports system files
for line in sys.stdin:
line = line.strip() # Strips a string of its trailing white spaces # Tabs tell python that it is part of the loop
word = line.split(' ') # Makes a list of substrings by using space as as delimiter
s = ' '.join(word[::-1]) # [::-1] reverses the contents of a list # The syntax for join is counter intuitive, first you write the delimiter and then the list.
print s # Prints the string
@uttamg911
uttamg911 / translate_to_numbers
Created February 20, 2014 23:22
This unix script translates the letters of a word to numbers a-z or A-Z to 1-26
tr 'A-Z' 'a-z'| tr 'abcdefghi' '123456789' | tr 'j' '10' | tr 'k' '11' | tr 'l' '12' | tr 'm' '13' | tr 'n' '14' | tr 'o' '15' | tr 'p' '16' | tr 'q' '17' | tr 'r' '18' | tr 's' '19' | tr 't' '20' | tr 'u' '21' | tr 'v' '22' | tr 'w' '23' | tr 'x' '24' | tr 'y' '25' | tr 'z' '26'
@uttamg911
uttamg911 / invert_lines.py
Last active August 29, 2015 13:56
This python program reverses the words of a sentence
import sys #imports system files
for line in sys.stdin:
line = line.strip() # Tabs tell python that it is part of the loop
word = line.split(' ')
s = ''
for i in range(1,len(word)+1):
s = s + word[len(word)-i] + ' '
print s
@uttamg911
uttamg911 / index.html
Created November 7, 2012 12:36
Artoo Donuts
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
svg {
@uttamg911
uttamg911 / index.html
Created November 6, 2012 07:34
Superformula test [forked]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Superformula</title>
<script src="http://d3js.org/d3.v2.min.js"></script>
<script src="https://raw.github.com/d3/d3-plugins/master/superformula/superformula.js"></script>
<style>
path {
stroke-width: 1.5px;
}