code snippets

Forget Gmail filters, let Google sort your inbox using Machine Learning algorithms

Among the multitude of programming APIs provided by Google lies a jewel called Prediction API. It has a high-quality classifier that allows for continuous learning with model updates.

Let's quickly use it to automatically sort incoming mail into your existing labels. The most tedious part is configuration:

Configuration

  1. Create a new Blank Project in Google Apps Script and enable Prediction API in the Resources/Advanced Google services… menu.
  2. Sign up for the Google Developers Console and take the 300$ free credit. Then, create your first Developers Console project and enable Prediction API in its API & auth section.
  3. Switch back to your newly created Google Apps Script and link it with your new Developers Console project through the Resources/Developers Console Project menu.

We are done configuring. Now, there are only two functions to implement: one to train the model and the other to classify incoming mail.

Train

The function GmailApp.getUserLabels() ❶ gets all labels that you defined in Gmail and disregards standard labels such as Inbox, All Mail or Spam. Mails in Gmail are organized by threads, so once you get a handle on a label, you have to get all of its threads ❷, then grab individual mails under that thread. We'll use the first email of a thread for this simple exercise ❸.

Лучшие фото фотосайта на рабочем столе, дубль 3

Продолжаем соревнование с фотосайтом по разработке программы для установки в Gnome фото дня с фотосайта в качестве обоев рабочего стола.

#!/bin/bash
cd /var/photosight && \
FN=`wget -q http://www.photosight.ru/applications/photo1.js -O - \
  | iconv -f cp1251 -t utf-8 \
  | sed 's/.*\(http.*jpeg\).*/\1/' \
  | sed 's/top_of_day/large/'  \
  |xargs echo`
ID=`echo $FN |sed 's/.*\/\([0-9]\+\)_large.jpeg/\1/'`
wget -q -N  $FN -O $ID.jpg && \
gconftool-2 -t str --set /desktop/gnome/background/picture_filename /var/photosight/$ID.jpg && \
gconftool-2 -t str --set /desktop/gnome/background/picture_options "centered"
cd ~-