Thursday, December 20, 2012

PrimeFaces: working with big dialogs

I've come across a problem with PrimeFaces dialogs, when those dialogs contained elements which could expand, such as data grids. When those dialogs were bigger than the document itself, you could run into situation where the close button was unreachable and the user could only refresh page and lose all data.

The problem is that the dialog are not added to the main element, but are displayed as position:fixed. It means, that even if the scroll is available, the dialog itself won't be scrolled. That kind of positioning is working quite good with small dialogs, which are displayed only in the middle of window, but for big dialogs this is disaster. I didn't want to change that behaviour for small dialogs, for which it was working fine.

As a solution, I've created a JavaScript snippet, that checks if the dialog can fit the screen. If it is too big, the document is expanded and the dialog positioning is changed to absolute, so that the browser window scroll is displayed and each region of dialog can be visited. The position of dialog is also checked, to prevent the situation, where the dialog is displayed in unreachable region of window (this can happen, if you change the size of the browser after hiding the dialog.

This solution isn't perfect, it could be improved to react dynamically on window resize, for example, but this is fixing the main issue with too big dialogs on too small screens.

Any comments are welcomed.


function handleResizeDialog(dialog) {
    var el = $(dialog.jqId);
    var doc = $('body');
    var win = $(window);
    var elPos = '';
    var bodyHeight = '';
    var bodyWidth = '';
    // position:fixed is maybe cool, but it makes the dialog not scrollable on browser level, even if document is big enough
    if (el.height() > win.height()) {
        bodyHeight = el.height() + 'px';
        elPos = 'absolute';
    }   
    if (el.width() > win.width()) {
        bodyWidth = el.width() + 'px';
        elPos = 'absolute';
    }
    el.css('position', elPos);
    doc.css('width', bodyWidth);
    doc.css('height', bodyHeight);
    var pos = el.offset();
    if (pos.top + el.height() > doc.height())
        pos.top = doc.height() - el.height();
    if (pos.left + el.width() > doc.width())
        pos.left = doc.width() - el.width();
    var offsetX = 0;
    var offsetY = 0;
    if (elPos != 'absolute') {
        offsetX = $(window).scrollLeft();
        offsetY = $(window).scrollTop();
    }
    // scroll fix for position fixed
    if (pos.left < offsetX)
        pos.left = offsetX;
    if (pos.top < offsetY)
        pos.top = offsetY;
    el.offset(pos);
}

Friday, May 11, 2012

The Ten Happiest Jobs - Forbes - why IT jobs are hated?

I've found recently the following article:
The Ten Happiest Jobs - Forbes

What can be for some people suprising, ont the list of the most hated jobs are many IT jobs: web developer, technical specialist, IT director... Because of high salary this jobs are seen by many as the dream job, however for this big money a high price is to be paid.

This jobs are very stressful and you spend usually the whole day sitting at the desk and starring at the screen, which is both disastrous for health and eyes. IT specialists are usually very creative people, which wish to create something new and important, and unfortunatelly most of IT jobs is doing task which requires copypasterism and reading documentation about magic switches in someone's magic framework that doing something creative and innovative. This is mostly visible in web frameworks, where there are very many things written and most of the job is configuring and modifying someone's job. DB developers are in better position.

Thursday, May 10, 2012

Exporting contacts to gmail


Google claims Gmail can import contacts from various programs, which is working because they accept 'various common names' for data fields. However, when I've wanted to import contacts from Excel spreadsheet, I've found out that it isn't as easy as it should.

I've named fields according to 'common sense' notation: first name, last name, name, e-mail, phone. E-mail got imported, name also, but other fields where added to 'notes'. I've tried to google out to which names the import react but I've found no tip. It seems that Google simply have implemented support for various popular formats, so if you want to prepare your own CVS file, you should apply to one of this formats. I've gone this way, using Gmail contacts export format. E-mail fields is named "E-Mail 1 - Value", phone - "Phone 1 - Value" (you can use numbers from 1 to 3). Additionally you need to specify e-mail and phone type: "Mobile" for cellular phone, "Other" for other, "Home" for 'home' email.

First I've formatted in such way the phone and it got imported. But when I've formatted e-mail, e-mail got imported, but not the phone. What was the cause? I was specifying value first, then type, and it seems google's import mechanism needs a bit stricter format. So finally, the works-for-me solution was:
  • Given Name - the first name
  • Family Name - the surname
  • Name - the displayed name
  • E-Mail 1 - Type - "Home" (or "Other")
  • E-Mail 1 - Value - e-mail
  • Phone 1 - Type - "Mobile"
  • Phone 1 - Value - phone number
  • Notes - additional info about contact

Tuesday, November 22, 2011

Invitation to StackOverflow

I'd like to invite every programmer to join StackOverflow and other StackExchange sites. Not only to create account and ask some question from time to time, but to active participation. Let me expain why it is worth your effort.

First of all, StackOverflow is a great place to get answered. If you have a problem involving programming, it's one of the places where you have very high chance to get answer with high quality. But in order to be answered, there must be someone that answers the questions. Portal is free, you need not pay for asking questions, so nobody is paid for giving answers. At least not in money. But you have the reputation, which measures your involvement in StackOverflow community. Users with high reputation are authorities for others. The same mechanism works on various foras, but there the user is authority for the people that knows him. Reputation is the mechanism, which can tell, that someone is worth your trust, even if you've never heard of him. It allows the StackOverflow to work as really big community.

You may ask, why should you care about reputation? Does the high reputation increase your chance to get answered? Well, if you have a lot of reputation, it means you are active and you are helping people, so you are worth spending time solving your problem. However, most people just answer questions that are good and interesting, illustrated with code examples, and ignoring those that are poor (how-to-do-that pattern). But if you have a lot of reputation, you can set bounty to your question, which sacrifice some of your reputation points, but greatly increase chance for your problem to be noticed and solved.

Many people engage in community and solve other people's problems just for satisfaction that they may be helpful and their engagement will be noticed and appreciated. The best way of showing your appreciation is to vote up good answers (and good questions too). You should do it obligatorily if someone gives helpful answer to your question, but also to answers to other questions, which you find good. The rule should be, when you search for some problem in internet and get to StackOverflow - you should vote up question (for being asked and relieving you from asking it yourself). If you find some answer that is helpful to you - you should vote it up. The rule for you should be - if you read something, and you find it good - you upvote. Number of upvotes is limited per day, but it usually should not be a problem. If it is, you can write the other links down and upvote it the next day. Not used upvotes are lost and they could be used for encouraging users to participate.

Except from satisfaction, StackOverflow is a great place to promote yourself. Please note - you can post links to your blog or webpage in questions and answers, if they are good illustration to the problem - that gives you visitors and increases your SERP rating. You can promote your web page and yourself in your profile. Each your post points to your profile. When you give good answer, it is cited, which gives you a lot of links to it inside portal. StackOverlfow is very good positioned in search engines, so there's really much to win.

I personally, when I'm searching for answers on particular topic, when I find something interesting on StackOverflow or one of other StackExchange sites, I'm alway voting up both the answer and the question. When I find some interesting technical article, which I find useful, I always 'like', '+1' and 'digg' it, when available. It's the way to reward the author for his work.

Thursday, March 12, 2009

What is annoying in power supplies.

The thing that annoys me often are cables.  Network cables, USB cables. But the worst are power supply cables, and AC's. There are many small devices, each taking a few wats, but each must have its own power supply cable and very big AC. It's a hard task to plug all of them. Big plugs simply collide.

There is a modem, router and wireless phone, that is 3 AC's. And handy charger (4), and battery charger (5). 

Would be that so hard to develop one standard for supplying power to small devices? There could be then one AC with small cables for all devices plugged into it (such as network cables to switch).  Such universal power supply could contain battery charger and could be less power-consuming.

I would be most pleased having such a device:
A wireless VOIP router connected to wireless handset (I have VOIP router and wireless phone as separate device, with phone cable connecting them and surplus power supply cable), containing slots for charging batteries and sockets to plug in power cables to other devices (such as handy charger etc.). 

I thing USB gadgets are so popular because they do not require additional power supply :)

Every AC means surplus power consumption, and additional costs. Computer-dependend devices such as monitors and printers could also drain power they need directly from computer's AC, optimally via the same cable they send data, so there would be another cable less.

Oracle & temporal types

When considering Oracle temporal types, most people think of TIME type and DATE type (which is date + time).
I was a bit suprised to find out that Oracle 10 supports INTERVAL type and temporal operator OVERLAPS.
Intervals are quite simple. There is INTERVAL DAY TO SECOND and INTERVAL YEAR TO MONTH support. 
Example:
INTERVAL '5' DAY is 5 days.
INTERVAL '5 01:00:00' is 5 days and 1 hour.
INTERVAL '1' YEAR is one year.
INTERVAL '1-2' YEAR TO MONTH is one year and 2 months.
INTERVAL '12' MONTH is 12 months.
I don't know what is INTERVAL YEAR TO MONTH for. In what case when operating on ISO dates one year would be something different from 12 months. The most interesting, in my opinion, would be INTERVAL MONTH TO DAY and INTERVAL MONTH TO WEEK, because operating on days/weeks and months simultanously is the most problemating.

OVERLAPS operator is less interesting. It can be used only in WHERE clause and returns true when 2 periods, defined as (date-from, date-to), overlaps.
When overlapping is considered, periods are defined as exclusive sets
so (date '2009-01-01', date '2009-01-10') OVERLAPS (date '2009-01-10', date '2009-01-20') is NEGATIVE. Inclusive treating of periods by OVERLAPS operator would be very problematic to handle, considering we operate on timestamps. However, when we treat DATE field as date (not date with time) and take care that time part is '0', OVERLAPS is not very handy. From my operations, it does not make temporal queries more effective.