Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Awad benawad

View GitHub Profile
@benawad
benawad / euler22.py
Created Oct 31, 2014
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()
View forms.py
from django import forms
class UploadForm(forms.Form):
image = forms.ImageField();
View settings.py
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
View urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^$', 'converters.views.index', name='index'),
url(r'^admin/', include(admin.site.urls)),
)
View upload.html
<h1>Hello, upload a file and I will turn it grey</h1>
<form method="POST" action="" enctype="multipart/form-data">
{{ form.as_p }}
<input type='submit' value='Upload'/>
</form>
View views.py
from django.shortcuts import render
from django.http import HttpResponse
from PIL import Image
from converters.forms import UploadForm
def index(request):
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
grey(request.FILES['image'])
@benawad
benawad / settings.py
Created Nov 8, 2014
Installed apps django project
View settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'converters',
)
View n_degree_pi.py
import math
print "Enter a number and I will print out that many decimal places of PI."
places = int(raw_input('>'))
print str(math.pi)[:places+2]
View n_degree_pi_mathmatically.py
from __future__ import division
from decimal import *
print "Enter a number and I will print out that many decimal places of PI."
places = int(raw_input('>'))
getcontext().prec = places
pi = 0
View n_degree_e.py
import math
print "Enter a number and I will print that many decimal places of e"
places = int(raw_input('>'))
print str(math.e)[:places+2]