Skip to content

Instantly share code, notes, and snippets.

View benawad's full-sized avatar

Ben Awad benawad

View GitHub Profile
@benawad
benawad / euler25.py
Created October 31, 2014 18:03
Euler problem 25
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 / settings.py
Created November 8, 2014 03:15
Installed apps django project
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'converters',
)
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)),
)
from django import forms
class UploadForm(forms.Form):
image = forms.ImageField();
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'])
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
<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>
@benawad
benawad / n_degree_pi.py
Created November 14, 2014 14:51
Solution #1
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]
@benawad
benawad / n_degree_e.py
Created November 14, 2014 15:22
solution#2
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]
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