how to switch email google appengine appcfg

python appcfg.py –email your-email@gmail.com –no_cookies update your-app-id

–no_cookies is very important na ja

Posted in Uncategorized | Tagged , , , | Leave a comment

How to import existing Android project into Eclipse

1. import > Existing Project into workspace
2. Properties > Android
Checked ! ” Project Build Target : Android 3.0 “
Apply
Very Important !! You have to apply first before going to next step.
3. Properties > Java Build Path
Libraries
Add Library
> Android Classpath Container

Posted in Uncategorized | Leave a comment

Better Javascript

Loop
1.

for (i = 0, max = myarray.length; i < max; i++) { 

2.

Count down to 0, is usually faster
it’s more efficient to compare to 0 than to the length of the array or to anything other than 0

For loop

for (i = myarray.length; i--;) {  

While loop
    i = myarray.length;  
while (i--) {  

For in / hasOwnProperty

Adding method to all objs

// somewhere else in the code  
// a method was added to all objects  
if (typeof Object.prototype.clone === "undefined") {  
   Object.prototype.clone = function () {};  
}  

Filter hasOwnProperty
// 1.  
// for-in loop  
for (var i in man) {  
   if (man.hasOwnProperty(i)) { // filter  
      console.log(i, ":", man[i]);  
   }  
}  
/* result in the console 
hands : 2 
legs : 2 
heads : 1 
*/  
// 2.  
// antipattern:  
// for-in loop without checking hasOwnProperty()  
for (var i in man) {  
   console.log(i, ":", man[i]);  
}  
/* 
result in the console 
hands : 2 
legs : 2 
heads : 1 
clone: function() 
*/  

Another pattern to filter

for (var i in man) {  
   if (Object.prototype.hasOwnProperty.call(man, i)) { // filter  
      console.log(i, ":", man[i]);  
   }  
} 

Or
1.

var i, hasOwn = Object.prototype.hasOwnProperty;  
for (i in man) {  
    if (hasOwn.call(man, i)) { // filter  
        console.log(i, ":", man[i]);  
    }  
}  

2.

// Warning: doesn't pass JSLint  
var i, hasOwn = Object.prototype.hasOwnProperty;  
for (i in man) if (hasOwn.call(man, i)) { // filter  
    console.log(i, ":", man[i]);  
} 

eval()

// antipattern  
var property = "name";  
alert(eval("obj." + property));  
  
// preferred  
var property = "name";  
alert(obj[property]);  

same as setTimeOut(), setInterval()
// antipatterns  
setTimeout("myFunc()", 1000);  
setTimeout("myFunc(1, 2, 3)", 1000);  
  
// preferred  
setTimeout(myFunc, 1000);  
setTimeout(function () {  
   myFunc(1, 2, 3);  
}, 1000);  

Here only un remains as a global variable polluting the namespace

console.log(typeof un); // "undefined"  
console.log(typeof deux); // "undefined"  
console.log(typeof trois); // "undefined"  
  
var jsstring = "var un = 1; console.log(un);";  
eval(jsstring); // logs "1"  
  
jsstring = "var deux = 2; console.log(deux);";  
new Function(jsstring)(); // logs "2"  
  
jsstring = "var trois = 3; console.log(trois);";  
(function () {  
   eval(jsstring);  
}()); // logs "3"  
  
console.log(typeof un); // number  
console.log(typeof deux); // undefined  
console.log(typeof trois); // undefined  

eval() can access and modify a variable in its outer scope, whereas Function cannot

(function () {  
   var local = 1;  
   eval("local = 3; console.log(local)"); // logs 3  
   console.log(local); // logs 3  
}());  
  
(function () {  
   var local = 1;  
   Function("console.log(typeof local);")(); // logs undefined  
}());  

string to number
Prevent octal confusion

var month = "06",  
    year = "09";  
month = parseInt(month, 10);  

Alternate string to number
+"08" // result is 8  
Number("08") // 8  

Code convention
Naming globals with all caps can reinforce the practice of minimizing their number and can make them easily distinguishable.

// precious constants, please don't touch  
var PI = 3.14,  
    MAX_WIDTH = 800; 

private with _

var person = {  
    getName: function () {  
        return this._getFirst() + ' ' + this._getLast();  
    },  
  
    _getFirst: function () {  
        // ...  
    },  
    _getLast: function () {  
        // ...  
    }  
};  

Other conventions :

  • private_ : name_, getElements_()
  • _protected properties, __private properties
  • In Firefox some internal properties not technically part of the language are available, and they are named with a two underscores prefix and a two underscore suffix, such as __proto__ and __parent__

ref : tutsplus

Posted in Uncategorized | Tagged , | Leave a comment

K3B burn DVD from iso

Tools > Burn DVD ISO Image

Posted in Uncategorized | Tagged , , , | Leave a comment

Appengine : ‘ascii’ codec can’t decode byte 0xe0 in position 5: ordinal not in range(128)

'ascii' codec can't decode byte 0xe0 in position 5: ordinal not in range(128)

Solution :

Execute setdefaultencoding in Interactive Console at http://localhost:8080/_ah/admin/interactive

import sys
reload(sys); sys.setdefaultencoding('utf-8')

ref : hrstc, gae

Posted in Uncategorized | Tagged , , , | 1 Comment

Scale Space Pyramid

scale invarient : correspondences often requires their comparison where they are seen at different scale

DoG : Different of Gaussian

Integral image can be used to up-scale at constant cost as seen in the right side of picture below.

ref : cornell, surf paper

Posted in Uncategorized | Leave a comment

Convolution basic example

Definition

y(t) = h(t)*x(t) = \int_{-\inf}^{\inf} x(\tau)h(t-\tau)d\tau = \int_{-\inf}^{\inf} h(\tau)x(t-\tau)d\tau = x(t)*h(t)

Discreate form

y(n) = \sum_{m=-\inf}^{\inf}x(n-m)h(m) = \sum_{m=-\inf}^{\inf}h(n-m)x(m)

Properties
1. h(t)*x(t) = x(t)*h(t)
2. h*(g*x) = (h*g)*x

In image processing : two dimensions convolution
h is called convolution kernel or mask

y(m, n) = \sum_{i=-k}^{k}\sum_{j=-k}^{k}x(m+i, n+j)h(i,j)

Sliding kernel throughout the image. If image is like in kernel, we will have peak value of y(m, n). –> roughly use to detect same image ??
The pictures below is a good visualization from Wiki.

ref : hmc

Posted in Uncategorized | Leave a comment

Internal Images Basic Concept

 

At each pixel (x,y), calculate sum of the rectangle [(0, 0), (x, y)]  by using the following formulas

 

Integral Image I_{\Sigma}(X) at location X=(x,y)^T

I_{\Sigma}(X) = \sum_{i=0}^{i <= x}\sum_{j=0}^{j <= y} I(i, j)

 

 

Suppose we want to find sum in D in the picture

D = (A+B+C+D) – (A+C) – (A+B) – A

 

 

ref : cornell

Posted in Uncategorized | 1 Comment

simpson rules อินทิกรัล จำกัดเขต ของกำลังสอง สมบูรณ์

การอินทิเกรท ก็คือ การหา พื้นที่ใต้กราฟ ซึ่งคิดว่า เคยทำกันมาแล้ว

ซึ่ง คุณ มณฑล สุกใส อธิบาย พร้อม พิสูจน์ ได้ดีมากๆ ที่เวป thaifoodscience ซึ่งคำอธิบายในรูปที่ว่า ” ถ้าคิดไม่ออก ก็ทำเป็นสี่เหลี่ยมคางหมูซะเลย ”  ทำให้ระลึกชาติ ได้ดีทีเดียว

ผมจดมาแค่ทฤษฎีนะครับ

Simpson integral rule

รูปและสมการเอามาจาก initmath

\int_{a}^{b} f(x) \, dx \approx \frac{\Delta x}{3}\left[y_{0} + 4 y_{1} + 2 y_{2} + 4 y_{3} + 2 y_{4} + .. + 4 y_{n-1} + y_{n} \right]

สังเกตว่า ตัวแรกกับตัวท้าย ค่าสัมประสิทธิ์เป็น 1

นอกนั้น 4 กับ 2 สลับกัน

ส่วนวิธีเลือกค่า \Delta x ให้เลือกตาม วิธีด้านล่าง โดยการ diff f(x) ไป 4 ที

If |f^{4}(x)| <= M for all x in interval a <= x <= b,
and h = (b-a)/n then

Error <= M * h^4*(b-a)/180

where n is the number of subintervals

Posted in Uncategorized | 2 Comments

Linear Regression using Matrix

ถ้าเรามี Y = \beta_{0} + \beta_{1} X + \epsilon

เมื่อ error \epsilon = N(0, \sigma^{2})

จะได้ว่า \hat{\beta} = (x'x)^{-1}x'Y เมื่อ ‘ คือ transpose นะ เดาเอา

และ s^{2 } = \frac{1}{n-k}(Y-\hat{Y})'(Y-\hat{Y}) เมื่อ hat คือ ค่าประมาณ
n = จำนวนข้อมูลที่นำมาคิด
k = จำนวน params ที่ประมาณ ในที่นี้ มี \beta_{0} กับ \beta_{1} ดังนั้น k = 2

ถ้าไม่รู้เรื่อง ไปใช้ gnuplot แก้เอาก็ได้ ดูตัวอย่าง ที่นี่

Posted in Uncategorized | Leave a comment