Tuesday 26 April 2011

A selection of gesture interactions using Kinect




CSS good practices

Found two interesting slides about good CSS practices from Nicole Sullivan. Here are some points about examining our best practices myths rationally that I think are really nice:
Myths Rational Rethink
Don't add any extra elements Add non-semantic elements judiciously
Use descendant selectors exclusivelyKeep specificity as low as possible
Use specificity to define your architecture
Don't add classes (Classitis)Abstract repeating visual patterns into class


A video of her presentation on this topic at WebStock.



Two main principles of object oriented CSS:
1. Separate structure and skin
2. Separate container and content: break the dependency between the container module (contour blocks, background blocks) and the content objects (headings, paragraphs, lists, headers, footers, buttons, etc) it contains.

Best practices:
1. Build HTML from component library
2. Extend objects by applying multiple classes to an element
3. Use classes for style. Save ids for JavaScript
4. Be flexible: extensible height and width -> Grids control width; content control height
Nicole Sullivan's original blog post.

Sunday 24 April 2011

Romanian

Useful phrases:
La mulți ani: Happy Birthday!
Noapte bună: Good night!
Bună dimineața: Good morning!
Bună ziua: Hello!

Tuesday 19 April 2011

Java: compare different methods for copying BufferedImage

Tested with copying a 640x480 RGB image.
// Fastest method (0-1ms).
public void copy1(BufferedImage src, BufferedImage dst) {
  int[] srcArray = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
  int[] dstArray = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
  System.arraycopy(srcArray, 0, dstArray, 0, srcArray.length);
}

// Second fastest (7-8ms).
public void copy1(BufferedImage src, BufferedImage dst) {
  int[] srcArray = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
  dst.setRGB(0, 0, dst.getWidth(), dst.getHeight(), srcArray, 0, dst.getWidth());
}

// Slowest method (18-19ms).
public void copy1(BufferedImage src, BufferedImage dst) {
  dst.setData(src.getData());
}

Java object reference is passed by value

Today I spent a whole afternoon debugging a piece of Java code. The code is something like this:

public void captureNow(BufferedImage image) {
  try{  
    image = ImageIO.read(new File(getRecordeDir() + files[index++])); // only changes the local variable image.
  } catch (IOException ioe) {
    System.err.println(e.getMessage());
  }
}

BufferedImage bi = new BufferedImage(width, height, type);
captureNow(bi); // bi does not change.

After calling captureNow(bi), bi didn't get the image that supposed to be read. The problem here is I got confused with C++. Even though Java is pass by reference, it does not mean the same thing as in C++. Here in Java, the local variable image got the address of bi. In side the method, image is assigned another address, but this does not affect bi. In C++, a reference is automatically dereferenced to point to the actual object. Hence, an assignment will affect the actual object passed.

Edit:
As a reader pointed out, here is a good explanation about Java's pass by value.

Monday 18 April 2011

Setting permissions of a Windows partition in Ubuntu

My Windows partition is in NTFS format which does not support chmod or chown for changing file permissions and ownership. These are set at the time of mounting. If I click the partition icon to mount it, the default permission does not allow execution. To change the mount settings, you need to edit the /ect/fstab file which is a system configuration file and is used to tell the Linux kernel which partitions (file systems) to mount and where on the file system tree.

Here is an example of a configuration to add to the fstab file:
/dev/sda4 /media/WinData ntfs uid=<user_name>,exec,fmask=037,dmask=027 0 0

fmask and dmask change the permissions of files and directories respectively. The numbers represent the permissions to turn off, and  4, 2, 1 represents read, write and execute respectively.

After setting this, the partition needs to be mounted by root using mount command line.

For more details, see this post: http://ubuntuforums.org/showthread.php?t=283131

Sunday 10 April 2011

Ruby: metaprogramming

Definitions
Singleton method: a method defined on a particular object
Singleton class: the anonymous class created in which a singleton method is defined

Object Model
  • Instance variables live in objects, and methods live in classes.
    • You can get a list of object's methods by calling obj.methods.
    • For a class, you can call klass.methods to see what class methods are available, and klass.instance_methods to know the instance methods. klass.instance_methods(false) returns methods defined by the class and not inherited.
  • Classes themselves are nothing but objects, and have their own class called Class.
    • All classes ultimately inherit from Object.
      "hello".class # => String
      String.class # => Class
      Class.instance_methods(false) # => [:allocate, :new, :superclass]
      # :superclass is only a method a class, not an object. 
      String.superclass # => Object
      
  • The methods of an a class are the instance methods of Class.
Self
  • Every line of Ruby code is executed inside an object - the so-called current object. The current object is also known as self.
  •  In a class or module definition, the role of self is taken by the class or module.
Singleton Methods
  • Class methods are Singleton Methods of a class.
  • Introspection methods:
    • singleton_methods returns all the singleton methods for the object (also the ones in included modules).
    • singleton_methods(false) returns all the singleton methods for the object, but not those declared in included modules.
    • methods(false) supposedly returns the singleton methods by calling singleton_methods, but it also passes the parameter false to it.
      String.methods(false) == String.singleton_methods(false) # => true

Saturday 9 April 2011

Convert ogv to wmv

Yesterday, I was trying to insert a video clip into a PowerPoint presentation. The video was recorded using recordMyDesktop under Ubuntu and is a .ogv file. PowerPoint does not support this format. So I need to convert it to either AVI or WMV format.

.ogv is one of the extensions used for files whose content use the Ogg container format. In particular, .ogv is used for video with or without sound. As PowerPoint supports AVI format and I can also play AVI file in Ubuntu, so I converted the .ogv file to .avi file using ffmpeg using the following command:

$ ffmpeg -i shutter.ogv -vcodec mpeg4 -acodec libmp3lame -sameq shutter.avi

However, when I opened the .avi file in Windows XP, it doesn't play in PowerPoint or in the DivX player. I thought there may be some incompatibility in the file made in Ubuntu, so I tried to convert the .ogv file to .avi or .wmv in Windows XP. I tried several software including ffmpeg and WinFF for Windows but the resulted file's quality is very bad. In the end, what worked is converting the .avi file I made in Ubuntu to .wmv using WinFF.