Wednesday, August 15, 2012

"datastore: invalid entity type"

The below error message is defined in datastore package of AppEngine.
ErrInvalidEntityType = errors.New("datastore: invalid entity type")
If by the accident one wrote:
data := Data{}
err := datastore.Get(c, key, data)

One will get above error message. The correct code looks as below:
data := Data{}
err := datastore.Get(c, key, &data)

The change is third passed parameter.

According to doc:
Get loads the entity stored for k into dst, which must be a struct pointer or implement PropertyLoadSaver.

Friday, August 10, 2012

Simple RegExp in Go

package main

import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile("/page/(?P[\\d]+)/")
  b := []byte("/page/1/")
  x := re.Find(b)
  fmt.Printf("Found: `%s`\n", x)
  x1 := re.FindAll(b, 100)
  fmt.Printf("Found: `%s`\n", x1)
  fmt.Printf("Subexp num: `%d`\n", re.NumSubexp())
  x2 := re.FindAllSubmatch(b, 100)
  fmt.Printf("Found: `%s`\n", x2)
  fmt.Printf("Subexp names: %s", re.SubexpNames())
}

And output:
Found: `/page/1/`
Found: `[/page/1/]`
Subexp num: `1`
Found: `[[/page/1/ 1]]`
Subexp names: [ pagenr]
You can try it here: http://play.golang.org/p/SqUe4X7vuR

Monday, June 18, 2012

Turn off "Pissing off flash content".

Have you ever experienced that annoying sound when you enter a web page? Probably not just once. But, there's a solution waiting for you to apply!

If you use Google Chrome, go to chrome://chrome/settings/content and in a section "Plug-ins" check option "Click to play". The flash content will be run only if you click on it. Additionally click "Manage exceptions..." and add domains for which you want to allow/deny flash (e.g. www.youtube.com).

Now you can browse in peace ;-)

Friday, April 20, 2012

Remove "edit" link from wiki site.

Paste below code to JavaScript console.
f = function(l) {
  for(var i = 0; i < l.length; i++) {
    var c = l[i];
    c.parentNode.removeChild(c);
  }
};

f($('.sectionedit'));

Wednesday, April 18, 2012

What every software engineer have to know

Being innovative and creative is a big advantage in a software world. Being ignorant is a curse. The basic principle is "you will never implement something what is already implemented unless...".

  1. Current implementation isn't enough and can't be easily adjusted to your needs.
  2. Current implementation is totally crap and you need implement it from scratch.
  3. You have a lot of time or money and can do it better (don't even dream about time).
  4. You can really make it better.
Anyway, to identify any of those there is one big prerequirement: you have to know about existing solutions: designs, architectures and libraries!

Sunday, April 15, 2012

Singleton in JavaScript with Google Closure library and compiler

I'm writing a small WebApp. I want to a create singleton. Probably there is a dozen different way to implement it in JavaScript. As I became a fan of Google technologies I will show two solutions how it can be easily implemented using Google Closure.

Thursday, February 9, 2012

vim notes

Replace bracket indexing by member indexing.
:%s/variable\['\(\w\+\)'\]/variable.\1/gc
And more general:
:%s/\['\(\w\+\)'\]/.\1/gc
Change: "smth1 = smth2; " to "smth2: 'smth1',". :%s/\W*\(.*\) = \(.*\);/ \2: '\1',/gc