jeudi, mars 10, 2011

Scala TreeSet: foreach vs foldLeft

Here is the best article I found to understand what is foldLeft. And here is an example on how to replace foreach with foldLeft:


class KbdKey() {
  def generateQuartets(): ListSet[Quartet] = {...}
}

class KbdMatrix() {
  var ts_keys = new TreeSet[KbdKey]()

  var l_quartets = ListSet.empty[Quartet];
  ts_keys.foreach(l_quartets ++= _.generateQuartets())

  // 2 lines above can be replaced by the line below

  val l_quartets = ts_keys.tail.foldLeft(ts_keys.head.generateQuartets)(_ ++ _.generateQuartets)
}

mercredi, mars 09, 2011

Scala Treeset example: partition

var ts_keys = new TreeSet[KbdKey]()(new CompareRowThenCol())

val (ts_inferiorOrEqualRowKeys,ts_superiorRowKeys) = ts_Keys.partition(_.i_row<=i_row)

class CompareRowThenCol extends Ordering[KbdKey] {
    def compare(k1: KbdKey, k2: KbdKey) = k1.value-k2.value
}

lundi, mars 07, 2011

Scala Treeset example: filter, groupBy, foldLeft, sortBy, etc...

A scala example doing various operations on a TreeSet containing keys organized in rows and columns and who have a certain type. Output is an html table.

def myPrint(i_type: Int, ts_keys: TreeSet[KbdKey]) {

  val lcol = (0 to 16)

  print(lcol.tail.foldLeft("Column [" + lcol.head +"]")(_ + "Column [" + _ +"]"))

  val ts_matrixFilteredByType = ts_keys.filter((k: KbdKey) => k.i_type==i_type)

  val m_matrixGroupByRow = ts_matrixFilteredByType.groupBy((k: KbdKey) => k.i_row)

  val m_matrixGroupBySortedRow = ListMap(m_matrixGroupByRow.toList.sortBy{_._1}:_*)

  m_matrixGroupBySortedRow.foreach((p:(Int, TreeSet[KbdKey])) => 
    print(p._2.tail.foldLeft("Row["+p._1+"]" + p._2.head.myprint)(_ + _.myprint) +"-"))
}

Things to notice are:
  • use of foldLeft to do some printing and not some plain summing "as usual".
  • groupBy returns pairs.

Scala and Java libraries in Eclipse

Don't try to mix scala and java in the same scala project in eclipse. You will 1st have the feeling that it works, but as they are not compiled the same way, it's better to have java and scala files in separate projects. Scala project should have the java project as a dependency.

To get it working, you have to do a lot of project cleaning, to "synchronize" both projects.

A Scala file using a Java class:
   import kbdmatrix_java._
   class KbdMatrix(val L: MyLog) {

The Java file:
   package kbdmatrix_java;
   public class MyLog {

Do not forget to advertize the Java class and its methods as public.

Scala: code to find worksheet name in an excel workbook saved in microsoft xml 2003 format

Scala: code to find worksheet name in an excel workbook saved in microsoft xml 2003 format:
def matchName(n: scala.xml.NodeSeq, s_attributeValue: String): Boolean = {
  n match {
            case xml.Elem(_, "Worksheet", xml.PrefixedAttribute("ss", "Name", v, _), _, _*) => 
                 if(v.text==s_attributeValue) true else false
            case _ => false 
  }
}

mercredi, février 23, 2011

Encryption is useless



What actually happened (Cnet 23Feb2011): Feds seek new ways to bypass encryption
SAN FRANCISCO--When agents at the Drug Enforcement Administration learned a suspect was using PGP to encrypt documents, they persuaded a judge to let them sneak into an office complex and install a keystroke logger that recorded the passphrase as it was typed in.

Read more: http://news.cnet.com/8301-31921_3-20035168-281.html#ixzz1EoUlHQa9

samedi, janvier 15, 2011

HTML5 & CSS3 READINESS

Here is an interestzing way of displaying information I found at http://html5readiness.com/
Click on the image below to dynamically see data:

vendredi, janvier 07, 2011

Dimensions Treemap using Protovis

Based on Treemap from protovis design in javascript, I have now a treemap with 3 dimensions.

Click on the image below to see it in action (because my post does not allow it to be dynamically displayed).



3 Dimensions are:
  1. definition of groups that share the same kind of color
  2. each square with it's area
  3. each square is more or less dark and more or less saturated
This is something that you I use to display a status of issues on a bunch of projects. For instance we develop several keyboards and mice at the same time.
  1. The yellow group of color could group all keyboard projects.
  2. square area is proportional to the total number of bugs for this project
  3. square darkness and saturation/alpha is proportional to the number of open bugs for this project

lundi, décembre 27, 2010

Chinese language to dominate the internet

What is interessant in the format of this visualization is earth at the center that stresses the fact that we are talking about world wide statistics.

We can also notice how internet growth in China is presented as a subset of the first graph.

jeudi, décembre 09, 2010

How to conduct a braimstorming session

Before brainstorming session:
·         Define a one sentence clear and focused objective.
·         Choose participants
o    Select a diverse and eclectic team
o    assign leader role (who is also a timekeeper)
o    assign script role (to write ideas on whiteboard)
·         Prepare material
o    whiteboard
o    clean wall
o    lots of post-it notes and markers

During actual brainstorming session:
1.     Write the one sentence clear and focused objective on white board
2.     Let wild ideas flowing
·         script writes ideas as they come on another whiteboard (meanwhile ideas are also written on post-it notes)
·         probably ideas will start with the most rational ones, but don't stop at the 1st good idea that comes, spend more time than you think, letting people write and post their ideas
3.     Classify/group ideas written on post-it notes by main topic
4.     Precise/detail main objective in SMART statements
5.     Remove ideas that cannot fit SMART objective 
6.     Vote on remaining ideas
  1. Assign actions items to follow on most promising ideas

lundi, novembre 01, 2010

Logitech Wireless Solar Keyboard K750 Firmware

Our keyboard embedded software team built the firmware for the Logitech Wireless Solar Keyboard K750. It was a tough project, because while we have extensive experience at Logitech Switzerland to use and manage regular and rechargeable batteries, here, we entered new area ... under the Sun.


Here are some of the new challenges that we had to tackle:
  • How much solar cell space do we need for an average user?
  • Who is the average user, someone living at the equator or a norvegian living above the polar circle?
  • Where do people work at home, in a cellar or near a wide window?
  • How long shall the keyboard work in total darkness?
  • How big should we make the energy reserve?
  • How to increase "battery" life by decreasing power consumption while keeping good keyboard performance?
The small energy reserve (a button battery) has electrical characteristics that are quite different from the batteries we were used to (especially the battery internal resistance). This had great impacts on the firmware which was "asked" to optimize power consumption, latencies, etc...

For instance we cut power supply if you leave a book on your keyboard. If we did not do that, you would temporary "kill" your keyboard until sufficiently recharged, which may take quite a long time depending on the light it gets.

We also worked closely with the software team for defining and developing a solar widget. We added a very basic "luxmeter" to measure the light that the solar cells are receiving. This is a gadget that was not required to have the keyboard working, but we felt it was a nice to have for users. Now for those who are using the keyboard at Logitech, we like to measure our light environment from time to time.

I hope we tackled all issues successfully. The customers will tell us, and we are eager to get their feedback through forums or Amazon.
Read more on Logitech's blog here.

vendredi, octobre 29, 2010

A history of world GDP

Unknown source :(

What would have been good is to have a definitions of the countries boudaries accross time. Anyway it gives a good idea of the trends.

vendredi, septembre 24, 2010

generating Innovation by linking different fields

About the T9 inventor:
King had an uncanny ability to look at problems from various angles, discovering new ways to solve complex issues, recalled Mason Boswell, a Seattle patent attorney who worked closely with the inventor.

“He would often ask questions that connected two fields in a way I had not thought of but that clearly pointed the way to interesting innovation,” said Boswell. “He also had a point of view five to 10 years into the future, thinking about devices in a way that transcended current hardware limitations and going more to what could be common down the road.”

Read also about Triz: http://en.wikipedia.org/wiki/TRIZ

lundi, juillet 26, 2010

Creativity is not top priority for the emergence of an innovation culture

Posted by: innovtoday @ http://innovtoday.wordpress.com/2010/07/06/creativity-is-not-top-priority-for-the-emergence-of-an-innovation-culture/

An injection of creativity serum for all employees – if such a thing was ever invented – is not what the enterprise seeking to become more innovative needs ... So, if it is not creativity, what will make the difference? My top-three critical success factors are:

* Setting the strategic challenge
* Getting out and making connections
* Driving ideas through the stage-gate.