Monday, August 25, 2014

App Script Form to add a Calender Event

Google App Script allows you to automate work flows and create Add-ons with Google Sheets, Docs and Forms. It is also possible to integrate external Google Apps.

One example is to create a Google Calender Entry or Event with an App Script. The following code snipped gives you the idea how it works:

The function doget() is responsible to define the form to enter data needed to create the event. It defines the clickhandler of the submit button.

 function doGet() {  
  var app = UiApp.createApplication();  
  var form = app.createFormPanel();  
  var grid = app.createGrid(5, 3).setId('gridForm');  
  var eventTitle= app.createTextBox().setName("eventTitle").setTitle("Event Title");  
  var descr= app.createTextBox().setName("descr").setTitle("Description");  
  var lbFromDate = app.createDateBox().setName("lbFromDate").setFormat(UiApp.DateTimeFormat.DATE_TIME_SHORT).setTitle("From");  
  var lbToDate = app.createDateBox().setName("lbToDate").setFormat(UiApp.DateTimeFormat.DATE_TIME_SHORT).setTitle("To");  
  var btnSubmit = app.createButton("Create");  
  var titleRequired= app.createLabel("*").setId('titleRequired');  
  var lblFromDateRequired = app.createLabel("*").setId('lblFromDateRequired');  
  var lblToDateRequired = app.createLabel("*").setId('lblToDateRequired');  
  grid.setWidget(0, 0, app.createLabel("Titel"));  
  grid.setWidget(1, 0, app.createLabel("Description"));  
  grid.setWidget(2, 0, app.createLabel("Von"));  
  grid.setWidget(3, 0, app.createLabel("Bis"));  
  grid.setWidget(0, 1, eventTitle);  
  grid.setWidget(1, 1, descr);  
  grid.setWidget(2, 1, lbFromDate);  
  grid.setWidget(3, 1, lbToDate);  
  grid.setWidget(4, 1, btnSubmit);  
  grid.setWidget(0, 2, titleRequired);  
  grid.setWidget(2, 2, lblFromDateRequired);  
  grid.setWidget(3, 2, lblToDateRequired);  
  //Controles and click handler  
  var submitHandler = app.createServerClickHandler('validateAndCreate');  
   return app;  

By pressing the submit button the function validateAndCreate will be executed. This function implements a simple check of the input data an creates the Google Calender Event within the given Calendar (defined by the Calendar ID).

  function validateAndCreate(eventInfo) {  
   var app = UiApp.getActiveApplication();  
   var flag = 0;  
   var currentTimestamp = new Date();  
   if (eventInfo.parameter.eventTitle== ''){app.getElementById('titleRequired').setText("* Title Required").setStyleAttribute("color", "#F00");flag = 1;}  
   if (eventInfo.parameter.lbToDate < eventInfo.parameter.lbFromDate){app.getElementById('lblToDateRequired').setText("* To Date must be later than From Date").setStyleAttribute("color", "#F00");flag = 1;}  
   if (eventInfo.parameter.lbFromDate == ''){app.getElementById('lblFromDateRequired').setText("* From Date required").setStyleAttribute("color", "#F00");flag = 1;}  
   if (eventInfo.parameter.lbToDate == ''){app.getElementById('lblToDateRequired').setText("* To date required").setStyleAttribute("color", "#F00");flag = 1;}  
   if (flag == 0){  
    var calendarId = "PUT_IN_HERE_YOUR_CALENDERID";  
    var startDt = eventInfo.parameter.lbFromDate;  
    var endDt = eventInfo.parameter.lbToDate;  
    var desc = eventInfo.parameter.desc + " created: " + currentTimestamp;  
    var title = eventInfo.parameter.eventTitle;  
    //Run the Crete event Function  
    app.add(app.createLabel("Event Created.");  
   return app;  
 function createEvent(calendarId,title,startDt,endDt,desc) {  
  var cal = CalendarApp.getCalendarById(calendarId);  
  var start = new Date(startDt);  
  var end = new Date(endDt);  
 //Manually set the Location, this can be modified to be dynamic by modifying the code if need be  
  var loc = 'YOUR LOCATION';  
 //Set the Options, in this case we are only using Description and Location, as we do not need Guests or sendInvites  
  var event = cal.createEvent(title, start, end, {  
    description : desc,  
    location : loc  

Then you can embed the App Script within your Google Sites page to visualize the form.

Tuesday, June 17, 2014

Install a Nest Thermostat in Europe

Currently the NEST thermostat is only available in the USA and Canada. But is it possible to install the Thermostat in also on the other site of the ocean? Recently the distribution was extended to the UK also, but on mainland Europe there is no official support.
Nevertheless it is possible to install the NEST thermostat in the rest of Europe. With the update to NEST software version 4.0 it is now possible to set postal codes in Europe. With this setting time zones are set correctly. More info on the update can be found here.

Sunday, April 13, 2014

Android 4.5 Screenshots leaked - Codename Lollipop

Android 4.4.3 will be the next Android release. This release will only include bug fixes but no new features. The next big version of Android will be Android 4.5 and probably called Lollipop. It is very likely that this new version is introduces at Google I/O in June 2014.
We are looking forward for the new and improved features of Android 4.5.

New Multitasking with Project "HERA"

According to several leaks Google is working to improve its multitasking by combining Chrome and Google Search. It will execute tasks through the web. HTML 5 will be used as technology to show the actions being taken in a multitasking menu, where the users will be able to switch between tasks.

Android 4.5 other new features

Many other features are leaked a few days ago. the new Gmail app will introduce a completely new interface. As Android 4.5. will integrate HTML 5 directly to the operating system we can expect even more exciting features. This is also proved by some screenshots of the calender app.
Android Lollipop will probably com with the Google Nexus 8 in June or July. Stay tuned.

Tuesday, April 1, 2014

Leaflet and CartoDB - The perfect combination

What is currently the most easy and convenient way to publish geographic data stored within a database via the web? One easy way doing so is the combination from Leaflet and CartoDB.

Leaflet is an open source library for publishing online maps. The JS library is lightweight (just 33 KB), and has all the features most developer expect from interactive maps. Furthermore functionalities can be extended via plug-ins developed by the open source community around leaflet.

CartoDB is a online database which can also be published on an own web server. The database allows to store geographic entities with geometry type point, lines and polygon. The database provides several APIs including an SQL API where it is possibly to execute native SQL queries. In addition CartoDB provides a leaflet JS plug in to access data directly as layer.

Some basic example to start with:

1) Create sample Data within CartoDB
2) Include Leaflet and CartoDB JS libraries within your HTML page.
3) Create a Leaflet map object and link it to a DIV object within the HTML page:

HTML part:
<div id="map" ></div>
JavaScript part:

// create a map in the "map" div, set the view to a given place and zoom var map ='map').setView([51.505, -0.09], 13);

4) add a basemap Layer (e.g. Openstreetmap) to the map)

// add an OpenStreetMap tile layer L.tileLayer('http://{s}{z}/{x}/{y}.png', { attribution: '&copy; <a href="">OpenStreetMap</a> contributors' }).addTo(map);

4) add sample data stored witin Cartodb to the map

// add an Cartodb layer var cartodb_leaflet = new L.CartoDBLayer({
        map: map,
        user_name: "user_name",
        table_name: "table_name",
        query: "SELECT * FROM {{table_name}}",
        tile_style: "#{{table_name}}{polygon-fill:blue;  polygon-opacity: 0; line-color: yellow;  line-width: 5;  line-opacity: 0.7}",
        interactivity: "cartodb_id",
        featureClick: function(ev, latlng, pos, data) { },
        featureOver: function(){},
        featureOut: function(){},
        attribution: "CartoDB",
        auto_bound: true

5) finnished.

Sunday, February 9, 2014

How to print from legacy applications and platforms

Printfil is an application which allows printing to windows printers from legacy platforms like MS DOS, Unix and Linux via tlnet or other terminal emulator software. It is also possible to print to USB easily.
PRN is well known as a short term for print and used an acronym since the DOS ages. In DOS the command PRN was used for the standard printer parallel Port, often also named as LPT1. The application DOSPRN simulates this. In this ages the LPT1 post was the only and dedicated port for printing and USB, network, Bluetooth and WiFi was not intended or used for printers.
With Windows a special kind of FILE was used to send the printing data to the printer. Creating such a file was easy for windows programs and applications., allows selecting to FILE as destination instead of a physical printer.
On some situations redirecting a print job to a file on disk is desirable because, for example, the real destination printer is not available in that moment, or just because we want to read a job on screen and trash it immediately, without wasting paper and ink for an unnecessary hardcopy.
How to print a PRN FILE in Windows
As we've said above a PRN file is a file on disk created by the Print to file option of a Windows program.
That file can be read on screen with the Windows Notepad only if you've choosen a "Generic / Text Only" printer when creating it because this way Windows normally creates a file containing a graphical print job, specifically designed to be PRINTED (not shown on screen) with the same printer originally selected when creating the file itself.
That file can be printed with a different printer model only if the printer driver originally selected was for a printer supporting a standard graphical language like HP-PCL or PostScript.
For example, if you did select a HP-PCL printer driver when creating the DOS PRN file, then that file can be printed to any HP-PCL capable printer, even if the printer is not exactly the same model selected when creating the file.
The same applies if you created the file by selecting a PostScript printer driver, but a PRN file containing PostScript data cannot be printed with an PCL capable printer, and a PRN file containing PCL data cannot be printed with a PostScript capable printer.
If instead you selected a GDI (also known as Windows-Only) printer when creating the DOS PRN file, then that file can be correctly printed only by that very same physical printer model later on.
Unfortunately, Windows allows easily creating a PRN file, but then there's no easy way to physically print it to a compatible printer.
Printfil easily overcomes this limit however. You just have to drag and drop the PRN file over the Printfil's icon on the desktop, then it will ask you to choose the destination printer on screen and Printfil will send the file there. That's all.
If you did choose to "associate DOS PRN files with Printfil" when requested during the Printfil installation, then a simple double-click on the PRN file is sufficient to print it.