免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2014年12月18日 星期四

try ipytho#5 , numpy, array,matrix, vector

//=== numpy support matrix operation by numpy.array
import numpy as np
arr= np.random.rand(3,5)

arr.shape             ### give the dimension of the matrix
Out[80]: (3L, 5L)

print arr
[[ 0.67248573  0.48092984  0.69184439  0.71945406  0.57882278]
 [ 0.79634702  0.02227532  0.77490943  0.36783077  0.98777438]
 [ 0.36116686  0.74907581  0.23774053  0.82991951  0.29351733]]

b=arr.T          ### perform matrix transpose

b
Out[83]:
array([[ 0.67248573,  0.79634702,  0.36116686],
       [ 0.48092984,  0.02227532,  0.74907581],
       [ 0.69184439,  0.77490943,  0.23774053],
       [ 0.71945406,  0.36783077,  0.82991951],
       [ 0.57882278,  0.98777438,  0.29351733]])

b.shape
Out[84]: (5L, 3L)


//=== indexer, i:j , i:j:s
i : j == i : j : 1  --> from i to j with increment step 1 ,  j is not included
i : j : s  --> from i to j with increment step s,  j is not included


 arr[ : , 0]  : get the column 0
 arr[..., :4] == arr[..., 0:4] : get column 0 -- 3 
 arr[..., :5] : get column 0 -- 4 

arr[:, 3:1:-1]
Out[95]: 
array([[ 0.71945406,  0.69184439],
       [ 0.36783077,  0.77490943],
       [ 0.82991951,  0.23774053]])



//=== bracket affect [ ]
arr= np.array([np.random.rand(3,5)])
arr.shape
Out[76]: (1L, 3L, 5L)

arr= np.array(np.random.rand(3,5))
arr.shape
Out[78]: (3L, 5L)

arr= np.random.rand(3,5)
arr.shape
Out[80]: (3L, 5L)




//=== double bracket affect
import numpy as np
arr1= np.array([1,2,3])

type(arr1)
Out[45]: numpy.ndarray

arr1.shape
Out[47]: (3L,)

arr2= np.array([[1,2,3]])
arr2.shape
Out[49]: (1L, 3L)

arr3= np.array([[1],[2],[3]])
arr3.shape
Out[51]: (3L, 1L)

arr4=arr3.T
arr4.shape
Out[53]: (1L, 3L)

arr5= arr1.T
arr5.shape
Out[55]: (3L,)


*** although type(arr1) shows numpy.ndarray ,
arr1 is actually a vector( === column vector === row vector ?)
the transpose of arr1 is still a vector containing 3 elements --> 3-tuple vector
i.e. transpose has no effect on vector

*** arr2 is a row 'vector' (single-row matrix)
*** arr3 is a column 'vector'(single-column matrix)



//=== the built-in list of Python not support transpose
L1=[1,2,3]

type(L1)
Out[61]: list

L1.T
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-62-167a2304fdf0> in <module>()
----> 1 L1.T

AttributeError: 'list' object has no attribute 'T'




LL1=[[1,2,3],[4,5,6]]

type(LL1)
Out[64]: list

LL1.T
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-65-49e25d799db3> in <module>()
----> 1 LL1.T

AttributeError: 'list' object has no attribute 'T'

try ipython#4, animation

//=== matplotlib, animation , ffmpeg
http://nbviewer.ipython.org/url/jakevdp.github.io/downloads/notebooks/AnimationEmbedding.ipynb
http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/

""" ...
C:\Users\bob\Anaconda\lib\site-packages\matplotlib\animation.py:727: UserWarning: MovieWriter ffmpeg unavailable
  warnings.warn("MovieWriter %s unavailable" % writer)
... """

*** need ffmpeg to create mp4 file

https://www.ffmpeg.org/download.html#build-windows
--> http://ffmpeg.zeranoe.com/builds/

-->
dnload & install 7zip
dnload & extract ffmpeg
add ffmpeg/bin  to $Path

[
//=== ffmpeg build for windows
https://www.ffmpeg.org/download.html#build-windows
--> http://ffmpeg.zeranoe.com/builds/


//=== the latest archive of static-build ffmpeg for 32bit linux
http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.latest.tar.gz
]

-->
""" ... Open the command prompt. Enter the command “ffmpeg –version”
If you receive a “libstdc++ -6 is missing” error, you may need to install the Microsoft Visual C++ Redistributable Package, which is available for free from Microsoft.
..."""


--> error
matplotlib\backends\backend_agg.pyc in print_raw(self, filename_or_obj, *args, **kwargs)
    503             close = False
    504         try:
--> 505             renderer._renderer.write_rgba(filename_or_obj)
    506         finally:
    507             if close:

RuntimeError: Error writing to file

--> has probolem with tempfile.NamedTemporaryFile()
use a local file under cwd instead, say , 'myani1.mp4'



//===
https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
http://matplotlib.org/1.4.2/examples/animation/index.html
http://matplotlib.org/1.4.2/api/animation_api.html


//===
import matplotlib.animation as animation
animation.Animation._repr_html_ = anim_to_html

animation.FuncAnimation
animation.ArtistAnimation
animation.TimedAnimation



//=== class matplotlib.animation.FuncAnimation(fig, func, frames=None, init_func=None, fargs=None, save_count=None, **kwargs)

""" ...
Bases: matplotlib.animation.TimedAnimation

Makes an animation by repeatedly calling a function func, passing in (optional) arguments in fargs.

frames can be a generator, an iterable, or a number of frames.

init_func is a function used to draw a clear frame. If not given, the results of drawing from the first item in the frames sequence will be used. This function will be called once before the first frame.

If blit=True, func and init_func should return an iterable of drawables to clear.

kwargs include repeat, repeat_delay, and interval: interval draws a new frame every interval milliseconds. repeat controls whether the animation should repeat when the sequence of frames is completed. repeat_delay optionally adds a delay in milliseconds before repeating the animation.
... """

//=== class matplotlib.animation.TimedAnimation(fig, interval=200, repeat_delay=None, repeat=True, event_source=None, *args, **kwargs)



//=== matplotlib.animation.FuncAnimation(fig, func, frames=None, init_func=None, fargs=None, save_count=None, **kwargs)

*** frames can be

  •    a generator, 
  •    an iterable, or 
  •    a number of frames.


--> data_gen, 25, frames=600

def data_gen():
    t = data_gen.t
    cnt = 0
    while cnt < 1000:
        cnt+=1
        t += 0.05
        yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
data_gen.t = 0

def run(data):
    # update the data
    t,y = data
    xdata.append(t)
    ydata.append(y)
...
animation.FuncAnimation(fig, run, data_gen, blit=True, interval=10,   repeat=False)



def update_line(num, data, line):
    line.set_data(data[...,:num])
    return line,

line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),  interval=50, blit=True)




def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return line,
ani = animation.FuncAnimation(fig, animate, frames=600,
                              interval=10, blit=True, init_func=init)



//=== class matplotlib.animation.ArtistAnimation(fig, artists, *args, **kwargs)

???
""" ...
Bases: matplotlib.animation.TimedAnimation

Before calling this function, all plotting should have taken place and the relevant artists saved.

frame_info is a list, with each list entry a collection of artists that represent what needs to be enabled on each frame. These will be disabled for other frames.
... """



//===  matplotlib.animation.ArtistAnimation(fig, artists, *args, **kwargs)
ims = []
for add in np.arange(15):
    ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),))

im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
    blit=True)


http://matplotlib.org/1.4.2/api/artist_api.html

2014年12月16日 星期二

try ipython#3 , short cut

[Q] how to run ipython notebook cells at one time?
[Q] how to run a whole ipython notebook instead of an indivisual cell?

-->
https://github.com/ipython/ipython/pull/4319
https://github.com/ipython/ipython/issues/2228

* menu:  Cell -> Run All
* keyboard: CTRL M, R shortcut for "run all cells" in the notebook


//=== interrupt
menu: Kernel  -> Interrupt
or
keyboard: Ctrl-m i

//=== restart
menu: Kernel  -> Restart menu
or
keyboard: Ctrl-m .


//===
'dd' to delete a cell

ssh, add key to authorized_keys on ubuntu

clientA, key pair (privkeyA, pubkeyA), ip address ipA
clientB, ipB, key pair to be added
serverC (where sshd is running) ,

assume clientA can  already connect to bob@serverC  via ssh
i.e.
/home/bob/.ssh/authorized_keys already contains pubkeyA
/etc/ssh/sshd_config contains "AllowUsers bob@ipA"

1. on clientB,  create key pair (privkeyB, pubkeyB) via Git Bash
  $ ssh-keygen

2. cp pubkeyB from clientB to clientA via clipboard/email/ftp/...
  pubkeyB is like
  "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDc ... ... "
  * take care not to wrap!

3. on clientA, ssh to connect to serverC via putty
   [session: Data/Auto-login username, SSH/Auth]

* add pubkeyB to  authorized_keys
bob@serverC$ nano .ssh/authorized_keys

* add ipB to sshd_config
bob@serverC$ sudo nano /etc/ssh/sshd_config

* reload sshd config
bob@serverC$ sudo service ssh  reload

4. on clientB, ssh to connect to serverC with privkeyB
[for putty, has to convert privkeyB to .ppk format by puttyGen]


2014年12月12日 星期五

try ipython #2, notebook

//=== http://www.randalolson.com/2012/05/12/a-short-demo-on-how-to-use-ipython-notebook-as-a-research-notebook/

IPython Notebook : seamless integration of text and code



//=== cell types

Markdown cell
Heading cell
Code cell
...


//===
[Q]  how to start ipython notebook from ipython console?

In [1]: notebook
UsageError: too few arguments
In [2]: !ipython notebook
--> dangerous??



[Q] how to stop ipython notebook?
[Q] how to close IPython Notebook properly?

after closing chrome browser,
the kernel is shutdown automatically,
but then
ctl+c does not work , nor other keys function,
the whole terminal console is frozen!
at last
--> kill  python process from Task Manager

//===
[Q] how to start ipython notebook with different profile ?
--> ipython notebook --profile=3h
xxx ipython --profile=3h notebook



[Q] how to view the plot result in noteboook?

http://nbviewer.ipython.org/github/ipython/ipython/blob/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb

%matplotlib inline
--> use the inline backend, which will embed plots inside the Notebook:


//=== http://ipython.org/ipython-doc/1/interactive/nbconvert.html
The command-line syntax to run the nbconvert script is:

> ipython nbconvert --to FORMAT notebook.ipynb
This will convert the IPython document file notebook.ipynb into the output format given by the FORMAT string.

* default format is html
> ipython nbconvert ex1.ipynb
> ipython nbconvert --to markdown ex2.pynb --stdout


a configuration file, say mycfg.py,
"""...
c = get_config()
c.NbConvertApp.notebooks = ["ex1.ipynb", "ex2.ipynb"]
..."""
and using the command:

> ipython nbconvert --config mycfg.py



//=== [Q] how to host ipython on internet?
http://nbviewer.ipython.org/github/minrk/ipython/blob/master/examples/Notebook/Running%20the%20Notebook%20Server.ipynb

""" ...
 Most of the time, users run the notebook server on their local computer using IPython's command line interface.
...
You can also specify the port manually:
> ipython notebook --port 9999

Or start notebook server without opening a web browser.
> ipython notebook --no-browser

... """

//=== Securing the notebook server

* Setting a password
* Encrypt network traffic using SSL

In [1]:
from IPython.lib import passwd
password = passwd("my secret pswd")
password
Out[1]:
'sha1:6c2164fc2b22:ed55ecf07fc0f985ab46561483c0e888e8964ae6'

add the hashed passwd to myconfig.py:

"""
# Password to use for web authentication
c = get_config()
c.NotebookApp.password = u'sha1:6c2164fc2b22:ed55ecf07fc0f985ab46561483c0e888e8964ae6'
"""



//=== certificate/private key for  ssl/https
adding the following to  myconfig.py:

"""
# The full path to an SSL/TLS certificate file.
c.NotebookApp.certfile = u'/Users/bgranger/.ipython/profile_my_profile/mycert.crt'

# The full path to a private key file for usage with SSL/TLS.
c.NotebookApp.keyfile = u'/Users/bgranger/.ipython/profile_my_profile/mycert.key'
"""


//=== make notebook server public
by listening to arbitrary ip address ?

> ipython notebook --ip=* --no-browser

or add the following to  myconfig.py:

"""
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
"""



try ipython #1

[Q] what's ipython ?
* an enhanced interactive Python interpreter, offering tab completion, object introspection...
* an enhanced command shell for Python
* high performance tools for parallel computing ?
* supporting interactive computing in any language ?

http://ipython.org/


//=== my environment, Win7x64

0. download and install Anaconda (Python+ iPython + notebook +  ... )
    http://continuum.io/downloads

1. open Anaconda cmd prompt


//=== install ipython by Anaconda
> conda update conda
> conda update ipython


or
traditional way
> pip install ipython

or include the dependencies for the IPython notebook:
> pip install "ipython[notebook]"

or
manually download IPython from Github or PyPI. To install one of these versions, unpack it and run the following from the top-level source directory using the Terminal:
> python setup.py install

* ipython is a module for python from this perspective


//=== how to start ipython
anaconda cmd prompt
> ipython



//=== http://ipython.org/ipython-doc/stable/interactive/tutorial.html
line-oriented and cell-oriented magics.

""" ...
Line magics are prefixed with the % character and work much like OS command-line calls:
they get as an argument the rest of the line, where arguments are passed without parentheses or quotes.

Cell magics are prefixed with a double %%, and they are functions that get as an argument
not only the rest of the line, but also the lines below it in a separate argument.

%run
%edit
%history

%pastebin 3 18-20 ~1/1-5
This will take line 3 and lines 18 to 20 from the current session, and lines 1-5 from the previous session.
..."""

In [1]: !ping www.bbc.co.uk
In [2]: !ls
'ls' is not recognized as an internal or external command,

In [3]: !dir
In [4]: x=4
In [5]: !echo $x
In [6]: quit

D:\ipython>

//=== http://ipython.org/ipython-doc/stable/interactive/tutorial.html
> ipython profile create
to produce the default config files.
These will be placed in ~/.ipython/profile_default


//=== http://ipython.org/ipython-doc/stable/config/intro.html#profiles

> ipython profile create foo # create the profile foo
> ipython locate profile foo
> ipython --profile=foo # start IPython using the new profile


//==  http://www.computerhope.com/prompthl.htm

myipy.bat

""" ...
chdir D:\ipython
D:
rem prompt $P$G
ipython --profile=urprofile
..."""


//=== ipython tutorial
http://ipython.org/ipython-doc/stable/interactive/tutorial.html


[Q] what's ipython ?
[Q] what's ipython notebook ?
[Q] what's ipython Qt console?



//=== ipython notebook :
0. a web app
1. turn console-based ipython to web-based
2. code + contents


http://ipython.org/ipython-doc/stable/notebook/notebook.html#introduction

* to start an ipython notebook server from the command line
> ipython notebook --profile=urprofile



*** nbconvert and nbviewer
Notebooks may be exported to a range of static formats, including HTML, Markdown, LaTeX, PDF ... , via  'nbconvert'

In effect, nbviewer is simply nbconvert as a web service ?

> ipython nbconvert notebook.ipynb
> ipython nbconvert --to html notebook.ipynb
> ipython nbconvert --to markdown notebook.ipynb --stdout



//=== how to run code in the IPython Notebook
http://ipython.org/ipython-doc/stable/notebook/notebook.html#introduction

* Shift-Enter: run cell
Execute the current cell, show output (if any), and jump to the next cell below.

* Ctrl-Enter: run cell in-place
Execute the current cell as if it were in “terminal mode”, where any output is shown, but the cursor remains in the current cell.

* Alt-Enter: run cell, insert below
Executes the current cell, shows the output, and inserts a new cell between the current cell and the cell below

* Esc and Enter: Command mode and edit mode


[Q] where does ipython notebook store the new document?
--> under the folder where you start notebook.





2014年12月4日 星期四

ssh to amazon ec2 via security group

*** using ssh to connect to amazon ec2 instance by adding inbound rules to the corresponding security group

基於安全考量,
0. 限制ssh的連入 source IP ;
1. 最好在client 自行產生key pair, 避免從server 產生再下載;
2. 避免透過網路複製 private key

//===
MyIP : will auto decide the public ip address of the client computer from which you connect to the ec2 instance

MyIP 給的是client 的public IP位址, 而非server 的ec2 elastic IP
當管理員可能從諸多不同的地點連入ec2,
MyIP提供設定security group rules的方便之門


//===
想允許ssh 使用不同的key pair 連入 ec2 ,
必須

0. 修改server端的 ~/.ssh/authorized_keys, 增加對應的public key

1. clientt端 必須擁有對應的private key ,
* git bash
$ ssh -i priv.pem ...

* putty needs priv.ppk [可用puttyGen.exe 將 pem 轉成 ppk]
Connection --> Data --> auto login username: ubuntu / ec2_user
Connection --> SSH --> Auth --> Browse for location of ppk file



//=== security group !== iptables

amazon ec2 的 security group 與 iptables 看來很像,
不過

0. security groups 是跨 instance 的 (cross-instance, instance-independent)

1. 每個 linux instance 都有各自的 iptables

2. security groups are not state-sensitive




//=== http://serverfault.com/questions/286665/why-have-both-security-groups-and-iptables-on-amazon-ec2
amazon

""" ...
I figured if anything Security Groups are just a fancy API for IPTables. It turns out they're running completely exclusively from what I can tell. Is there any reason to use both? One firewall should be plenty and adding another layer of complexity seems to be a headache just waiting to happen

...
The security groups add no load to your server - they are processed externally, and block traffic to and from your server, independent of your server. This provides an excellence first line of defense that is much more resilient than one residing on your server.

...
However, security groups are not state-sensitive, you cannot have them respond automatically to an attack for instance. IPTables are well suited to more dynamic rules - either adapting to certain scenarios, or providing finer grained conditional control.

... think about the security group like a hardware firewall in a normal networking scenario.

I guess you wouldn't really have to use both unless you had a special scenario, for example: you have a security group called webservers that controls access to web servers. You want to block an IP from hitting port 80 on one of those servers but not all of them. So what you would want to do is go into iptables on that one server

..."""

how to make notepad save file in utf-8 encoding by default

[Q] how to make the default file encoding to be utf-8 when saving a file by notepad?

0. create an empty file and save it with utf8 encoding
1. place it under Documents(or your frequent folder) and make it read-only

2. right-click to create a shortcut to it
[change the icon of the shortcut by Right-click ->Properties->ShortCut tab -> Change Icon ]

3. place the shortcut on the desktop



//=== http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/default-utf-8-encoding-for-new-notepad-documents/525f0ae7-121e-4eac-a6c2-cfe6b498712c

""" ...

1- Open notepad and don't type anything;

2- Go to File>Save As...;

...

4- Under "Encoding" choose "UTF-8";5- Save file in a safe place;

...

7- Right click on it and choose "Properties";

8- In "General" tab check the "Read-only" checkbox and press "OK";

9- Again right click on it and choose "Create Shortcut";

...

11- Right click on "Notepad.lnk" and choose "Properties";

12- In the "Shortcut" tab click on "Change Icon...";

13- Under "Look for icons in this file:" type the path of "notepad.exe" which is "%windir%\system32\notepad.exe" and press "OK" twice;

...

place Notepad.lnk on the desktop for more ease


... """

2014年11月26日 星期三

nodejs + heroku

0. launch git bash from the working folder of nodejs project, say mynjs1
  $ heroku login

1.  initialize git repository
   $ git init
   $ git add .
   $ git commit -m "initialize mynjs1"

2.  create the corresponding app on heroku
   $ heroku create --http-git
   [   $ heroku apps:create --http-git  ]
   https://infinite-lake-5143.herokuapp.com/
   https://git.heroku.com/infinite-lake-5143.git
...
   $ git push heroku master


3. Ensure that at least one instance of the app is running by :
   $ heroku ps:scale web=1

4.  visit the app at the URL generated by its app name.
   $ heroku open  [ or open it by browser]

5. view log
   $ heroku logs --tail
   Press Control+C to stop streaming the logs


6.  create package.json by
   $ npm init

7.  Procfile
   web: node httpsvr1.njs

8. rename app
   $ heroku apps:rename mynjs2

9.  run bash on heroku
   $ heroku run bash

10.
$  heroku config:set TIMES=4

11. revise files, git add, git commit, git push
httpsvr.listen(8080)  --> httpsvr.listen(process.env.PORT)



[ref]
https://devcenter.heroku.com/articles/getting-started-with-nodejs


[err]
ssh: connect to host  port 22: Bad file number
fatal: Could not read from remote repository.
-->

//=== http://stackoverflow.com/questions/16436284/failing-to-push-git-to-heroku-port-22-bad-file-number-could-not-read-from-remot


""" ...
if unable to access Heroku on port 22, then HTTP Git should solve it (it works on port 443). ...

To create a new app and have it be configured with a HTTP Git remote...
$ heroku apps:create --http-git

To change an existing app from SSH to HTTP Git ...
$ heroku git:remote --http-git

... """

2014年11月25日 星期二

install nodejs on ubuntu


//=== https://github.com/joyent/node/wiki/Installation
"""...
You can install a pre-built version of node.js via the downloads page available in a .tar.gz.
..."""

$ sudo apt-get remove nodejs

$ wget http://nodejs.org/dist/v0.12.0/node-v0.12.0-linux-x64.tar.gz
$ sudo tar -C /usr/local/ --strip-components=1 -zxvf node-v0.12.0-linux-x64.tar.gz
$ sudo ln -s /usr/local/bin/node /usr/bin/node
$ node --version
$ npm --version [newer nodejs should already include npm in its package]






//===
1.  quick way to install nodejs on ubuntu
$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo apt-get install npm

$ mkdir ~/nodejs
$ cd ~/nodejs
$ npm install node-static
-->  ~/nodejs/node_modules/node-static
...


2.  build from source

//=== http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/#installNode

$ git clone git://github.com/joyent/node.git
$ cd node

$ git tag -l
[ view available Node tags (versions)  ]

$ git checkout v0.6.8
$ ./configure
$ make      [需要30分鐘以上?]
$ sudo make install
[ how to change name to nodejs to avoid conflict ?]


[ install NPM(Node package manager) ]
$ git clone https://github.com/isaacs/npm.git
$ cd npm
???
$ sudo make install





如何讓 nodejs 與 apache 共用 port 80 ?

[Q] nodejs 無法在port 80 執行?
[Q] why does nodejs listening to port 80 cause error  :listen EACCES?

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EACCES
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1020:19)
    at listen (net.js:1061:10)


""" ...
The error code EACCES means you don't have proper permissions to run applications on that port.
On Linux systems, any port below 1024 requires root access.

... """

[ref]
http://stackoverflow.com/questions/18947356/node-js-app-cant-run-on-port-80-even-though-theres-no-other-process-blocking-t


[try]
0. run nodejs with sudo,  --> 恐有資安風險?
  $ sudo nodejs httpsvr.njs

1. use apache as reverse proxy  --> 效能較弱?
[ need to install/enable apache proxy, proxy_http module ]
 $ sudo a2enmod proxy
 $ sudo a2enmod proxy_http

<VirtualHost *:80>
ServerName subdomain.yourdomain.com
ProxyRequests Off

#ProxyPreserveHost on
ProxyPass / http://localhost:3000/
</VirtualHost>

""" ...
Every request that comes in through Apache will cause an Apache thread to
wait/block until the response is returned from your Node.js process.

... """

2. use nodejs package http-proxy to redirect port 80 traffic
-->  http-proxy 尚未穩定?
--> still needs sudo to run the proxy listening to port 80?
$ npm install  http-proxy

myproxy.njs

var http = require('http');
httpProxy = require('http-proxy');
proxy = httpProxy.createProxy(options);
var options={
    hostnameOnly: true,
    router: {
        'urdomain.com':       'http://127.0.0.1:1001',
        'nodejs.urdomain.com':     'http://127.0.0.1:1002',
        '127.0.0.1':        'http://127.0.0.1:1003'
    }
};

http.createServer(function(req, resp) {
  proxy.web(req, resp, {
    target: options.router[req.headers.host]
  }).listen(80);

xxx target : '127.0.0.1:1001'
--> target: 'http://127.0.0.1:1001'

--> 'nodejs.urdomain.com':     'http://127.0.0.1:1002',
run the actual httpsvr.njs on localhost at port 1002

3. use Nginx as reverse proxy ...

[ref]
http://www.chrisshiplet.com/2013/how-to-use-node-js-with-apache-on-port-80
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://stackoverflow.com/questions/11172351/how-to-put-nodejs-and-apache-in-the-same-port-80

http://blog.nodejitsu.com/http-proxy-intro/



2014年11月24日 星期一

favicon, png, ico

*** ico may contain mutliple resolutions(multiple layers) of image.
*** IE 11 has to operate in compatibilty view mode to show favicon correctly !?

$ convert /?

$ convert srcImg.png -background transparent -colors 256 fav16.ico

$ convert srcImg64.png -bordercolor white -border 0
( -clone 0 -resize 16x16 )   ( -clone 0 -resize 32x32 )
( -clone 0 -resize 48x48 )  ( -clone 0 -resize 64x64 )
-delete 0  -alpha off -colors 256  fav4in1.ico

$ convert favicon-256.png -resize 16x16 favicon-16.png
$ convert favicon-256.png -resize 32x32 favicon-32.png
$ convert favicon-256.png -resize 64x64 favicon-64.png
$ convert favicon-256.png -resize 128x128 favicon-128.png
$ convert favicon-16.png favicon-32.png favicon-64.png favicon-128.png favicon-256.png -colors 256 favicon.ico

$ convert ico64.png -resize 16x16 -transparent white fav16.png
$ convert ico64.png -resize 32x32 -transparent white fav32.png
$ convert fav16.png -background transparent -colors 256 fav16.ico
$ convert fav16.png fav32.png -colors 256 5gen2in1.ico

[ref]
https://gist.github.com/pfig/1808188


//=== http://www.jonathantneal.com/blog/understand-the-favicon/
32×32 icon is used in the address bar on IE10 Metro ?

<!-- IE6-10 -->
<link rel="shortcut icon" href="path/to/favicon.ico">

<!-- Everybody else -->
<link rel="icon" href="path/to/favicon.ico">


PNG favicon files do not include multiple resolutions like ICO favicons
-->
<link rel="icon" href="favicon-16.png" sizes="16x16">
<link rel="icon" href="favicon-32.png" sizes="32x32">
<link rel="icon" href="favicon-48.png" sizes="48x48">
<link rel="icon" href="favicon-64.png" sizes="64x64">
<link rel="icon" href="favicon-128.png" sizes="128x128">




File Shortcut and Symbolic Link in Windows

//===
File shortcut [檔案捷徑/shell link] :  副檔名 .lnk / .LNK
通稱 shortcut / link file

根據wikipedia:
"a small file containing a target URI or GUID to an object, or
the name of a target program file ..."

//===  Symbolic link
> mklink   linkname  targetFileName            [file symbolic link]
> mklink  /D  linkname  targetDirName        [directory symbolic link ]


> mklink /?
MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J       Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.

//===
IShellLink
IPersistFile
IPersistSystem


[ref]
http://en.wikipedia.org/wiki/File_shortcut

shell link spec:
http://msdn.microsoft.com/en-us/library/dd871305(v=prot.13).aspx
http://download.microsoft.com/download/a/e/6/ae6e4142-aa58-45c6-8dcf-a657e5900cd3/[MS-SHLLINK].pdf



2014年11月13日 星期四

EC2 elastic ip

網路搜尋 elastic ip charge 之後
終於了解 amazon EC2 elastic ip 與 public ip 的差異

將一個elastic ip 指定給某個 EC2 running instance i-123c484c,
(綁在一起, to associate an elastic ip to an EC2 running instance)
停掉 instance i-123c484c 再啟動, 這個 elastic ip 不會改變;
若採用public ip , 在instance重新啟動時會動態取得一個IP , 很有可能與原來的不同.
-->
* elastic ip == fixed external ip
* public ip == dynamic external ip

[pricing]
Amazon 目前提供一個免費的 elastic ip, 前提是它必須與某個running instance 綁在一起(assoicate elastic ip with instance),
也就是透過running instance 的 流量/CPU/Storage/ ...來收費.



*** 向系統要求分配了elastic ip後, 卻未指定給某個running instance,  Amazon 將酌收費用 ...

*** 為了避免用戶的損失與資源的有效利用, Amazon 鼓勵用戶盡快釋出閒置的elastic ip   (release elastic ip)

*** 一個 elastic ip 可以在不同的running instances切換, dis-associate with one then associate with another.


[ref]
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-
eip.html

http://aws.amazon.com/ec2/pricing/

2014年11月10日 星期一

ssh bitbucket.org by GitBash

//=== https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

0. launch GitBash
1. chk OpenSSH/OpenSSL are installed
$ ssh -v
   OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007 ...

$ cd    //go back user home folder
$ pwd
$ cd .ssh
[ $ cd ~/.ssh ]


$ ls
id_rsa    id_rsa.pub  known_hosts

* id_rsa is the private key
* id_rsa is the public key
* id  --> identifier for short

2. $ ssh-keygen

[ 3.  notepad ~/.ssh/config , 預設的組態檔
加入
Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa

"...
The second line is indented.
That indentation (a single space) is important, so make sure you include it.
..."
IdentityFile 的那一行開頭必須有一個空白, 之後緊接著IdentityFile  path-to-privatekey

]

4.  $ ssh-add -l
Could not open a connection to your authentication agent
-->
need to start ssh-agent before you run the ssh-add command:

$ eval `ssh-agent -s`  # need to use eval instead of just ssh-agent
$ ssh-add path-to-target-privatate-key

path-to-target-privatate-key 代表密鑰檔案路徑
會蓋過預設組態檔的設定
[例] /c/myProjs/sshkeys/privkey-for-bitbucket

5. 將公鑰(.pub)內容複製到 bitbucket.org 帳戶
account settings --> ssh
*** take care not to wrap the lines


6. 更改既存的git config, 將https改為ssh
$ cat .git/config
[core]
  ...
[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  url = https://username@bitbucket.org/teamid/repo1.git
[branch "master"]
  remote = origin
  merge = refs/heads/master

--> url = ssh://git@bitbucket.org/username/repo1.git

https://accountname@bitbucket.org/accountname/reponame.git
-->  ssh://git@bitbucket.org/accountname/reponame.git

https://accountname@bitbucket.org/teamid/reponame.git
-->  ssh://git@bitbucket.org/teamid/reponame.git


//=== 讓 Git Bash 啟動時帶入 ssh-agent
http://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent

1. notepad .bashrc

#!/bin/bash
eval `ssh-agent -s`
ssh-add

ssh-add without paramaters
-->  ~/.ssh/id_rsa

for customized location of the private key
--> ssh-add path-to-private-key


2. Restart GitBash (Msysgit)


//=== ssh-add, ssh-agent
$ man ssh-add
""" ...
-L      Lists public key parameters of all identities currently repre?
             sented by the agent.

-l      Lists fingerprints of all identities currently represented by the
             agent.
... """

$ man ssh-agent
""" ...
     a program to hold private keys used for public key authenti?
     cation (RSA, DSA, ECDSA).  The idea is that ssh-agent is started in the
     beginning of an X-session or a login session, and all other windows or
     programs are started as clients to the ssh-agent program.  Through use of
     environment variables the agent can be located and automatically used for
     authentication when logging in to other machines using ssh(1).
..."""


//===

2014年11月5日 星期三

subdomain alias or subdomain forward?

//=== "subdomain forward" is different from "subdomain alias"
subdomain forward is done by 'A record'
subdomain alias is done by 'CNAME record'

* subdomain alias 會將輸入的域名保留在瀏覽器的網址列
[例]
it.3hd.me 其實是指向 3hitek.blogspot.com
在網址列仍顯示 it.3hd.me

* 典型的subdomain forward (without masking) 網址列則會顯示域名所轉指的url,
[例]  book.3hd.me --> 3hbook.blogspot.com
網址列顯示 3hbook.blogspot.com

* masked subdomain forward (subdomain with masking) 則可達到類似alias的效果, 與CName alias 不同的是即使點選連結到外部的網頁
masked subdomain 的框架(frame/mask) 會一直籠罩著之後的網頁,
網址列始終顯示原來輸入的域名值, 這使得許多搜尋引擎會特意過濾掉
masked subdomain, 因而影響SEO (seach engine optimization).


[例]  tour.3hd.me  --> 3htour.blogspot.com
網址列顯示 tour.3hd.me , 即使點選外部連結, 網址列依然顯示 tour.3hd.me

""" ...
The main disadvantage of this type of forwarding is that is uses Frames.
...
Many search engines, such as Google, ignore framed content, and so your site will not be found easily ...
..."""


* subdomain forward 所增加的 A records
book    A     50.63.202.15  
tour      A    184.168.221.30


* subdomain alias 的設定比較麻煩, cname record並非直接指向目標網址,
而是要知道目標網址的域名伺服器(domain name server) ,
如果要指向既有的blogger(blogspot.com) 或是 google site, 則cname record 的 值要設為 ghs.google.com

[例]
it                  CNAME     ghs.google.com
yyyxxxzzz   CNAME     afjklgjkljajdkturjkj5.dv.googlehosted.com

除了正常的別名設定之外 it --> ghs.google.com ,
google 還會要求增加另一個隨機產生的 cname record 以驗證域名的所有權,
yyyxxxzzz   -->    afjklgjkljajdkturjkj5.dv.googlehosted.com


"""...
For security reasons, your domain must be verified with Google. See the below section, 'Domain is not verified' error ...

..."""



[ref]
http://wiki.gandi.net/en/domains/management/domain-as-website/forwarding

https://support.godaddy.com/help/article/5112/mapping-your-domain-name-to-work-with-blogger
https://support.godaddy.com/help/article/422/manually-forwarding-or-masking-your-domain-name


https://support.google.com/blogger/troubleshooter/1233381
https://support.google.com/sites/answer/99448


//=== https://www.linode.com/docs/networking/dns/introduction-to-dns-records
""" ...
 a CNAME record does not function the same way as a URL redirect.
... """


//=== use subdomain alias binding to backup/spread/aggregate your blogs
運用subdomain alias/forward 將散落各處的部落格集中在自己的網域,
方便存取/管理, 也達到縮址(縮短網址)的效果.


//=== 將自己的 subdomain 指向 github

http://www.openfoundry.org/index.php?option=com_content&task=view&id=9307&Itemid=4;isletter=1

""" ...

用 CNAME 的方式將一組子網域名稱指向你的 Github Pages
...
•將受惠於 Github Pages 站台的 CDN 效益。
•Github Pages 伺服器換 IP 的時候你不必跟著換否則其他人就連不上去。
•網頁載入的速度較快。

... """





//=== https://support.google.com/blogger/troubleshooter/1233381
""" ...
1.Go to your blog and click on Basics under the Settings tab. In the "Publishing" section, click the link to add a custom domain.

Add a custom domain
... """

//=== https://support.godaddy.com/help/article/5112/mapping-your-domain-name-to-work-with-blogger
To Edit Your CNAME Record

"...
1. Log in to your Account Manager.
Next to Domains, click Launch.
2. Click the domain you want to use, and then select the 'DNS Zone File' tab.
3. Click Add Record.
4. Select CNAME (Alias)for the Record type.
....

Click Save, and then click Save Changes.

... """


//===
domain : 網域
domain name : 域名
subdomain: 子網域

registrar : 域名註冊商, 網域代理商,
例如 godaddy.com, name.com, namecheap.com ...

2014年10月21日 星期二

file extension association on windows

//=== display assoication
> assoc .py
.py=Python.File

//=== set association
>assoc .pys=pysFile

//=== remove association
> assoc .pys=


//=== ftype (file type)
> ftype |findstr Python

Python.CompiledFile="...\Python27\python.exe" "%1" %*
Python.File="...\Python27\python.exe" "%1" %*
Python.NoConFile="...\Python27\pythonw.exe" "%1" %*



//=== where
> where assoc
??? could not find files for the given patterns

> where demo.bat


//=== pathExt
> echo %pathExt%


//=== http://pcsupport.about.com/od/fixtheproblem/ht/default-program-windows-7.htm

Control Panel\All Control Panel Items\Default Programs\Set Associations

Control Panel --> Default Programs --> Associate a file type or protocol with a specific program

2014年8月28日 星期四

移除 windows 8.1 已安裝的更新

[Q] how to uninstall the installed update on windows 8.1?
[Q] windows8.1 如何解除更新?  (如何移除已安裝的update?)

[try]
0. 先進入Windows Update  [ Control Panel > Windows Update ]

1. 視窗左下角 有一個 Installed Updates 的連結 點下去

2. 視窗改換成顯示已安裝的更新 --> Control Panel > Programs and Features > Installed Updates

3. 選擇想移除的標的,  right-click to uninstall

2014年8月21日 星期四

sqlite3 memo 2014.08.21

//=== examples
sqlite3 ex3.db  "select * from invoice;"  > op1.txt
sqlite3 ex2.db   ip2.sql >  op2.txt
sqlite3 ex1.db  .dump  > ex1.sql


//=== sqlite3 命令列 (sqlite command line shell)

http://www.sqlite.org/cli.html
http://www.sqlite.org/download.html

下載 Precompiled Binaries for Windows
http://www.sqlite.org/2014/sqlite-shell-win32-x86-3080600.zip
解壓縮後得到 sqlite3.exe ,
為了方便, 把 sqlite3.exe 放到 python 的根目錄下



//=== create a new empty database file ex1
先進入 Git Bash
$

$ sqlite3 ex1
SQLite version 3.8.6. ...
Enter ".help" for usage hints.
sqlite> .q

$ ls ex1*
ex1


$ sqlite3 ex2.db
...
sqlite>.q
$ ls ex2*
ex2.db

//=== .q or .quit or .exit to escape sqlite cmd shell


//=== create a new table
$ sqlite3 ex1
sqlite> create table t1 (id Integer, name Text);
sqlite> create table t2 (id int, address text);
sqlite> .tables
t1 t2

sqlite> pragma table_info(t1);
0|id|Integer|0||0
1|name|Text|0||0


//=== insert record
sqlite> insert into t1 values(1, "name1");
sqlite> insert into t1 values(2, "name2");
sqlite> insert into t2 values(1, "addr1");
sqlite> insert into t2 values(2, "addr2");


???
sqlite> commit;
Error: cannot commit - no transaction is active


//=== open a database file
$ sqlite3 db_fname
or

$ sqlite3
sqlite> .open db_fnmae



//=== backup/dump a database or a table to a file
$ sqlite3 db_fname
sqlite> .output db.sql
sqlite> .dump

sqlite> .output t1.sql
sqlite> .dump t1

sqlite> .output t2.sql
sqlite> .dump t2

sqlite> .q
$ ls *.sql



//=== run sql script
$ sqlite3 db_fname "select * from t1;"
$ sqlite3 db_fname "insert into t1 values(3, 'name3');"
$ sqlite3 db_fname "pragma table_info(t1);"
$ sqlite3 db_fname < script_to_run.sql

//=== restore/import from a dump/backup.sql to another db file
 $ sqlite3 -init dbback.sql db_restored_fname


 //=== http://erikej.blogspot.com/2012/08/exporting-sql-server-compact-to-sqlite.html

export/dump/backup
$ sqlite3 ex1.db .dump > ex1_dump.sql

import/load/restore
$ sqlite3 ex1_restored.db < ex1_dump.sql


//=== encoding problem and other notes from erikej.blogspot.com
1. The dump file must be in UTF8 without BOM, i.e. plain utf-8 file

2. ALTER TABLE is limited, so constraints must be included in the CREATE TABLE statement

3. GO separator is not used, all statements must simply end with semicolon ;


???
7. SQLite binary data format: X’FFAABB’

8. not to include rowversion columns in the dump file ...




//===

2014年8月7日 星期四

如何列出 python 模組中可用的方法?

[Q]  how to list methods for a module in python?
[Q]  如何列出python 模組中的方法?

http://stackoverflow.com/questions/139180/listing-all-functions-in-a-python-module

$ dir(modulename)
to see all available methods/attributes


$ import modulename
$ help(modulename)


//=== https://docs.python.org/2/faq/windows.html#is-a-pyd-file-the-same-as-a-dll
pyd 與 dll 的分別

" ... If you have a DLL named foo.pyd, then it must have a function initfoo() ....  "

[例]
extern "C" __declspec(dllexport) void initmyrandom(void) {

Py_InitModule("myrandom", MTPRNGMethods);
}

*** 模組名稱, 檔案名稱, 函數名稱 三者需一致



" ... “import foo” ...
Python will search for foo.pyd (as well as foo.py, foo.pyc) ...
will attempt to call initfoo() to initialize it.
"
*** foo.pyd is not required if  "import foo" is not called

 "... the search path for foo.pyd is  PYTHONPATH,  not the same as the path that Windows uses to search for foo.dll. ..."



???
 " ... In a DLL, linkage is declared in the source code with __declspec(dllexport).
 In a .pyd, linkage is defined in a list of available functions....
"


2014年8月1日 星期五

Skype 帳號一直呈現 online 的狀態

今天突然發現自己另一個 Skype 帳號( B帳號 )一直呈現 online 的狀態,
心想該不會帳號被盜用了, 試著login,  還好還能登入,
趕緊更改密碼, 並將狀態更改為 offline 然後登出;

改用A帳號登入,  沒想到 B帳號還是一直顯示online 的狀態,
難道還有在其他台電腦上裝skype嗎?

網路搜尋  "how to disable multiple login of skype on different computer"

輾轉數折 最後終於找到解法
https://support.skype.com/en/faq/FA10042/what-are-chat-commands-and-roles

" ...
/remotelogout
Sign out all other instances except the current one. This will also stop push notifications on all other instances.
..."

[try]
改以B帳號(不正常顯示者)登入

在發送訊息(message) 的對話盒中 輸入
/showplaces 然後送出(send) 就會顯示目前在那些電腦上有登入 
You have 4 online endpoints:
  {dc4xxxxx-dxxx-bxxxx-xxxx-xxxxxxxxx}) AUTO1 Windows Skype
  {xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx}) localhost Android Skype
  {xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx}) localhost Android Skype
  {xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx}) localhost Android Skype


發送
/remotelogout 則會將本機以外的登入狀態清除掉

再發送一次 /showplaces 來查看
You have 1 online endpoints:
  {dc4xxxxx-dxxx-bxxxx-xxxx-xxxxxxxxxx}) AUTO1 Windows Skype


登出B帳號, 改以A帳號登入  查看B帳號 狀態 
終於正常了!

至於localhost Android Skype 怎麼來的? 
應該是個把月前買的android 電視盒 
裝了skype 才發現沒有麥克風輸入孔 ...


2014年7月11日 星期五

Create a new repository for git + bitbucket

Create a new repository and 'upload' ( push)  to bitbucket


//=== initialize local repository first
~$ mkdir projectname
~$ cd projectname


~$ nano .gitignore
venv
env
*.pyc




~$ git init
~$ git add .
~$ git commit -m 'first commit'




*** git commit -a automatically stage all tracked, modified files before the commit ...
~$ git commit -a -m 'commit all changed files'


http://stackoverflow.com/questions/19877818/git-commit-m-vs-git-commit-am




//=== remote repository
0. use web browser to login bitbucket to create remote repository  "repoName.git"

1. ~$ git remote add origin  https://bitbucket.org/ownerName/repoName.git
[ add remote branch 'origin' ]

2. ~$ git push origin master
[ push  to remote branch 'origin' from local branch 'master' ]

2014年7月7日 星期一

兩年前的硬碟 重新開機 Windows Installer DEP Error

塵封兩年的3.5" 外接eSata 硬碟 重新開機
在試過5V DC 變壓器 確定不行之後
換上了12V DC 變壓器之後還算順利


不過 Windows Update 出現
"...
Windows could not search for new updates
An error occurred while checking for new updates for your computer
Code C80003FA
...
"


接著出現
Windows Installer  DEP Error ...
*** Make sure you've got the latest version of Windows Installer first.
*** no need to change DEP settings




重新開機兩次之後
"
Problem signature:
  Problem Event Name: BEX
  Application Name: MsiExec.exe
  Application Version: 4.5.6002.18005
  Application Timestamp: 49e01c42
  Fault Module Name: MSIFF7E.tmp_unloaded
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp: 4333dd69
  Exception Offset: 1001b76c
  Exception Code: c0000005
  Exception Data: 00000008
  OS Version: 6.0.6002.2.2.0.16.7
  ...


//===  http://www.ehow.com/how_7310317_check-windows-installer-version.html
check the windows installer (msiexec) version
msiexec /?

//=== http://answers.microsoft.com/en-us/windows/forum/windows_vista-windows_programs/msiexecexe-crashes-when-installing/e9796657-be86-45c4-b816-ce568cb6b096


Step 1: "Reregister" the Windows Installer

1.1  msiexec /unreg
1.2  msiexec /regserver


Step 2: Stop and Restart the Windows Installer Service.
2.1 services.msc
2.2   Expand the Services window and then scroll down to Windows Installer.
2.3   Right-click the Windows Installer list item and then click Stop, right-click again and then click Start.


Step 3: SFC Scan
SFC utility allows administrators to perform a scan of all protected resources to verify that they are the correct version.


 3.1 cmd prompt + run as administrator
 3.2 sfc /scannow




Step 4: Windows Installer CleanUp Utility:
Download the latest version from ???

Step 5: Windows Installer
Download the latest version from ???




//===
http://support.microsoft.com/kb/918355#_method2
http://support.microsoft.com/kb/923159


http://superuser.com/questions/75950/windows-installer-gets-terminated-by-data-execution-prevention

*** Make sure you've got the latest version of Windows Installer first.
*** need to have thorough understanding of virtual memory to understand DEP .
*** turn off the DEP by going to my computer --> system properties --> DEP -->



勞健保網路加保, 退保

***
IE10/11 用戶請開啟IE--工具--相容性檢視設定
(Tools -> Compatibility View Settings)

nhi.gov.tw
edesk.bli.gov.tw
新增至相容性檢視網站--即可正常運作...


//=== 勞動部 勞工保險局
https://edesk.bli.gov.tw/aa/
https://edesk.bli.gov.tw/cpa/


透過公司加保 點選
 投保單位網路申報及查詢作業


勞保申辦作業 -> 單筆作業 -> 加保作業
-->
勞保(含普通及職災保險)、就保、勞退
勾選健保本人 + 健保業務組別


健保業務組別   服務電話               轄區
台北業務組 (02)21912006     台北市、新北市、基隆市、宜蘭縣、金門 縣、連江縣
北區業務組 (03)4339111       桃園縣、新竹市、新竹縣、苗栗縣


雖然勾選了健保本人 但隔天到健保署網站查詢並無加保資料
不知是否IE11的問題 導致資料未送入健保署 ???
因為在操作的過程中 最後有出現眷屬加保的按鈕 按下去之後
跳回勞保局的登入畫面, 在操作第二次時 就只有勾選健保本人 + 健保業務組別,
沒敢再按眷屬加保的按鈕 ...






只好用健保署的單獨健保加保作業, 替自己(本人加保)和媽媽(眷屬加保) 加健保 ...


//=== 衛生福利部 中央健康保險署
衛福部健保署 多憑證網際網路加退保作業系統


https://eservice.nhi.gov.tw/nhiweb1/System/Login.aspx


網路健保加保
一至三類加保作業
本人加保
眷屬加保






*** 勞保局網路 加勞保後 隔天公司查詢的申報狀態變為成功
但經過周末 禮拜一個人查詢勞保的異動資料 仍停留在上一個工作
未出現禮拜四的申報結果, why???









//=== before 65
either 勞保 + 健保 or 國保 + 健保
勞保與國保應該是互斥的,
國保的繳費單 NT$778




有工作時公司會自動幫你保健保,
那沒工作時的健保 --> 鄉鎮區公所

//=== http://www.mobile01.com/topicdetail.php?f=291&t=3480011
" ...
沒工作時選擇國民年金加健保會有二種情況:
...


若單身情況下無選擇職業工會加入勞保.
就要自行去公所加保健保.為健保第六類地區人口保險.好像是六百多.

... 健保局的催繳單 ....

如果是已婚情況下.
若無選擇職業工會加入勞保.
則要跟配偶一起加保.是不能去加保公所的健保.要跟配偶的加在一起


...
重點是我覺得勞保福利比較好 ???
...
"


//===
健保要繳到死亡


除非


得到重大疾病政府就不收錢 ...
非自願性離職,有申請失業補助, 政府免繳健保費6個月 ...
有些縣市健保費老人65歲以上會有補助

//===
國保繳至65歲,
勞保繳至退休,


...

2014年6月18日 星期三

Windows 8, 如何更改顯示亮度/對比/字型的大小

[Q] How to change font size on Windows8/8.1 ?

* Right-click on desktop  -> Screen resolution ->  Make text and other items larger or smaller
* In the "search control panel" box , type font or display

---> Control Panel\Appearance and Personalization\Display



[Q] How to change LCD monitor/screen contrast/brightness on Windows8/8.1 ??

* contrast --> need driver utility for display chipset such as Intel or NVidia ...
* brightness --> slide to right-bottom corner to  show "Gear" for Settings
   -> Change PC settings -> brightness


2014年6月6日 星期五

haxe tutorial+3 , haxe3, neko, haxelib

//=== new haxe3 webpage
http://haxe.org


//=== old haxe webpage
http://old.haxe.org/manual/haxe3/migration


//=== download haxe3 windows binaries
http://haxe.org/download/file/3.1.3/haxe-3.1.3-win.zip


0. unzip and move folder haxe3.1.3 to haxe\


1. create symbolic directory link [ require admin privilege]
    F:\sandbox\haxe> mklink /D haxepath haxe-3.1.3
    (haxepath is the symbolic link pointing to the actual folder haxe-3.1.3)


2. add F:\sandbox\haxe\haxepath to environmental Path


3. create haxe3lib folder under haxe\
   > haxelib setup
   enter the lib path :  F:\sandbox\haxe\haxe3lib




//=== haxelib setup
uncaught exception - std@module_read
--> haxelib.exe still needs dll from the newer neko,





//=== where to download neko
https://github.com/HaxeFoundation/neko
http://nekovm.org/download


http://nekovm.org/_media/neko-2.0.0-win.zip
download neko-2.0.0 windows binaries
0. unzip  move folder neko-2.0.0 to haxe\
1. create symbolic directory link [ require runas admin ]
    F:\sandbox\haxe> mklink /D nekopath  neko-2.0.0
 

2. add F:\sandbox\haxe\nekopath to environmental Path








//=== using haxelib
http://old.haxe.org/doc/haxelib/using_haxelib





Eclipse ADT update tips

http://stackoverflow.com/questions/18483815/an-error-occurred-while-collecting-items-to-be-installed


 Android SDK更新後, Eclipse 啟動時出現錯誤訊息
"location of the android SDK has not been setup in the preferences"
--> Eclipse 的 ADT 版本是舊的, 需要更新 ADT Plug-in


ADT: Android Development Tools (ADT) is a plugin for the Eclipse IDE




//===  http --> https
Window->Preferences->Install/Update -> Available Software Sites --> "ADT Plugin"  -->
https://dl-ssl.google.com/android/eclipse/



//=== Help -> Install New Software
Uncheck “Contact all update sites during install to find required software”






//=== download the ADT zip file to local machine and manually install it:
https://dl.google.com/android/ADT-22.6.0.zip
 1 .Download the ADT Plugin zip file (do not unzip it):
 2. Start Eclipse, then Help --> Install New Software.
 3. Click Add, in the top-right corner.
 4. In the Add Repository dialog, click Archive.
 5. Select the downloaded ADT-22.6.0.zip file and click OK.

...



2014年5月19日 星期一

windows 8.1 + microsoft account

拖了好一陣子, 還是決定試試 windows 8.1 , 看是否如想像中的 ...
果然 !

我是用hyperV的windows 8 vm (fixed-size vhd) 來試
整個從windows 8 升級到 windows 8.1 過程 要花不少時間 --

下載及安裝超過50分鐘 (cht adsl 10Mbps)

安裝完成需要重新啟動, 之後藍屏白字
(類似 Applying/Configuring/Changing  ... %...的字母, 老眼昏花 沒看仔細 )
也得要40分鐘

重新啟動完成後 碰到的
第一個問題就是remote desktop(rdp) 無法連線 :
因為關掉了 "Find devices and content"
導致network type 變成 public
public network環境讓 firewall 的預設值阻擋 rdp ...

第二個問題 無法登入
因為在升級8.1 時 一時找不著避開microsoft account (windows live account) 的方法
升級完成後, 登入的帳號就與安裝時所輸入的 microsoft account 綁在一起
( tied with microsoft account ) .
原來的本機帳戶( local account ) 似乎消失不見了 ...

第三個問題 IE 三不五時 就當掉 特別是在google.com.tw 輸入中文時,
之前在windows 8 時 還好好的,  原來 windows 8.1 自動把 IE10 也升級到 IE11 ...


[WorkArounds]

1. 將 network type 改為 private
Settings -> change PC Settings ->Network -> connections -> Ethernet -> click to show properties about the Ethernet adapter -> turn on  "Find devices and content"

2.  將與microsoft account的結解開,
 Settings -> change PC Settings ->Accounts -> Your Account -> click on "Disconnect" ...


*** 其實在升級8.1 時可以避開這個結, 當畫面要求sign-in microsoft account 時,
選擇 create new account , 然後在下一個畫面的下方 選擇
"Continue using my existing account" ...


3. 在 IE 的icon 上 right-click 再 right-click , 選擇 Run as administrator
還沒找到更方便的方法 ...
*** note, 2014.06.06, IE11的中文輸入恢復正常了, 應該是Windows 自動更新(auto update) . 在更新過程中, task tray 語言工具列 曾出現"繁體" 與 "Chinese bopomo" 並存的奇怪狀態, 後來消失了 ...










[ref]
http://windows.microsoft.com/en-us/windows-8/update-from-windows-8-tutorial

http://answers.microsoft.com/en-us/ie/forum/ie11-iewindows8_1/internet-explorer-11-on-windows-81-cannot-display/098d2a3c-6c0f-40ed-869f-97c2119c5284





2014年5月15日 星期四

Windows 命令列 + grep + php

[Q]  Windows 命令列 是否有類似 Linux 的 grep ?
* findstr
* 安裝GnuWin32 或者 Cygwin 或者 Mingw

C:\> netstat -n | findstr 3389
C:\> dir | findstr php.ini
C:\> php -i |findstr error_log


[Q]  php cli mode (php 的命令列模式) 如何設定 記錄檔 (log file)?
$ php -i | grep error_log
修改php.ini 中 error_log 的值, 確認該路徑可寫入

$ php -c /etc/php5/cli/php.ini -r " error_log('test 123'); "
$ tail /var/log/php_errors.log


[Q]  How to set error log for PHP CLI?
* chk the error_log location
* make sure php cli is run with enough permission to write to error_log file


//===
php -v
php --ini
php -i
php -h
php -r "echo 'run echo cmd'; "
php -c  myphp.conf //use myphp.conf as php.ini ???
php -c mydir  //look for php.ini under mydir

[ref]
http://stackoverflow.com/questions/1416241/is-there-a-pattern-matching-utility-like-grep-in-windows

http://stackoverflow.com/questions/6387542/php-cli-wont-log-errors

2014年4月29日 星期二

php + iis + win8

最近(2014.04) 試著在windows 8上 跑dropBox php sdk 的 sample code,
至少得有php 才行. 到php.net 下載 php5.4的zip檔, 該選 thread-safe 還是 non-thread-safe ?
應該是safe比較安全吧 ? 小心駛得萬年船?  -->  莫非 non-thread-safe 才對 ? [***]

解壓縮之後, 將php.exe的目錄加入環境變數的Path裡,

在命令列(command line, command prompt)執行
php ./examples/authorize.php  ...
php .examples/account-info.php ...
都 OK,

But

php ./examples/web-file-browser.php  ...
試了好幾次都不行 ...

只好回頭來檢查 iis 與 php 的設定,
多次參拜google 大神後, 終於發現指示 :

//===
0. 比較新也比較方便的做法就是先安裝Web Platform Installer(WebPI),
1. 執行WebPI , search php, 找到最近的php5.4.24, 按下Add,
    WebPI的左下角會顯示所選擇的套件數目 ...

2. WebPI 自動將php 安裝於
    C:\Program Files (x86)\iis express\PHP\v5.4   , 並加入 Path
    所以得將之前手動安奘所加的路徑移除 避免打架

3. 於C:\inetpub\wwwroot 建立 info.php 測試網頁
    <?php phpinfo(); ?>

4. http://localhost/info.php ... 又失敗!!!
    看看錯誤訊息 :  iis 尚未加入php 的handler. 根據 [2] 還需要加入 module mapping:

Admin Tools -> IIS manager  ->  雙擊(double click) "Handler mappings"
-> 右邊panel 上方 點選Add Module Mapping ...

//=== add module mapping
Request path: *.php
Module: FastCGImodule
Executable: C:\Program Files(x86)\php\v5.4\php-cgi.exe
Name: phpFastCgi

5. restart Default Web Site,  refresh http://localhost/info.php ,
   終於看到phpinfo()的結果了.

6. 其實還是可以手動安裝, 不過要自己去更改php.ini裡的諸多設定 [2][***]

[ref]
1.  http://support.microsoft.com/kb/2819022

2.  http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/install-and-configure-php

3. enable fastCGI
http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php


***
根據 [2] [3], 在Windows 上 應該下載 non-thread-safe (nts) 的版本, 檔案名稱中含有-nts-
[2][3] 都建議要用FastCGI 模式, 而非 ISAPI ...

2014年4月28日 星期一

Eclipse + Cannot create project content in workspace

一直沒搞清楚 Eclipse workspace 的觀念
在建立新的 project 時, 常會出問題 ...
今天想試試看DropBox 的 sdk examples,
又碰到 "Cannot create project content in workspace" 的錯誤訊息

上網搜尋找著似乎以前曾看過的文章, 還是讀不太懂 ,
不過終究歸納出解決之道:

0. project 不一定要放在workspace 的目錄下
1. 解壓縮後的sample code 先不要複製到 workspace 的目錄下

2. 建立新的project 時
簡單的方式就是先選
Create "new" project in workspace  [所以名字不能與workspace中既有的project或目錄名字相同]
之後再將解壓縮後的sample code 複製到該project的目錄下.

或者就在sample code 所在的目錄建立新project
Create new project at existing location(from existing source)
前提是1. sample code 所在的目錄不能先放在 workspace 的目錄下,
否則就會出現 "Cannot create project content in workspace" 的錯誤訊息


**** 我用的是 Eclipse Juno , 有好一陣子沒用, 也沒更新 ...

[ref]
http://stackoverflow.com/questions/9075849/cannot-create-project-content-in-workspace-when-trying-to-recreate-a-project

http://stackoverflow.com/questions/13552266/eclipse-workspaces-what-for-and-why

2014年4月15日 星期二

haxe tutorial+2, nme and flashdevelop

//=== 安裝好haxe之後
下載安裝 java sdk (1.6+?)
到flashdevelop.org 網站下載安裝 flashdevelop

http://www.flashdevelop.org/wikidocs/index.php?title=Installation
http://3hitek.blogspot.tw/2012/09/fd-flashdevelop-learning-1-debug-needs.html

於命令列安裝 nme
> haxelib install nme
> nme setup

*** 2014.04.15
haxe3 以後, nme 已轉成 openfl, 但openfl 與 nme 並不完全相容 ...
http://forum.haxepunk.com/index.php?topic=605.0
***

//== http://haxe.org/doc/start/cpp
nme uses .nmml file rather than hxml


"...
NME includes a custom build tool, mainly to handle the crossplatform assets management. The application isn't configured
using a .HXML file but with a .NMML config file, e.g.

sample.nmml :

<?xml version="1.0" encoding="utf-8"?>
<project>
  <app title="Displaying A Bitmap" main="DisplayingABitmap" package="org.haxenme.tutorial.displayingabitmap"
version="1.0.0" company="NME" />
 
  <window width="640" height="480" fps="30" orientation="portrait" resizable="true" />

  <set name="BUILD_DIR" value="Export" />
  <classpath name="Source" />
  <haxelib name="nme" />
  <assets path="Assets" rename="assets" include="*" exclude="nme.svg" />
  <ndll name="std" />
  <ndll name="regexp" />
  <ndll name="zlib" />
  <ndll name="nme" haxelib="nme" />
  <icon name="Assets/nme.svg" />
</project>
...
"

//=== 'nme' is a shortcut to 'haxelib run nme'

[nme usage samples]
nme test sample.nmml flash
nme test sample.nmml cpp
nme test sample.nmml android
nme test sample.nmml ios -simulator
nme update sample.nmml ios


haxe tutorial+1

下載/ 解壓縮/ 把檔案放到適當的目錄底下, 設定環境變數Path, ...

命令列用法:
  • haxe  -main <class>  -<target_platform> <output>  [option]+  [<input>]+
  • haxe  <hxml_file.hxml>  [option]+
[ ] 中括號裡的參數 可以省略
[ ]+ 表示可以不只一個
[<input>]+  就表示輸入的檔案可以不只一個(以空白隔開?)


-<target_platform> 支援的平台有 Flash, JavaScript, C++, PHP, Android?, Java?, ...
-swf
-js
-cpp
-php
-


[例1]
//=== 主類別 Client.hx, 輸出flash檔案 index.swf
haxe -main Client -swf index.swf

//=== 主類別 Server.hx 輸出neko檔案 server.n
haxe -main Server -neko server.n


//=== 將以上兩件工作放入 build.hxml  檔案中
#some comment
-main Client
-swf client.swf
--next
-main Server
-neko server.n
//=== 命令列
haxe build.hxml


[例2] 主類別Main.hx, 用到nme lib, tween lib
haxe -main Main -swf op1.swf -lib nme -lib tween


[ref]
http://haxe.org/doc/compiler

2014年1月28日 星期二

win8 rdp 登入到 win xp, 讀卡機無法工作

讀卡機插在xp的 USB port
從win8 使用remote desktop 登入到 win xp,
雖然 xp 裝置管理員中 讀卡機狀態正常
但是用自然人憑證/IE8開啟健保的多憑證網路承保作業 網站
輸入密碼後 出現讀卡機錯誤 3003/3009
...

但記得之前 xp/IE8/自然人憑證 用起來是沒問題的,
把鍵盤/滑鼠拿到xp的機器上 改成local 測試 ,
恢復正常了!

所以是 rdp [remote desktop] 的問題?