Wednesday, February 3, 2016

writing an executable in javascipt

Hi,

today I played around with javascript and its possibilities. To execute js in the browser was a quite non-innovative approach. That windows-8/10 apps can be written in js was also not new to me.The missing element to cover all kinds of applications was the desktop application. After 10 seconds of google-ing I found out that this works too. Even better, it works in combination with the .net framework which opens up a lot of possibilities.

The following code snippets show my test case. The resources I used were: http://www.phpied.com/make-your-javascript-a-windows-exe/ and additionally to check for the ability to use WPF components (yes that works too) https://social.msdn.microsoft.com/Forums/vstudio/en-US/bb41013f-e915-4743-81b0-8bea2d9acebb/jscriptnet-wpf?forum=netfxjscript .

make.bat
@echo off
del program.exe
"c:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc" "program.js"
program.exe

program.js
import System;
import System.Windows.Forms;
function outputMessageBox(text) {
 MessageBox.Show(text, "output message");
};
 
function output(text) {
 Console.Write(text);
};
 
output('hello world');
outputMessageBox('hi');


I am looking forward to find a use case for it :-)

kind regards,
Daniel

Friday, December 4, 2015

Debugging return values in C#

Hi,

I found an extremly helpful feature in Visual Studio 2013: showing the value which is returned by a function.
Example:


1
2
3
4
public bool CheckExists(string itemId)
{
   return ItemList.Exists(item => item.ItemId == itemId);
} // <- breakpoint

With the debugger it is hard to find whether the itemId is or is not in the list (if the list has thousands of entries), BUT as shown in the link it is possible to get this value through the "Autos" window or the immediate window in visual studio while having a breakpoint on the "}" in line 4. The good news is that it even works with "$ReturnValue" in the watch window, but in contrary it seems not to work properly for any use case (with all above introduced solutions). I'm pretty sure that this is reasonable if we have a look on the disassambly, but that is out of scope here.
kind regards,
Daniel

Wednesday, December 2, 2015

javascript functions in html elements

Hi,

I was wondering today about the following possibility to declare functions in html:

<html><body>
<div id="divid">content</div>
 

<a href="#" onClick="document.getElementById('divid').setAttribute('style', 'font-weight: bold; color: red; font-size:150%;');" >attack 1</a>
 
<a href="#" onClick="
var x = function() {
 document.getElementById('divid').setAttribute('style', 'font-weight: bold; color: red; font-size:150%;');
};
x();
" >attack 2</a>
 
</body>
</html>

both versions of the link are really scary... (tested in chrome).

So in server generated code even here HTMLEncoding must be considered to prevent XSS-attacks.

kind regards,
Daniel

Thursday, November 26, 2015

Book-Review: Responsive Web Design with AngularJS (Sandeep Kumar Patel)

The book is a low level beginner’s guide to AngularJS and some of its responsive capabilities if you are using AngularJS pure (without twitter - bootstrap). A responsive portfolio-application is built as a show-case to introduce the reader to common problems of the field. Other technologies like SASS and JSON are mentioned and partly shown. The book ends with tool advises like the Chrome-F12-tools and Batarang.
AngularJS topics:
-          Templates and DataBinding (MVW)
-          Partials
-          Router
-          Modules / Controller / Scopes
-          Directives (built-in and custom)
-          Custom Services
-          Events / $Watch
-          Publish-Subscribe with $emit, $broadcast - $on
It was easy to read and with good background information, but I would say that after reading it you are not 100% able to build an AngularJS application responsively (and even not responsively) your own. Further investigations are definitely necessary...

kind regards,
Daniel

Wednesday, November 11, 2015

Helpful error handling in JavaScript

Hi,

today I tried to develop an error handling in javascript (more exact: angularjs, but this is as good as meaningless here) that makes sense and is helpful. The following solution is built and tested in Chrome.

First of all: javascript support try/catch blocks we can use by throwing errors


1
2
3
4
5
try {
  throw new Error('Whoops!');
} catch (e) {
  alert(e.name + ': ' + e.message);
}

(see: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Error )
... but this is not the thing I meant...

I wanted to create a central function (error callback, error output method) that can be used to gather further information during development time (e.g. as an error callback for a bad web service rest request; as a usable function to call if an internal object state is unknown => a situation happens that should never happen).

... so I did the following:

1
2
3
4
5
6
7
8
            $scope.writeError = function (response) {
                if (true) { // DEBUG
                    console.error('error', response);
                    console.trace();
                    debugger;
                    throw new Error('error');
                } 
            };

writeError has an if (line 2) which disables the javascript-console information fast. In angularjs it is easily possible to build this "if" depending on angularjs-constants that can be configured central in a application configuration section.

line 5 sets a coded breakpoint in the javascript console (see: http://stackoverflow.com/questions/10050465/set-a-javascript-breakpoint-in-code-in-chrome / I adapted the jsfiddle to http://jsfiddle.net/hBCH5/70/ ); 3 and 4 writes the data (and all its properties) to the console; line 6 throws an exception that can be caught in code and shows similar information to the console.

Attention: the removal of the throw statement can change the application execution logic if try/catch blocks were used outside.

kind regards,
Daniel

// Update

I should have mentioned 2 things:
- there is window.onerror where you can assign an event handler
- there are frameworks like jsnlog ( jsnlog.com ) that sends the error to a server where they can be monitored centrally (angularjs compatible)

Friday, October 30, 2015

Reporting solutions

Hi,

today I had a look on reporting software... of course I did not consider the hardcore solutions for big corporations like Cognos, tibco, microStrategy,...

After some research I decided to pick the following solutions to dig deeper:
- SAP: Crystal Reports
- Microsoft: SSRS
- Eclipse: BIRT
- tibco: JasperReports
- jsreport
- sealreport
- Pentaho

The free solutions looked mature enough to kick the commercial solutions out of my evaluation.
jsreport seems to have currently fewer features than the others (even if the concept looks quite straight-forward for web-solutions), so I kicked it.
seal-reports is open source, but the full power of the solution will not be unleashed until buying a license (when I understood it right), so I kicked it.

- Eclipse: BIRT
- tibco: JasperReports
- Pentaho

These are exactly the solutions as described in http://opensource.com/business/14/6/three-open-source-business-tools ... Because I want to stay focused on reporting and not on BI I removed Pentaho from the list ( http://www.pentaho.com/ seemed to stress the data integration and the setup of a cube) and choose BIRT because of a lot of opinions on the web like  http://stackoverflow.com/questions/2513534/birt-vs-jasper-reports .

A good comment of the opensource.com-link above introduced the page www.reportserver.net which seems to be a good extension to the BIRT technology.

must criterias for the reporting solution:
- db interface
- pdf output
- web output
- IDE for power-users
- active development / community
- command line support

kind regards,
Daniel

Thursday, October 29, 2015

bootstrap editors

Hi,

after a small break I am back reincarnated as a web developer.

Today I played around with bootstrap trying to change the style of my web-page.

Following resources helped me much
- http://getbootstrap.com/
http://www.bootply.com/
- http://fortawesome.github.io/Font-Awesome/
http://glyphicons.com/

but it didn't feel right to work online (and to collaborate without possibly wanting it).

I found other resources to consider
http://www.layoutit.com/
http://brix.io/

... again web, but there are still the stand-alone, cloud-less, good-old tools like:

commercial desktop products:
http://pinegrow.com/

free desktop products:
http://pingendo.com/


What I did not found are true alternatives to bootstrap itself and in fact I don't even need any. Bootstrap is a really good designed, good working framework which does create good looking pages.

kind regards,
Daniel