Skip to content

Instantly share code, notes, and snippets.

Avatar

gundotio Gunio

View GitHub Profile
View gist:1536565
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster@example.com
WSGIScriptAlias /cal /srv/http/caldav-to-gtasks/server.py
<Directory /srv/http/caldav-to-gtasks/>
AuthType Basic
AuthName "WSGI"
@Gunio
Gunio / Simple Django URLs
Created Oct 18, 2011
Simple Django URLs
View Simple Django URLs
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^(?P<input>[^/]+)$', 'UppercaseMaker.upper.views.home'),
)
@Gunio
Gunio / Simple Django Template
Created Oct 18, 2011
Simple Django Template
View Simple Django Template
<html>
<head><title>{{output}}</title></head>
<body>
Your output is: {{output}}.
</body>
</html>
@Gunio
Gunio / Django Relative Template Directory
Created Oct 18, 2011
Django Relative Template Directory
View Django Relative Template Directory
import os
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
@Gunio
Gunio / Simple Django View Response
Created Oct 18, 2011
Simple Django View Response
View Simple Django View Response
from django.shortcuts import render_to_response
def home(request, input="No input supplied"):
output = input.upper()
return render_to_response('home.html', {'output': output})
@Gunio
Gunio / gist:1296354
Created Oct 18, 2011
Django Installed Apps
View gist:1296354
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
@Gunio
Gunio / Parsing HTML in Python
Created Oct 18, 2011
Parsing HTML in Python with LXML
View Parsing HTML in Python
import requests
import lxml
from lxml import html
r = requests.get('http://gun.io')
tree = lxml.html.fromstring(r.content)
elements = tree.get_element_by_id('frontsubtext')
for el in elements:
print el.text_content()
@Gunio
Gunio / Parsing JSON in python
Created Oct 18, 2011
Parsing JSON in python
View Parsing JSON in python
import requests
import simplejson
r = requests.get('https://github.com/timeline.json')
c = r.content
j = simplejson.loads(c)
for item in j:
print item['repository']['name']
@Gunio
Gunio / POSTing using Python Requests
Created Oct 18, 2011
POSTing using Python Requests
View POSTing using Python Requests
import requests
url = 'https://testexample.com/form'
data={'title': 'RoboCop', 'description': 'The best movie ever.'}
r = requests.post(url, data=data)
print r
@Gunio
Gunio / GET using Requests And Authentication
Created Oct 18, 2011
GET using Requests And Authentication
View GET using Requests And Authentication
import requests
r = requests.get('https://api.github.com', auth=('YOURUSERNAME', 'PASSWORD'))
print r