11/28/2013

scipy optimize curve_fit fitting to cumtom function


ref:  http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

>>> import numpy as np
>>> from scipy.optimize import curve_fit
>>> def func(x, a, b, c):
...     return a*np.exp(-b*x) + c
>>> x = np.linspace(0,4,50)
>>> y = func(x, 2.5, 1.3, 0.5)
>>> yn = y + 0.2*np.random.normal(size=len(x))
>>> popt, pcov = curve_fit(func, x, yn)

11/23/2013

PyQt4 solution for 한글 path name unicode problems


tmp = QFileDialog.getOpen...(....)

Here, QString "tmp" contains 한글 characters. Therefore..

print tmp -> make error
print unicode(tmp) -> OK


and if one want to print out to a textbox ..

ui.textbox.setText(tmp) -> error
ui.textbox.setText(unicode(tmp)) -> OK


some other ...

os.chdir(tmp) -> error
os.chdir(unicode(tmp)) -> OK

10/14/2013

HOWTO use malgun.ttf font in dokuwiki dw2pdf plugins


1. Copy malgun.ttf and malgunbd.ttf to dokuwiki/lib/plugins/dw2pdf/mpdf/ttfonts/
2. Ensure the dokuwiki/lib/plugins/dw2pdf/mpdf/config.php file contains :

$this->useAdobeCJK = false;

** If the value is true, it forces using AdobeCJK font even if a user modify the css file and config-fonts.php file.

3.  Add the following lines to dokuwiki/lib/plugins/dw2pdf/conf/style.local.css file:

body {
    font-family: malgun;

4. Open dokuwiki/lib/plugins/dw2pdf/mpdf/config-fonts.php, find "$this->fontdata = array(", and add the followings :

"malgun" => array(
'R' => "malgun.ttf",
'B' => "malgunbd.ttf",
'I' => "malgun.ttf",
'BI' => "malgunbd.ttf",
), 

...

9/10/2013

python datetime timedelta



import datetime

tmp1 = date1 + date2
tmp2_bool = date1 > date2 # return True
today = datetime.date.today()
five_days_after = today + datetime.timedelta(days=5)
seven_days_before = today - datetime.timedelta(days=7)
seven_days_five_hours_before = today - datetime.timedelta(days=7, hours=5)
date1 = datetime.timedelta(hours=5) # 5 hours later from now
date2 = datetime.timedelta(days=-5) # 5 days earlyer from today


.

9/09/2013

correction of mem leak of django + apache


The code below consume large memory and don't return.
Apache process memory will keep increasing with the code below.


aaa = data.objects.all().order_by('-id')
count_of_aaa = len(aaa)

The problem is "len(aaa)". (dunno why)
It should be replace by ...

count_of_aaa = aaa.count()

Then no mem leak occur.