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.

3/25/2013

adobe reader font fix

ref: http://ubuntuforums.org/showthread.php?t=1006831



  1. #1
    MrFSL's Avatar
    MrFSL is offlineDipped in Ubuntu
    Join Date
    Mar 2006
    Location
    Somewhere outside Ubuntu
    Beans
    602

    [SOLVED] Adobe Reader Font Fixed



32bit Hardy Install

I searched the forum and could not find an answer to this problem so I am posting it here. Hopefully it helps some people.

I use the adobe reader 8.1.3 package for pdf files:
Located Here

I have noticed that often I get errors saying that a certain font cannot be displayed. This happens frequently with Microsoft fonts like Arial,Bold or Arial,Narrow. In the reader these fonts come out as little black dots instead.

I simply could not find a fix here nor on the Adobe forums. After some hacking though I have a solution:

First install the msttcorefonts package (if you haven't already)
Code:
sudo apt-get install msttcorefonts
Next edit the the reader's startup file:
Code:
sudo gedit /opt/Adobe/Reader8/bin/acroread
And uncomment these two lines:
Code:
ACRO_ENABLE_FONT_CONFIG=1
export ACRO_ENABLE_FONT_CONFIG
Now reader acts as should be expected.