C#: Save the page state on a Metro-style application

May 2nd, 2012

Suppose you have two pages, A and B. The user can modify things on page A then navigate to page B. When he is on page B, he clicks the “Back” button to go to page A. Everything that has been done previously is lost.

There is a way to get the exact same state by using, in the Page constructor:

1
2
this.NavigationCacheMode = 
        Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;

You can also know if the page is loading coming from a back button click or if it is new.

1
2
3
4
5
6
7
protected override void OnNavigatedTo(NavigationEventArgs e)
{
  if (e.NavigationMode == NavigationMode.Back)
  {
    // LoadPreviousSate...
  }
}

Android: Status Swisscom for Android

June 30th, 2011

I’m happy to release a little app I firstly did for myself, Status Swisscom. The app lets you check out your SMS and Data credit in your Swisscom phone plan.

Beware if you are not in Switzerland or not using Swisscom, it sends an SMS to the number 444. It’s free for Swisscom users, but not guaranteed to other operators.

Android: Download a vCard on Android or iPhone

June 30th, 2011

If you visit my homepage schmid.pro using a mobile device, you will see that the design is slightly different. Plus, you will be able to download my vCard.

By default, if you don’t specify anything, Apache is not able to understand the .vcf extension, and serves the file as plain/text, which is bad!

Android sees it as a text file and lets the browser open it instead of opening the Contact application. Same as for the iPhone. I had to find a workaround.

Serve a vCard for Android

Android is able to handle vCards, as long as their mime-type is text/x-vcard. The easy view is to add this type to your htacces file and an Android user will have his contact application opened up when he clicks on your vCard file!

1
2
  ForceType text/x-vcard
  Header set Content-Disposition attachment

Serve a vCard for iOS/iPhone

As usual when Steve decided that you cannot do something, you cannot find a workaround. Well… Steve decided it is not worth being able to download a vCard from the browser…

There is no easy way to enable the iPhone user to download your vCard and add it to its contact list.

But there are some hacks you can use.

The first one is

  • Detect the iPhone
  • Asks the user his email address
  • Send him your vCard by email

Believe it or not, the Mail app is able to handle vCards, but not Safari.

The second one is to create a Google Places entry, because the Google Maps application can handle Google Places.

1
2
3
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*Mobile.*Safari
RewriteRule ^(.*)vcard.vcf$ http://maps.google.com/maps....

I currently implemented none of them on my site. I don’t know if iPhone users are worth the effort ;)

You can try to download my vCard.

C#: Debug a SOAP Webservice client with Visual Studio, access its raw content

June 9th, 2011

I’ve had some problems with a service provider we are working with. I don’t have access to the service itself, and communication was a bit… hard with them. So I had to look by myself what the service was answering to my queries.

When you create a service endpoint with Visual Studio, you cannot see what’s going on with the service itself, it is wrapped by a generated container and not easy look into it. You cannot see the raw content of the response.

The best solution I have found is to use Fiddler. This software sniffs the HTTP(S) requests and format them in a readable way.

If a request goes wring, launch Fiddler, retry your request and see in Fiddler what you got from the service.

For me it was everything I needed to see that the response was not well formatted.

Android: PocketCampus EPFL beta is out!

May 12th, 2011

I am happy to announce that we released a beta of PocketCampus.

PocketCampus is an Android application dedicated to EPFL’s campus. On this first release you can find:

  • Camipro: get access to all the transactions (payments) you made with your student card
  • Food: get the menus of EPFL’s restaurants, get suggestions (meat, vegetarian, pasta, …) and rates each menu
  • Map: map of the campus with an awesome list of layers to help you locate anything on the campus
  • News: news from EPFL’s website
  • Transport: get transportation information from EPFL to your home

Be aware that it’s still in beta :)

Now you all want to try it, here is the link

EPFL: Menus at EPFL restaurants for a Mobile device

February 17th, 2011

I forgot about this mini-project. But I created last year a small web-app to access to restaurants menus at EPFL.

Since it’s a web-app, you can access it using any kind of mobile device (Android, iPhone).

Try it!

Menus EPFL

Android: SnowReport hits 5’000 downloads !

January 23rd, 2011

Quick post to tell that SnowReport Switzerland for Android reached 5’000 downloads this week-end :)

It got some bad ratings because it crashes when you have a certain configuration, and I did not have time to patch it although I know exactly what causes the problem.

Holidays soon, bugfix nights in approach… :)

Javascript: Remove multiple Facebook photo albums

January 20th, 2011

I’ve been thinking of removing some photo albums from my Facebook account for a long time now. Recent events convinced me to do it quickly.

But I found it is a pain to remove one album after the other. You have to go to you albums, choose the one, click “edit”, click “delete”, click “delete” (yes, twice). And after my trip to the USA in 2008, I had looooots of albums.

Well, you know where I’m going: I created a script to remove albums easily.

I hope I’ll have time to improve it, so I created a “project page”, instead of just a blog post. You find it here: Facebook mass album remover bookmarklet

Apache: Really simple and efficient caching system using htaccess

December 12th, 2010

I recently had to use a caching system in a web service we provide at Epsitec.

The service needed to provide some data, generated every day. This data was retrieved from another server then processed to get useful information, and kept the same for the whole day. We also wanted to store the data.

I decided to devise a really simple caching system, inspired by WP Super Cache.

The system works that way:

  • Hide the “processing” part from the user using URL rewriting
  • The user always thinks he’s accessing a file
  • If the file does not exist yet, process the data, create the file, serve the file
  • If the file does not exist but cannot be fetched (too early, too late), return an error

Here is the code of the htaccess file:

1
2
3
4
5
6
7
8
9
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^daily/([0-9]{4})-([0-9]{2})-([0-9]{2})\.xml$ /fetcher.php?year=$1&month=$2&day=$3 [L]
 
</IfModule>
ErrorDocument 404 /error.xml

You can see that the name of each file is daily/yyyy-mm-dd.xml.

We first check that the file does not exist yet with RewriteCond. The regexp passes it to the fetcher to generate the content using RewriteRule.

My fetcher.php file is the script that retrieves the data, processes it and saves it into a file.

It has many advantages:

  • Retrieve the data only once a day, efficient for both you, your data provider and the user who doesn’t have to wait
  • Efficient, since most of the accesses are accesses to a file, involving no processing, and no database access

Android: Christmas Live wallpaper is out!

December 1st, 2010

This week is full of surprises :)

You can know download my second Android application: Christmas Live Wallpaper.

Have fun with it! :)