Виртуальная песочница (тм)

Thursday, August 21, 2008

Number to month name


echo form_label('Month: ');
$options = array(
'0' => 'New',
'1' => 'January',
'2' => 'February',
'3' => 'March',
'4' => 'April',
'5' => 'May',
'6' => 'June',
'7' => 'July',
'8' => 'August',
'9' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December',
'13' => 'I'm an idiot!',
);
Read more...

Wednesday, August 20, 2008

The March of Progress

1980: C

    printf("%10.2f", x);

1988: C++
   cout << setw(10) << setprecision(2) << showpoint << x;

1996: Java
   
java.text.NumberFormat formatter
= java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++) System.out.print(' ');
System.out.print(s);

2004: Java
   System.out.printf("%10.2f", x);


[Cay Horstmann's Home Page]

Read more...

Thursday, August 14, 2008

Encoding Recipe

Q: знатоки, подскажите, как из строки типа "Привет" получить "\u0441\u043b\u0443\u0445\u0438"?
A: на C это делается так:
if (str == "Привет") str = "\u0441\u043b\u0443\u0445\u0438"; Read more...

Tuesday, August 5, 2008

Transaction management and JPA

"My current project is a web application with Struts in the web tier, a stateless session EJB (EJB3) in the middle tier and various entity pojos (JPA) that model the data. The application server is JBoss 4.2.0.CR2 that uses Hibernate as the persistence provider.

In this configuration with container-managed transactions, the transaction boundary is the EJB method call. Struts action classes make calls to the session EJB methods in order to retrieve data for display in various JSPs. The problem is that after the EJB method returns, the transaction is over, the persistence context has ended and the POJOs returned are detached. If the JSP that displays the data tries to access any lazily loaded associations an exception occurs."

Read more...

At least we all understand each other on Wednesday

http://www.unbound.ru/pict/cows.gif Read more...

Friday, August 1, 2008

"Довольный, как слон после купания"

Когда я говорю сабж, я имею в виду примерно следующее:
69,15 КБ Read more...

Monday, July 28, 2008

The Excel Monkey

Вариация известного анекдота. В оригинале первая обезьяна умела кодировать на С, вторая в дополнение знала C++, Java и OOP, а третья была project manager'ом.

A tourist went into a pet shop and started looking around. While he was doing so, a customer came in and said to the shopkeeper, "Do you have an Excel monkey?"

The shopkeeper nodded, went over to a cage, and brought out a monkey. He put it on a lead and handed it over to the customer, saying "That will be £3,000." The customer paid and walked out of the shop with the monkey.

The tourist was amazed. He went over to the shopkeeper and said, "That's a huge amount to pay for a monkey. Why on Earth was it so expensive?" The shopkeeper answered, "The monkey can write Excel spreadsheets. It's very quick, never makes mistakes, and knows all the built-in functions. If you need any spreadsheets written, it's just the thing for the job."

The tourist looked at another monkey in the cage. "This one is even more expensive. It's £5,000 — what can it do?" The shopkeeper said, "Oh, that's a Web monkey. It's an expert Web developer, can code interactive pages, handle graphic design, give presentations, everything you need."

The tourist looked around the shop a bit more, and then spotted a third monkey in a cage. The label round this one's neck read £25,000. Dumbfounded, he walked up to the shopkeeper and said: "This costs more than all the others put together! What does it do?" The shopkeeper answered, "Well, I've never actually seen it do anything useful. But the other monkeys call it an administrator."

Read more...