Skip to content

Instantly share code, notes, and snippets.

View lerrua's full-sized avatar

Igor Leroy lerrua

  • Brazil
  • 01:00 (UTC -03:00)
View GitHub Profile
import urllib2
site = Site.objects.get_current()
absolute_url = 'http://%s%s' % (site.domain,
instance.get_absolute_url())
asolute_url = urllib2.quote(absolute_url, safe='')
vamu_api = 'http://va.mu/api/create/?url=%s' % (absolute_url)
short_url = urllib2.urlopen(vamu_api).read()
def latest_post(request, blog_slug):
blog = get_object_or_404(Blog, slug=blog_slug)
try:
latest = blog.posts.latest('pub_date')
except
q = model.objects.all().order_by('-'+date_field)
if kwargs:
q = q.filter(**kwargs)
/* ABAS DE PROGRAMAÇÃO */
(function(){
var tabContainers = $('div.tabs > div > div');
$('div.tabs ul.tabNavigation a').click(function () {
tabContainers.hide().filter(this.hash).show();
$('div.tabs ul.tabNavigation a').removeClass('active');
$(this).addClass('active');
return false;
}).filter(':first').click();
})();
@lerrua
lerrua / weather.py
Created April 6, 2011 18:10
Playing with python-weather-api
# -*- coding: utf-8 -*-
import pickle
import pywapi
import string
import pprint
pp = pprint.PrettyPrinter(indent=4)
forecasts = ['BRXX3706', 'BRXX0104', 'BRXX2863', 'BRXX1936', 'BRXX0079', 'BRXX0063', 'BRXX0137', 'BRXX0151', 'BRXX1865']
@lerrua
lerrua / weather.py
Last active September 25, 2015 10:07
# Yahoo Weather Solution with RSS
# http://developer.yahoo.com/weather/
# http://weather.yahoo.com/
import requests
url = "http://weather.yahooapis.com/forecastrss?w=26804118&u=c"
response = requests.get(url)
print response.content
<h1>{{ poll.question }}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form action="/polls/{{ poll.id }}/vote/" method="post">
{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from agenda_test.polls.models import Choice, Poll
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('poll_list.html', {'latest_poll_list': latest_poll_list})
def detail(request, poll_id):
@lerrua
lerrua / person.rb
Created March 2, 2011 04:15
Model com comentários gerados com seus atributos pela gem annotate
# == Schema Information
#
# Table name: people
#
# id :integer not null, primary key
# user_id :integer
# profile_id :integer
# full_name :string(255)
# birth_date :date
# created_at :datetime
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Documentos Subscritos ao iTunes</title>
<dateCreated>Tue, 11 May 2010 00:01:55 GMT</dateCreated>
<dateModified>Tue, 11 May 2010 00:01:55 GMT</dateModified>
</head>
<body>
<outline text="RailsLab : Scaling Rails" type="rss" xmlUrl="http://feeds.feedburner.com/Scaling-Rails" htmlUrl="/category/scaling-rails.rss" />
<outline text="Ruby on Rails Podcast" type="rss" xmlUrl="http://feeds.feedburner.com/rubyonrailspodcast" htmlUrl="http://podcast.rubyonrails.org" />