Skip to content

Instantly share code, notes, and snippets.

View rdegges's full-sized avatar

Randall Degges rdegges

View GitHub Profile
@rdegges
rdegges / views.py
Created January 3, 2011 06:18
A simple example of a django-tropo view.
from tropo import Tropo
from djtropo import tropo_view
@tropo_view
def ivrintro(request):
"""Say hello world and hangup."""
t = Tropo()
t.say('hello, world!')
@rdegges
rdegges / my-first-php-page.php
Created November 23, 2010 17:10
My first PHP page :)
<html>
<head>
<title>My Test PHP Page!</title>
</head>
<body>
<?php echo "<p>My first dynamic website!</p>"; ?>
</body>
</html>
/*
* test.c
*
* This example program demonstrates a weird way to reference array elements in
* C. All credit goes to the Stack Overflow 'Strangest language feature'
* discussion page:
* http://stackoverflow.com/questions/1995113/strangest-language-feature
*/
#include <stdio.h>
##
# This gist is an update of the tropo python scripting tutorial page. It contains some
# suggested changes that would make the tutorial more familiar to native python
# developers.
#
# The tropo python scripting tutorial can be found at:
# https://www.tropo.com/docs/scripting/t_tutorial-python.htm
#
# NOTE: All changes I've proposed here are very simple (just removing parenthesis
# from if statements, mostly). All examples work well. The python style guide
from sys import exit
from lxml import etree
response = 'some xml response here'
try:
doc = etree.XML(response.strip())
code = doc.findtext('code')
print code
except etree.XMLSyntaxError:
from lxml import etree
response = 'some xml response here'
try:
doc = etree.XML(response.strip())
code = doc.findtext('code')
print code
except etree.XMLSyntaxError:
print 'XML parsing error.'
<?xml version="1.0" encoding="utf-8"?>
<response version="1.0">
<code>400</code>
<errors>
<error>This API call requires a HTTP POST.</error>
</errors>
</response>
<?xml version="1.0" encoding="utf-8"?>
<response version="1.0">
<code>200</code>
<id>50</id>
</response>
from myapp.models import Server
from myapp.models import ServerForm
from django.template import RequestContext
from django.shortcuts import render_to_response
def create_server(request):
"""
Create a new Server model.
"""
from django.db import models
from django.forms import ModelForm
class Server(models.Model):
"""
This class represents a physical server.
"""
hostname = models.CharField('Server Name',
help_text = 'Hostname of the server.',
max_length = 50