2016年4月18日 星期一

[python] python 3.x , date itreating from start date to stop(today) date.


from datetime import datetime,timedelta


def daterange(begin, end, delta = timedelta(1)):
    """Form a range of dates and iterate over them.

    Arguments:
    begin -- a date (or datetime) object; the beginning of the range.
    end   -- a date (or datetime) object; the end of the range.
    delta -- (optional) a timedelta object; how much to step each iteration.
             Default step is 1 day.

    Usage:

    """
    if not isinstance(delta, timedelta):
        delta = timedelta(delta)

    ZERO = timedelta(0)

    if begin < end:
        if delta <= ZERO:
            raise StopIteration
        test = end.__gt__
    else:
        if delta >= ZERO:
            raise StopIteration
        test = end.__lt__

    while test(begin):
        yield begin
        begin += delta


def main():

    start = datetime(2010, 1, 1,19,00,00)
    stop = datetime.today()
    for x in daterange(start,stop):
        # only when today, it need to download after 7:00pm, so force the start date all is 19:00:00
        if(stop > x):
            #print(stop,x)
            year=str(x.year)
            month=str('%02d' % (x.month))
            day=str('%02d' % (x.day))

            download_xxxxx_from_web(year,month,day)

        else:
            print('For ',x,'Need to wait to 7:00')
    return


main()


2016年4月14日 星期四

[Ubuntu 14.04.1] 解決Chrome/ Firefox字體變成標楷體或者新細明體的問題


[Ubuntu 14.04.1] 解決Chrome/ Firefox字體變成標楷體或者新細明體的問題

fonts-arphic-ukai,fonts-arphic-uming
這兩個套件

移除他即可

# sudo apt-get remove fonts-arphic-ukai && sudo apt-get remove fonts-arphic-uming



***** logout, login again

[ubuntu] 14.04 install 酷音

1.安裝酷音

sudo apt-get install ibus-chewing

2.

logout, login again, go to text entry , and add

Chinese (Chewing)

 

2016年4月12日 星期二

[python] python numpy static , sum, mean, std (axis = dimension)


a = np.array([[1, 2], [3, 4],[5, 6]])

print('-------------------')
print(np.sum(a))
print(a.sum())
print(a.sum(0))
print(np.sum(a,axis=0))
print(np.sum(a,axis=1))
print('-------------------')
print(np.mean(a))
print(a.mean())
print(a.mean(0))
print(np.mean(a, axis=0))
print(np.mean(a, axis=1))

print('-------------------')
print(np.std(a))
print(a.std())
print(a.std(1))
print(np.std(a, axis=0))
print(np.std(a, axis=1))


output:
-------------------
21
21
[ 9 12]
[ 9 12]
[ 3  7 11]
-------------------
3.5
3.5
[ 3.  4.]
[ 3.  4.]
[ 1.5  3.5  5.5]
-------------------
1.70782512766
1.70782512766
[ 0.5  0.5  0.5]
[ 1.63299316  1.63299316]
[ 0.5  0.5  0.5]
[Finished in 0.1s]



ps: axis 0 means do operator in each column individual. (first dimension.) 
 
print(np.sum(a,axis=0))
  
[1,2]
[3,4]
[5,6] 

=[1+3+5 , 2+4+6]= [9,12]
 
axis 1 means to operator second dimension.  
 
print(np.sum(a,axis=1)) 

=[1+2,3+4,5+6]=[3,7,11]
 
 
 
 
 
---------------------
a = np.array([[1, 3,3, 4, 5, 6],[1, 3,3, 4, 5, 6]])
b = np.array([[1, 2,3, 4, 5, 6],[1, 1,1, 1, 1, 1]])
print(a)
print(np.mean(b, axis=0))
print(a-np.mean(b, axis=0))
 
[[1 3 3 4 5 6]
 [1 3 3 4 5 6]]

[ 1.   1.5  2.   2.5  3.   3.5]

[[ 0.   1.5  1.   1.5  2.   2.5]
 [ 0.   1.5  1.   1.5  2.   2.5]]
[Finished in 0.1s 
 










2016年4月7日 星期四

[python] python 3.4 Ubuntu 14.04 install scikit-learn by building from source code.

0.Optional, If you needed....

sudo apt-get install build-essential python3-dev python3-setuptools \
                     python3-numpy python3-scipy \
                     libatlas-dev libatlas3gf-base




1. download scikit-learn source code form

https://pypi.python.org/pypi/scikit-learn/0.15.2#downloads


The same as below, download the first one, scikit-learn-0.15.2.tar.gz

and extract it in your downloaded folder.



2. go to the extracted folder , and build it.

xxxxx/Downloads/scikit-learn-0.15.2$ python3.4 setup.py install --user

 








**if you get the error


 x86_64-linux-gnu-gcc: error: unrecognized command line option ‘-fstack-protector-strong’

 (Solution A:)
edit the below file by sudo

/usr/lib/python3.4/plat-x86_64-linux-gnu/_sysconfigdata_nd.py 

=>this file is belone libpython3.4-minimal package, if you don't have it,
install that.



and replace "all"  -fstack-protector-strong  to -fstack-protector

and saved.


and use the build command above again....

$  python3.4 setup.py install --user





 (Solution B:)
upgrade gcc to 4.9 (I don't want to do that.....)
















































































2016年4月1日 星期五

[IDE] Sublime text 3 , editing config for myself. Tabs to spaces, trim white space when save, draw white sapce for notice.



1. go to  submits -> preferences -> settings - user

copy and pasted below config.


{
    "draw_white_space": "all",
    "font_size": 14,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "auto_match_enabled": false,
    "use_tab_stops": false
}



2.  TrailingSpaces-master package.
Optional: highlight the white space with red color.
 (But in fact, space will be trim when you save file as above setting.)

Go to github to download the zip file for whole project on the right buttom

https://github.com/SublimeText/TrailingSpaces

then extract that and you can see the folder  TrailingSpaces-master.

Go Submits =>Preferences => Browser Packages

Then move the folder TrailingSpaces-master in to the folder which Submits jumped out.

Which means you should pasted TrailingSpaces-master folder in to

sublimes-text-3/Packages/

and place with the /sublimes-text-3/Packages/User folder together.


It will seem like....


xxxx:~/.config/sublime-text-3/Packages$ pwd
/home/xxxx/.config/sublime-text-3/Packages

xxxx:~/.config/sublime-text-3/Packages$ ll
total 24
drwx------  6 xxxx xxxx 4096  3月 22 14:43 ./
drwx------  7 xxxx xxxx 4096  3月 15 17:29 ../
drwxrwxr-x 11 xxxx xxxx 4096  3月 22 14:43 bz2/
drwxr-xr-x  7 xxxx xxxx 4096  3月 15 17:32 ssl-linux/
drwxrwxr-x  3 xxxx xxxx 4096 10月 27 22:54 TrailingSpaces-master/
drwx------  3 xxxx xxxx 4096  3月 29 09:52 User/



You are good to go.