Skip to content

Instantly share code, notes, and snippets.

View benawad's full-sized avatar

Ben Awad benawad

View GitHub Profile
@benawad
benawad / gray.py
Last active August 29, 2015 14:08
Command line script that takes a path to an image, grayscales image, and then saves the picture in the directory the original image was found in.
View gray.py
from PIL import Image
import os, shutil
print "Please enter location of image"
input = raw_input('> ')
path = os.path.abspath(input)
img = Image.open(path)
@benawad
benawad / color.py
Created October 26, 2014 17:03
simple script to make into a .exe
View color.py
favorite_color = raw_input('What\'s your favorite color? ')
print "%s is my cousins favorite color too!" % favorite_color
raw_input()
@benawad
benawad / setup.py
Last active August 29, 2015 14:08
sample setup.py file for turning a color.py script into a .exe
View setup.py
from setuptools import setup
import py2exe
setup(console=['color.py'])
@benawad
benawad / setup.py
Created October 26, 2014 17:49
setup.py script for a greyscale project
View setup.py
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import py2exe
config = {
'description': 'Turn any image to grayscale',
'author': 'Ben Awad',
'url': 'benawad.com',
View lexicon.py
def convert_numbers(s):
try:
return int(s)
except ValueError:
return None
def scan(sentence):
words = sentence.split()
sentence = []
for word in words:
@benawad
benawad / sample_sentence.py
Created October 31, 2014 16:35
small snippet
View sample_sentence.py
"north south east"
@benawad
benawad / parser_test.py
Created October 31, 2014 16:54
Test file for chapter 49 of Learning Python The Hard Way
View parser_test.py
from nose.tools import *
from ex48 import parser
def test_sentence():
s1 = parser.Sentence(('noun', 'bear'), ('verb', 'kill'), ('direction', 'north'))
assert_equal(s1.subject, 'bear')
assert_equal(s1.verb, 'kill')
assert_equal(s1.object, 'north')
def test_peek():
@benawad
benawad / euler22.py
Created October 31, 2014 17:31
Solution for problem 22 of Project Euler
View euler22.py
alphabet = {'"':0,'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8,'I':9,'J':10,'K':11,'L':12,'M':13,'N':14,'O':15,'P':16,'Q':17,'R':18,'S':19,'T':20,'U':21,'V':22,'W':23,'X':24,'Y':25,'Z':26}
def name_value(name, pos):
sum = 0
for letter in name:
sum += alphabet[letter]
return sum * pos
names_file = open("names.txt")
names = names_file.readlines()
@benawad
benawad / euler24.py
Created October 31, 2014 17:48
Euler problem 24
View euler24.py
import itertools
nums = [0,1,2,3,4,5,6,7,8,9]
perm = list(itertools.permutations(nums))
print perm[999999]
View euler24_one_line.py
import itertools
print list(itertools.permutations([0,1,2,3,4,5,6,7,8,9]))[999999]