Skip to content

Instantly share code, notes, and snippets.

View guilhermecarvalhocarneiro's full-sized avatar

Guilherme de Carvalho Carneiro guilhermecarvalhocarneiro

  • Palmas, Tocantins, Brasil
View GitHub Profile
package base;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@Override
protected String doInBackground(City... params) {
// TODO Auto-generated method stub
String nameCity, idCity;
nameCity = "Palmas";
idCity = null;
try {
JSONParser jsonParser = new JSONParser();
String url = "http://mobile.nuvolscloud.com.br/cidade/api/cidade/1/?format=json";
JSONObject json = jsonParser.getJSONFromUrl(url);
@guilhermecarvalhocarneiro
guilhermecarvalhocarneiro / gist:9097083
Created February 19, 2014 17:35
Redirecionar conforme limite do usuário
def get_form(self, request, obj=None, **kwargs):
form = super(EstabelecimentoAdmin, self).get_form(request, obj, **kwargs)
import pdb
pdb.set_trace()
try:
if not request.user.is_superuser:
if Usuario(user=request.user).get_limit() >= self.model.objects.filter(user=request.user).count() and obj == None:
return render_to_response('limit_places.html', {'app_label': 'Limite atingido'})
form.base_fields['cidade'].queryset = Usuario(user=request.user).get_city()
except Exception, e:
{
public class Estado
{
public int id { get; set; }
public string nome { get; set; }
public string uf { get; set; }
}
public class City
{
@guilhermecarvalhocarneiro
guilhermecarvalhocarneiro / gist:9189531
Created February 24, 2014 14:41
Evento Async para pegar as coordenadas atual do usuário
private async void StartGeoLocation()
{
try
{
City city = new City();
if (city.GetCurrencyCity() == null)
{
//TODO Preciso verificar o load da localizacao
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
@guilhermecarvalhocarneiro
guilhermecarvalhocarneiro / gist:9207435
Created February 25, 2014 11:45
Chamando método Async no OnNavegatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
LoadCity();
await StartGeoLocation();
base.OnNavigatedTo(e);
}
private async Task StartGeoLocation()
{
try
@guilhermecarvalhocarneiro
guilhermecarvalhocarneiro / gist:9401632
Created March 6, 2014 23:02
Chamando MapsDirectionTask
private void Address_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
try
{
MapsDirectionsTask mapsDirectionsTask = new MapsDirectionsTask();
GeoCoordinate CoordenadaFinal = new GeoCoordinate(LatItem, LngItem);
LabeledMapLocation EndPoint = new LabeledMapLocation(PanoramaDetailItem.Title.ToString(), CoordenadaFinal);
mapsDirectionsTask.End = EndPoint;
JSONObject jsonobj; // declared locally so that it destroys after serving its purpose
jsonobj = new JSONObject();
JSONObject header = new JSONObject();
jsonobj.put("nome", "Guilherme");
jsonobj.put("pais", "Brasil");
jsonobj.put("chave", regIdGCMService.toString());
jsonobj.put("Authorization", "Token 0d0c898a1c26235f25f256ed853c9a09f3dce8bd");
DefaultHttpClient httpclient = new DefaultHttpClient();
def send_message(self):
json_data ={"collapse_key":"msg","data":{"data":"xyz",},"registration_ids":['APA91bH2DtFn9494z-*****bMP1BPUsVI8ltb395MNp-39k8sp0',],}
url ='https://android.googleapis.com/gcm/send'
myKey ="AIzaSyC********************A7S"
data = json.dumps(json_data)
headers ={'Content-Type':'application/json','Authorization':'key=%s'% myKey}
req = urllib2.Request(url, data, headers)
f = urllib2.urlopen(req)
response = json.loads(f.read())
@guilhermecarvalhocarneiro
guilhermecarvalhocarneiro / gist:9506197
Created March 12, 2014 12:44
HttpPost Android para API DjangoRestFramework
JSONObject jsonobject = new JSONObject();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://*******/apirestfull/******/");
httppost.setHeader("Content-Type","application/json");
httppost.setHeader("Authentication", "Token 0d0c898a*****e8bd");
jsonobject.put("nome", "Guilherme");
jsonobject.put("pais", "Brasil");
jsonobject.put("chave", Key);