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

Wednesday, June 3, 2015

.NET Crawler Harvest

Alexander Nyquist ( http://nyqui.st/ ) made a cool crawler-component I used once... the solution worked quite good for me...

http://nyqui.st/harvest-a-c-multithreaded-web-crawler
https://github.com/alexandernyquist/Harvest/

in my solution I wrote the page to the filesystem using the OnPageDownloaded and wrote some code for filtering items which redirect to a login page. Here a decision has to be made about using a white-list or a black-list approach. For full-text search purpose media content can be filtered too.

cheers,
Daniel

Wednesday, May 27, 2015

dynamic dispatch using "as dynamic" in c#

I found a new entry for our internal coding guidelines: "don't use dynamic dispatching if not absolutely necessary!".

wikipedia:
...
In computer science, dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at run time. Dynamic dispatch contrasts with static dispatch in which the implementation of a polymorphic operation is selected at compile-time. The purpose of dynamic dispatch is to support cases where the appropriate implementation of a polymorphic operation can't be determined at compile time because it depends on the runtime type of one or more actual parameters to the operation.
...
Dynamic dispatch is often used in object-oriented languages when different classes contain different implementations of the same method due to common inheritance. 
...


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dynamic
{
    public interface IInt
    {
    }

    public class A : IInt
    {
    }

    public class B : A
    {

    }

    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();

            IInt x = new A();
            p.Print(x);
            p.Print((A)x);
            p.Print(x as B);
            p.Print(123);
            p.Print(x as dynamic);

            Debugger.Break();
        }

        public void Print(IInt p)
        {
            Console.WriteLine("IInt");
            //if (p is B)
            //{
            //    Print(p as B);
            //} 
            //else if(p is A)
            //{
            //    Print(p as A);
            //}
        }

        public void Print(A p)
        {
            Console.WriteLine("A");
        }

        public void Print(B p)
        {
            Console.WriteLine("B");
        }
        /*
        public void Print(object p)
        {
            Console.WriteLine("obj");
        }*/

        public void Print(dynamic p)
        {
            Console.WriteLine("dynamic");
        }
    }
}

Output:
 IInt
A
B
dynamic
A

 The reason why line 61 to 65 is commented out is that it is technically not possible to keep both functions in code ... the one with the object parameter and the one with the dynamic (will be translated to object later). At first sight it seems to be elegant to call line 30 and get the interface function and then call line 34 and get the "right" function, but don't forget the difference... you put compiler decisions to run-time, so you trick the compiler in some ways. Don't do that!

 kind regards,
Daniel

sql recursive functions (linked lists in sql)

In modern programming languages it makes sense to work with lists, stacks, dictionaries and other collections. This can be crucial when you want to persist the data into the database, because some considerations have to be made about sorting and stuff like that.

Now implementing a linked list in a table is easy:

table: mylist

  • ID: int (not null)
  • data: nvarchar(50)
  • nextID: int (null)
... more tricky is to walk through the list and find e.g.: the leaf of a corresponding root (seeing a list as a special sort of tree). 

the solution is described at: 

http://stackoverflow.com/questions/16749095/sql-recursive-function-that-gets-all-ancestors-of-an-item

...but the other way round using parent_id instead of a next_id

data_table:
ID       parent_id   name
---------------------
1        2            first 
2        4            second
3        3            third
4        5            fourth
5        -            fifth

the solution looks as follows:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
with parents as 
(
  select ID, parent_ID
  from data_table t
  where parent_ID is not null
  union all 
  select p.ID, t.parent_ID
  from parents p
    inner join data_table t on p.parent_ID = t.ID
      and t.parent_ID is not null
      and t.ID <> t.parent_ID
)
select *
  , parents = '(' + stuff
    (
      (
        select ', ' + cast(p.parent_ID as varchar(100))
        from parents p 
        where t.ID = p.ID
        for xml path('')
      ), 1, 2, ''
    ) + ')'
from data_table t
order by ID

  • line 1 gives the inner statement a name to call it e.g.: more often like in
    with y as (select * from x where id > 12) select * from y, y
    ... here you have a smaller set of data to cross join
  • line 3 to 5 makes a select as a starting point for the recursion (the original records)
  • union all in line 6 adds to the starting point a data set defined below
  • line 7 to 11 was at first sight simply magical to me
    • line 7 selects the columns corresponding to line 2 (required by the union and makes sense with the recursive algorithm) ... the own id and the parent of parent
    • line 8 requests data from the data table itself (the recursion using the name), but
    • line 9 joins parent data to the original data
  • line 13 to 24 uses the "expanded" data evaluated and shows it nicely in an own column using "for xml path".
the expanded result is:
| ID | parent_ID |
|----|-----------|
|  1 |         2 |
|  2 |         4 |
|  3 |         3 |
|  4 |         5 |
|  2 |         5 |
|  1 |         4 |
|  1 |         5 |

this will be transformed to

| ID | parent_id |   name |   parents |
|----|-----------|--------|-----------|
|  1 |         2 |  first | (2, 4, 5) |
|  2 |         4 | second |    (4, 5) |
|  3 |         3 |  third |       (3) |
|  4 |         5 | fourth |       (5) |
|  5 |    (null) |  fifth |    (null) |

...

There is an addition for select statements to overwrite the max recursion depth (in sql server it is default set to 100) to work with "deep" lists or trees.

    OPTION (MAXRECURSION 0)

kind regards,
Daniel