Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Awad benawad

View GitHub Profile
@benawad
benawad / gray.py
Last active Aug 29, 2015
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 / setup.py
Created Oct 26, 2014
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',
@benawad
benawad / setup.py
Last active Aug 29, 2015
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 / color.py
Created Oct 26, 2014
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 / euler25.py
Created Oct 31, 2014
Euler problem 25
View euler25.py
f1 = 1
f2 = 1
term = 2
while True:
temp = f1
f1 = f2
f2 = temp + f2
term += 1
if(len(str(f2)) == 1000):
print term , " : " , f2
@benawad
benawad / parser_test.py
Created Oct 31, 2014
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():
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 / euler24.py
Created Oct 31, 2014
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]