Secure and private online JSON viewer

Lately I’ve been doing a lot web development, which means a lot of JSON. Although JSON is pretty readable, for bigger of more complex JSON a viewer is necessary. The are some free tools, some work local, some online, but most of them lack a privacy note, so you don’t know what happens with the data you view in those viewers.
Since I work with medical data from patients, I needed to be sure this data isn’t sold or used for data mining.  So I wrote my own secure and private JSON viewer, which uses only client-side processing so data doesn’t leave your PC.

It is available for free for anyone to use, for any purpose. You can use it in this post, in an iframe, or you can use the ”bigger version” here.


I you like it or have a question or remark, please use the comment feature of this post

Comments Off on Secure and private online JSON viewer  

Use a Adafruit print on the Raspberry pi with Mono

This post is different from previous posts. This post only combines the information from these 3 webpages:
Printing on a thermal printer from .Net: http://electronicfields.wordpress.com/2011/09/29/thermal-printer-dot-net/
Installing a the Adafruit printer on a Raspberry: http://pikiosk.tumblr.com/post/38866317521/printing-with-raspberry
Changing the TTL setting on the Raspberry: http://64.13.91.137:86/Comp/RPi/Serial.html

When you know the information on these 3 pages it is quite simple to get the Adafruit thermal print, which is very cheap $50 or so, working on the Raspberry Pi and controlling it with Mono.

  1. The first thing you have to do is change the TTL port setting of the Raspberry Pi. Default this port is used for remote SSH, so you can connect you’re PC/laptop using a 10 bucks converter. But we want the Raspberry Pi to use the TTL port as a serial port. To change these settings we must edit 1 file:
  2.     /etc/inittab.
  3. If you know VI or can use an other editor on Linux, use that otherwise install GEDIT (85mb for a text editor, dear anyone say something about Windows). To do that, open a terminal window and type the following command:
  4.     sudo apt-get install gedit
  5. After confirmation an some waiting the installation is ready, the you can edit the txt file using this command:
  6.     sudo gedit /etc/inittab
  7. In the editor, find a line containing this text:

  8.     T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
  9. Add a hash tag # before that line:
    •     #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
    • And save. Now turn the Raspberry Pi off:
    •     sodu halt
  10. Next thing we need to do is to connect the printer to the raspberry. You can read the full story on the this site. The short version is:
  11. Get a descent power supply for the printer (9V 2A is the best)
  12. Connect the power to the printer, – = black, + = red
  13. Test the printer, check if the led blinks and check if the button feeds the paper
  14. The next step is scary, cut the green wire from the printer, if you don’t do it, the printer might damage your Pi.
  15. Connect the printer to the Raspberry Pi, black wire goes on pin 6 (third pin from the corner) the yellow wire goes on pin 8 (forth pin from the corner), the connector fist perfectly
  16. Last step it programming. Download the open source printer library, create a new solution, add a reference to the newly downloaded library. The print use this code:
  17. SerialPort printerPort = new SerialPort("/dev/ttyAMA0", 19200);
    printerPort.Open();
    ThermalPrinter printer = new ThermalPrinter(printerPort);
    printer.WakeUp();   // Let's wake up the printer
    printer.WriteLine("Hello from Pi");
    printer.LineFeed(); // Feed paper
    printer.Sleep();    // Save some energy
    Console.WriteLine("Printer is now offline.");
    printerPort.Close();

    Especially the first line is very important and it took me quite some time to find the correct setting.

    Test it and have funGlimlach
Comments Off on Use a Adafruit print on the Raspberry pi with Mono  

The best tools for software development

Here is a list of tools I you when developing software and for the reason I use that tool. Of course there are many other tools that do similar things and that are preferred by other people. Try all different tools you find and see which meets your needs best.

IDE

Since I only develop .net software the only IDE I use is Visual Studio. The Express edition is free to use for everyone, including business users. For .net this is just the on and only IDE. It is a very complete IDE, that includes tools for remote debugging, very good autocomplete and many extensions.

SOURCE CONTROL

For source control I use 2 different solutions:

  1. TFS, from Microsoft, which can be downloaded here and is a very complete solution, including continues integration, support for lean/scrum development. It is a quite heave tool so use it when you need all the features
  2. Visual SVN, a open source version control which can be downloaded here. It is a light weight, version control only solution. It has a big advantage, it is cross-platform and clients are available for most platforms
TEXT EDITING
 
I mainly use 2 different text editors for all kind of text editing:
  1. GVIM, an open source text editor based on VI, known as text editor that was included in Unix systems and currently is included in most, if not all, Linux distribution. I use it mainly when I need to search log files or when I need to extract specific data from texts, eg get measurements from and product name. For this I use regex, I is difficult to start, but once you get started, you see how powerful it is. But for regular editing I never got used to it.
  2. Notepad++ an other open source text editor. It is very powerful, with many plugins. The features I use most are the macro recorder and find in files. Useful plugins are the hex editor and the ftp plugin.
DATABASE
 
For al projects that need a database, I use Microsoft Sql Server. For most projects the free express edition is enough. For bigger projects or advanced maintenance you need a paid version. It is a descent stable and very capable database which integrates nicely with other Microsoft products.
 
 
 

How to use the updateprogress without an updatepanel

In a project I’m currently working on, we couldn’t use an updatepanel anymore. Why? Because we need to use some third party control that doesn’t work with an updatepanel. On that page we already used a nice updateprogress and we wanted to keep that functionality because the are some time consuming functions on that page.
If you use Bing or Google you will find no real solution. But we found one. First we need to create our own updatepanel in the.ascx file:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<a href="#" style="display: none; visibility: hidden;" onclick="return false" id="dummyLink" 
    runat="server">dummy</a> 
<cc1:ModalPopupExtender ID="popUp" runat="server" TargetControlID="dummyLink" PopupControlID="pnlTstPopup" 
    BackgroundCssClass="modalBackground" BehaviorID="MyMPE"> 
</cc1:ModalPopupExtender> 
<asp:Panel ID="pnlTstPopup" runat="server" Style="display: none;" SkinID="PopUpPanel" 
    CssClass="modalpopupBusy"> 
    <div class="zorgplan_progress"> 
        <div id="parent" style="width: 100%"> 
            <div align="center" id="container"> 
                Bezig met het verwerken van gegevens. 
            </div> 
        </div> 
    </div> 
</asp:Panel>

And of course some css:

.modalpopupBusy 
{ 
    background-color: blue; 
    border-color: White; 
    border-radius: 7px; 
    position: relative; 
    border: 1px solid #ccc; 
    width: 40%; 
    height: 150px; 
} 
.modalProgress 
{ 
    background-color:aqua; 
    color: #4D4B57; 
    border-radius: 7px; 
    vertical-align: middle; 
    padding: 50px; 
    margin: 0; 
}

And here is the trick, we need some Javascript to show the popup:

function show_popup() { 
   setTimeout(function() { $find('popUp').show(); }, 1000); //Time in ms before the popup appears  
} 

And no the worst part of this solution, we need to call this js function with every action that could take some time. For example:

<asp:Button ID="cmdVerder" Text="Verder" runat="server" OnClick="cmdVerder_Click" 
    CssClass="button_verder" OnClientClick="show_popup();" />

I know this solution isn’t ideal but it works just fine.
I hope that you find this method useful.

Comments Off on How to use the updateprogress without an updatepanel  

MVVMlight button in DataTemplate

For a major project I’m currently working on I needed to add a button to the items in a ListPicker. This projects uses MVVMLight as MVVM framework, so I have to use the RelayCommand for the handling of the button clicks. My initial thought was to do it just like any other button:

View (XAML):

<button content="Action" width="200">
<phone:PhoneApplicationPage.Resources>
  <datatemplate x:key="ActionTemplate">
    <stackpanel orientation="Horizontal"> 
      <textblock width="450" textwrapping="Wrap" margin="0" text="{Binding ActionName}" />  
      <button content="Use" width="200">
        <custom:interaction.triggers>
          <custom:eventtrigger eventname="Click">
	    <galasoft_mvvmlight_command:eventtocommand command="{Binding ActionCommand, Mode=OneWay}" />
          </custom:eventtrigger>
        </custom:interaction.triggers>
      </button>
    </stackpanel>
  <datatemplate />
</phone:PhoneApplicationPage.Resources>

ViewModel:

public RelayCommand ActionCommand
{
  get;
  private set;
}
//Constructor
public LogonViewModel()
{
  this.ActionCommand = new RelayCommand(() => this.DoAction());
}
public object DoAction()
{
  //Some action
  return null
}

But that didn’t work, the relaycommand was never executed. The reason is obvious, the datacontext of the ListPickerItem, and thus the DataTemplate, isn’t the ViewModel, it’s the item itself. How to solve this problem? That is quit simple. The ViewModel and the View needs only a small adjustment:

<phone:PhoneApplicationPage.Resources>
  <ContentControl x:Key="Context" Content="{Binding}" />
  <datatemplate x:key="ActionTemplate">
    <stackpanel orientation="Horizontal"> 
      <textblock width="450" textwrapping="Wrap" margin="0" text="{Binding ActionName}" />  
      <button content="Use" width="200">
        <custom:interaction.triggers>
          <custom:eventtrigger eventname="Click">
	    <galasoft_mvvmlight_command:eventtocommand Command="{Binding DataContext.ActionCommand, Mode=OneWay, Source={StaticResource Context}}" CommandParameter="{Binding}"/>
          </custom:eventtrigger>
        </custom:interaction.triggers>
      </button>
    </stackpanel>
  <datatemplate />
</phone:PhoneApplicationPage.Resources>
public RelayCommand<Action> ActionCommand
{
  get;
  private set;
}
//Constructor
public LogonViewModel()
{
  this.ActionCommand = new RelayCommand<Action>(a => this.DoAction(a));
}
public object DoAction(Action a)
{
  // "a" contains the item which button was pressed
  //Some action
  return null;
}
Comments Off on MVVMlight button in DataTemplate