fgaublog

string.find(s, sub[, start[, end]]) ... und so zeugs ...

 

 

android http post to django server

30. November 2014 01:16:50 | categories: programming, python, android, django

for an android/server gps project, i have need to send some data to a server. in my case a django server. on my android app a HttpPost sends data to http://epydial.pyneo.org/receiver/. The HttpPost is embedded in a AsyncTask. After sucessfully post, a toast message is genereated.

private class PostAsyncTask extends AsyncTask {
        @Override
        protected Double doInBackground(String... params) {
            // TODO Auto-generated method stub
            postData(params[0]);
            return null;
        }

        protected void onPostExecute(Double result){
            Toast.makeText(getApplicationContext(), "successfully logged", Toast.LENGTH_SHORT).show();
        }

        @SuppressWarnings("unused")
        public void postData(String valueIWantToSend) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://epydial.pyneo.org/receiver/");
            try {
                // create a list to store HTTP variables and their values
                List nameValuePairs = new ArrayList();
                // add an HTTP variable and value pair
                nameValuePairs.add(new BasicNameValuePair("myHttpData", valueIWantToSend));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                // send the variable and value, in other words post, to the URL
                HttpResponse response = httpclient.execute(httppost);
            } catch (ClientProtocolException e) {
                // process exception
            } catch (IOException e) {
                // process exception
            }
        }
    }

the receiver method on my django server:

@csrf_exempt
def receiver(request):
    if request.method == 'POST':
        with open('/var/www/qblog/static/xml/test.xml', 'w') as f:
            f.write(request.POST.get('myHttpData'))
            f.close()
further information about the @csrf_exempt decorator you can find here. the rest of the receiver method is self-explanatory. all my data, in that case longitude and latitude are saved in the myHttpData array and are writing to a xml file for more web processing.


autumn 2014 in berlin

8. November 2014 20:13:28 | categories: other

this image is composed of 2 photos, and showing the gartenstrasse in northerly and southerly direction. and it is not the berlin wall.


guitar hero

12. Juli 2014 01:05:18 | categories: music

zakk wylde from black label society presented new songs from the new album 'Catacombs Of The Black Vatican' in berlin 'huxleys neue welt' on july 1st. the show and the sound was impressive. the berlin chapter says thank you for a great show!


adminer - alternative to phpmyadmin

29. Juni 2014 22:45:34 | categories: databases

more security, more performance, better interface, which promises the database management tool adminer. the single php script can handle mysql, postgresql, sqlite, ms sql, mongodb and other. i have tested the functionality, and it does what it promise. a cool tool!


python and the facebook api

12. Juni 2014 20:35:22 | categories: programming, python

to run this example, you need at first a facebook app. this video shows the simple setup. pick the App ID and App Secret from there and insert it in the python code below.

the program returns all comments from a single facebook post. you can limited the request and you can change the facebook post ID. the graph api explorer is the perfect starting point to learn more about the fb api.

the last part is for error handling and simple json parsing to get all the interesting information.

#!/usr/bin/env python          
# -*- coding: utf-8 -*-

from json import loads         
from urllib2 import Request, urlopen, URLError, HTTPError

APPID = "XXXXXXXXXXXXXXXXXX"   
APPSECRET = "XXXXXXXXXXXXXX"   
FBPOSTID = "588013424601016"   
LIMIT = 3000
GRAPH_URL = "https://graph.facebook.com/%s/comments?access_token=%s|%s&limit=%d" % (
                FBPOSTID,      
                APPID,
                APPSECRET,     
                LIMIT)         
try:
    response = urlopen(GRAPH_URL)

except HTTPError as e:         
    print 'The server couldn\'t fulfill the request.'
    print 'Error code: ', e.code    

except URLError as e:
    print 'We failed to reach a server.'
    print 'Reason: ', e.reason 

else:
    decoded = loads(response.read())
    for item in decoded['data']:
        print '%s,%s,%s' % (
            item['created_time'],
            item['from']['name'],
            item['message'])

what a night

11. Juni 2014 10:45:23 | categories: music


here we go!

4. Juni 2014 17:59:10 | categories: music


a simple d-bus daemon implemented with c

4. Juni 2014 12:50:31 | categories: c, programming

first of all, you need a d-bus config file for the daemon. on a standard debian system it is saved in /etc/dbus-1/system.d/ as cneod.conf .

and here you can find the daemon code. what can you do with the compiled code? with the d-bus rules above, you are able to:

  • shutdown
  • suspend
  • reboot
  • setbrightness
  • getbrightness

your system without root access. if you have a closer look to the code, you will see, the program is intended for my openmoko GTA02 and for my laptop/netbook. example d-bus calls and the gcc command are inline from cneod.c now its time to build your own system daemons. more about the architecture behind the d-bus concept you can find here.


initial commit

29. April 2014 12:55:09 | categories: other