abidibo.net

Weblog

Android development, fetch data from API and execute a callback

android java programming

I love first-class function programming languages (js and python for example), and I use to pass callbacks everywhere, especially when dealing with events or async tasks.

I'm a completely newbie with Java, but I started learning it because I decided time has come to develop android native applications. One of the first functionality I needed and I wanted to master is retrieving information (in json format, in my case) from some sort of API in order to display it in my application.

The equivalent in a modern js application would be making an ajax call to a server endpoint and process the data when fetched. This of course involves the use of callbacks, since data are fetched asynchronously and must ...

read the full post


U8 SmartWatch Voice Commands

android smartwatch tasker u8

Hi everybody!

It turns out that our astonishing watch can perform voice commands to the phone.
And that's good news! You can perform as Michael Knight and women will tear their air to be at your side.

I thought about this possibility long time ago' but foolishly I supposed that there was no way to stream my fucking voice from the watch to the phone (except during a phone call), now I've discovered I was wrong.

When the watch is ...

read the full post


Show google analytics statistics in django admin

django django-admin

In this post we'll see how to show google analytics statistics inside your admin index. If you use django-suit as your admin application then you could simply install django-otto-admin and follow the provided instructions to get it working.

Requirements

First of all we need to create a google developer project and a service account which will allow us to authenticate to the google analytics account.

Follow the steps in the Google Identity Platform documentation to create a service account from the Google Developer Console.

Once the service account is created, you can click the Generate New JSON Key button to create and download the key and add it to your project. Place the json file in a secure place, not ...

read the full post


Modal django forms with bootstrap 4

bootstrap django modals

Some time ago' I wrote an article about how to implement django forms with bootstrap 3 modals. It turned out to be a quite interesting theme since many people surfed and read that page. So now I'll refresh these concepts changing them a bit, in fact we'll see how to implement django forms with bootstrap 4-alpha modals.

Aperitif

Some preliminary stuff.

I'm almost bored with overwriting the model form class of my generic view in order to add bootstrap classes to form fields, so I'll use django-widget-tweaks. Let's install it:

(.virtualenv)$ pip install django-widget-tweaks 

Add widget_tweaks to your installed apps ...

read the full post


ng-upload-window

angularjs

Yeppa! Today I registered my first bower package, ng-upload-window, an angularjs directive wrapped around Danial Farid's ng-file-upload upload service, which organizes uploads inside a layer window which remembers the google drive upload window.

$ bower install ng-upload-window

You can find all relevant information and installation instructions in the github project page.

In a nutshell:

  • all the uploads are stacked in a fixed positioned layer window
  • for each upload information are shown: file name, file size,  progress bar, the downloading remaining time and the status of the upload.
  • uploads can be cancelled
  • the window can be iconized
  • the window can be closed when there are no more running uploads, or it's automatically closed after 8 seconds.

This directive wraps only the ...

read the full post


How to send short text messages from your U8 smartwatch

android smartwatch tasker u8

With this entry I should gain a mention from U8 boss, whoever he is.

It's a shame that the wrist dialer can transmit to the phone only ~ 40 numbers, otherwise all this stuff could be even more cool. But first things first...

Some one told you that your cheap and stupid smartwatch can't send text messages?

Well, he was wrong! At least a bit wrong. Actually you can send very short text messages from your wrist and here I'll tell ...

read the full post


U8 smartwatch - Calculator App - Proof of Concept

android smartwatch tasker u8

This is a proof of concept of how we can develop a simple calculator app (basic operations over two numbers) for the U8 smartwatch taking advantage from the tasker+notification method described in my prevoius post. Read the "How to get the best of your U8 smartwatch" entry before going on if you've not done it yet.

Your Smartwatch Loves Tasker!

Since the whole post series about U8 smartwatch and tasker had a good following, I decided to ...

read the full post


Serve private media with angular, DRF, CORS and token authentication

angularjs django drf rest

A long time has passed since my last post, I was fighting hard with a project learning django REST framework and angularjs, and now time has come to share some interesting knowledges.

This entry talks about serving private media from a django REST webservice, developed with django REST framework, to angularjs, in a scenario which uses a token authentication schema and CORS requests.

The problems to face

Let's see the problems we have to deal with.

  • Media with django are normally served directly by the web server, so they are out of the authentication/permission logic of the application
  • The token authentication schema needs every request to contain an header 'Authentication' part providing the token key (also when requesting files ...

read the full post


Decorators with Python

decorator patterns python

Decorators in python can be quite easy to use and understand, but flexible decorators using the new syntax introduced by python 2.4 can be a bit more complex.

Here I'll try to explain (especially to myself) the world of decorators in python, starting from simple cases and ending with complex ones. Ideas and notions taken from the Pro Django book by Marty Alchin.

Decorators without extra arguments

Let's create a simple cache decorator you can use to store complex operations:

>>> def cache(func):
...   cache_dict = {}
...   def wrapper(*args, **kwargs):
...     key = '%s-%s' % (repr(args), repr(kwargs))
...     if key not in cache_dict:
...       cache_dict[key] = func(*args, **kwargs)
...       print 'cached'
...     return cache_dict[key]
...   return wrapper

A simple decorator function takes ...

read the full post


Python's excess arguments

programming python

What I've always really appreciated of python is the ability to give a function an arbitrary number of positional and keyword arguments, something that in PHP is not possible and is indeed very powerful.

When declaring a function, we can define 4 different types of arguments:

  • required arguments
  • optional arguments (a default is provided)
  • excess positional arguments
  • excess keyword arguments

for example:

def myfunc(a, b=3, *c, **d)
  • a is a required argument
  • b is an optional one since it's default value it's 3
  • the single asterisk before the c argument allows the function to accept any number of positional arguments
  • the two asterisks before the d argument allow the function to support arbitrary kewyword arguments

The order of ...

read the full post


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured