Skip to content

Instantly share code, notes, and snippets.

View santiagobasulto's full-sized avatar

Santiago Basulto santiagobasulto

View GitHub Profile
@santiagobasulto
santiagobasulto / gist:3056999
Created July 5, 2012 23:05
Mocking private methods in python
""" This is a simple gist to show how to mock
private methods. I've got lots of questions
regarding this topic. Most people seems confused.
Hope it helps.
"""
import unittest
import mock
@santiagobasulto
santiagobasulto / gist:3062809
Created July 6, 2012 21:21
Bash completion for GIT
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
[ { "distance" : 1609.3440000000001,
"time" : 466.0
},
{ "distance" : 1609.3440000000001,
"time" : 420.0
},
{ "distance" : 1609.3440000000001,
"time" : 421.0
},
{ "distance" : 1609.3440000000001,
@santiagobasulto
santiagobasulto / gist:3151147
Created July 20, 2012 14:53
Uploading a picture to our API
package com.athlete.com.api.clients.api_java_client;
import java.io.File;
import java.io.IOException;
//http://developer.android.com/reference/org/apache/http/HttpEntity.html
import org.apache.http.HttpEntity;
// New headers
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
@santiagobasulto
santiagobasulto / gist:3251381
Created August 3, 2012 20:49
Django DRY context managers
"""
You find yourself doing this all the time?
>>> car = Car.objects.get(id=1)
>>> if c.user != request.user:
>>> return HttpResponse("This car doesn't belong to you")
>>> c.brand = request.POST.get('brand_name')
>>> c.save()
Better to turn it into:
santiago@santiago-desktop:~$
>> curl -XGET -vv http://www.ole.com.ar > /dev/null
* About to connect() to www.ole.com.ar port 80 (#0)
* Trying 200.42.93.137... % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0connected
* Connected to www.ole.com.ar (200.42.93.137) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
[
{
"lat":37.1571709,
"lng":-113.634999,
"elev":901.197369863,
"time":"2012-07-05T17:00:00Z"
},
{
"lat":37.1571478,
"lng":-113.6349291,
======================================================================
ERROR: test_post_a_workout_from_GPX (athlete.test.api.resources.workouts.TestWorkoutCreation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/santiago/code/python/athlete/athlete/src/athlete/test/api/resources/workouts.py", line 143, in test_post_a_workout_from_GPX
response = self.workout_resource.dispatch_list(request)
File "/home/santiago/.virtualenvs/athlete.com/src/django-tastypie/tastypie/resources.py", line 407, in dispatch_list
return self.dispatch('list', request, **kwargs)
File "/home/santiago/.virtualenvs/athlete.com/src/django-tastypie/tastypie/resources.py", line 436, in dispatch
response = method(request, **kwargs)
Running migrations for routes:
- Migrating forwards to 0015_auto__chg_field_route_distance_in_meters.
> routes:0010_auto__unify_route_data
> routes:0011_unify_route_data
- Migration 'routes:0011_unify_route_data' is marked for no-dry-run.
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had
! to leave it in an interim state between migrations.
@santiagobasulto
santiagobasulto / gist:3524233
Created August 30, 2012 08:35
GPX sample with pauses
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="Exported from Strava"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
<link href="http://cosmocatalano.com/strava/export">
<text>Strava GPX Exporter - Version 2</text>