Skip to content

Instantly share code, notes, and snippets.

View Gunio's full-sized avatar

gundotio Gunio

View GitHub Profile
@Gunio
Gunio / gist:1536565
Created December 29, 2011 22:52
Siri CalDAV
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin [email protected]
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 October 18, 2011 20:02
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 October 18, 2011 19:30
Simple Django Template
<html>
<head><title>{{output}}</title></head>
<body>
Your output is: {{output}}.
</body>
</html>
@Gunio
Gunio / Django Relative Template Directory
Created October 18, 2011 19:25
Django Relative Template Directory
import os
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
@Gunio
Gunio / Simple Django View Response
Created October 18, 2011 19:11
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 October 18, 2011 19:02
Django Installed Apps
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 October 18, 2011 18:33
Parsing HTML in Python with LXML
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 October 18, 2011 05:25
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 October 18, 2011 05:14
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 October 18, 2011 04:52
GET using Requests And Authentication
import requests
r = requests.get('https://api.github.com', auth=('YOURUSERNAME', 'PASSWORD'))
print r