tag:blogger.com,1999:blog-84441865731416772862024-03-06T05:24:35.512+08:00Open or not open, that is the stupid question.Recommend to use google chrome to browse this blog. Let's Rock~Stanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.comBlogger408125tag:blogger.com,1999:blog-8444186573141677286.post-5975361131041780832017-03-13T07:30:00.001+08:002017-03-13T07:30:39.890+08:00[Level 1] Lost and Found in gitOnce you get lost in git and you could try to find it by the following commands
<pre class="prettyprint lang-py linenums:1">
$ git fsck --lost-found
$ git reset HEAD@{1}
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-67400757571721654012017-03-10T15:59:00.001+08:002017-03-10T15:59:37.001+08:00[Level 1] Reversion of gitJust read an article mentioned about the reversions of git, so take a note here.
<pre class="prettyprint lang-py linenums:1">
G H I J
\ / \ /
D E F
\ | / \
\ | / |
\|/ |
B C
\ /
\ /
A
A = = A^0
B = A^ = A^1 = A~1
C = A^2 = A^2
D = A^^ = A^1^1 = A~2
E = B^2 = A^^2
F = B^3 = A^^3
G = A^^^ = A^1^1^1 = A~3
H = D^2 = B^^2 = A^^^2 = A~2^2
I = F^ = B^3^ = A^^3^
J = F^2 = B^3^2 = A^^3^2
</pre>
reference: <a href="http://schacon.github.io/git/git-rev-parse#_specifying_revisions">http://schacon.github.io/git/git-rev-parse#_specifying_revisions
</a>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-54505858691485717282017-02-18T11:12:00.001+08:002017-02-18T11:13:25.219+08:00[ Level 1 ] Limit memory usage in Python programWe could limit memory usage in Python program.
<pre class="prettyprint lang-py linenums:1">
#!/usr/bin/env python3.5
import resource
def show_memory_limit():
soft, hard = resource.getrlimit(resource.RLIMIT_DATA)
print 'Soft limit changed to :', soft
print 'Hard limit changed to :', hard
def set_memory_limit(soft, hard):
resource.setrlimit(resource.RLIMIT_DATA, (soft, hard)) #limit to one kilobyte
if __name__ == '__main__':
show_memory_limit()
set_memory_limit(1024, 2048)
show_memory_limit()
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-29530141440742234352016-12-30T22:41:00.003+08:002016-12-30T22:41:51.082+08:00[Level 1] Install RStudio on Ubuntu 16.04One you have installed R on Ubuntu, there is a great R develop environment called "RStudio". You could install "R Studio" via apt-get command.
<pre class="prettyprint lang-html">
$ sudo apt-get -y install rstudio
$ rstudio
</pre>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi90hATL7NqVCb-202HCkvOJR-SjetMunsImDw_mGGF42WI0Bcv_LUJjVXRxWJIRqNG-wqRKe1zrHvMIbXxSaMAT5raV4yTcB-7VNPiJ8_uWJAFr7eSRAnmbQAi7yzmCPQZYPlWY6_fmY0/s1600/Screenshot+from+2016-12-30+22-39-36.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi90hATL7NqVCb-202HCkvOJR-SjetMunsImDw_mGGF42WI0Bcv_LUJjVXRxWJIRqNG-wqRKe1zrHvMIbXxSaMAT5raV4yTcB-7VNPiJ8_uWJAFr7eSRAnmbQAi7yzmCPQZYPlWY6_fmY0/s320/Screenshot+from+2016-12-30+22-39-36.png" width="320" height="112" /></a>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-89221966864709101742016-12-30T22:35:00.001+08:002016-12-30T22:35:29.884+08:00[Level 1] Install R in UbuntuHere are the steps to install R on Ubuntu 16.04
<pre class="prettyprint lang-html">
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/'
$ sudo apt-get update
$ sudo apt-get -y install r-base r-base-core
$ sudo -i R ## test R
</pre>
Here are the steps to instal R packages from CRAN
<pre class="prettyprint lang-html">
$ sudo -i R
> install.packages('__package_name__')
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-28937100942898639512015-11-30T18:38:00.001+08:002015-11-30T18:38:33.257+08:00[Level 1] How to setup Debian for sharing screen on WebEx.I installed Debian 8 on my laptop but cannot share my screen on WebEx. After I google it and I found I could share my screen by installing the following packages.
<pre class="prettyprint lang-html">
libgcj14-awt:i386
libpangoft2-1.0-0:i386
libpangox-1.0-0:i386 libxft2:i386
libpangoxft-1.0-0:i386
libgtk2.0-0:i386libxmu6:i386
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-53828082760058726612015-07-31T10:13:00.001+08:002015-07-31T10:13:18.348+08:00[ Level 1 ] What could we do in Sprint 0?There are many different opinions about if team should have Sprint 0 or not. In my opinion, Sprint 0 is a good for team, because it could avoid team to take pressure immediately if no more Sprint 0.1, 0.2, 0.3...etc.
What will I do in Sprint 0? Here is a task list of Sprint 0.
<pre class="prettyprint lang-html">
* Kick-Off
* Agile/Scrum training. (SM)
=> http://scrummethodology.com/
=> http://scrumreferencecard.com/scrum-reference-card/
=> 2 half day training.
* Auto training. (Auto)
* Schedule regular meetings. (SM)
* Define user stories. (PO)
* Define DoD. (Team)
* Prepare developing/testing/integration environment.
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-73980116107760286182014-08-23T07:50:00.002+08:002015-07-20T23:07:54.439+08:00[Level 1] git ignoreIf you want git not to commit some temporary files or log files...etc.,
you could create .gitignore file to ignore them.
If you don't have any idea about which file should be ignore,
you could also download ignore templates that prepared by github.
<pre class="prettyprint lang-py linenums:1">
mkdir ~/git-home
cd ~/git-home
git init
git clone https://github.com/github/gitignore
cd ~/my_py_project
cp ~/git-home/gitignore/Python.gitignore ./.gitignore
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-14981777697610359522014-08-19T14:36:00.000+08:002014-08-19T15:01:23.905+08:00[Level 1] HOWTO Installing Packages from Yaourt AUR in Archlinux.If you want to install packages from Yaourt(Yet AnOther User Repository Tool ) AUR(Archlinux User Repository),
you could follow the following steps.
a. Install yaourt by downloading source code.
<pre class="prettyprint lang-html">
1. Install development environment.
$ sudo pacman -S base-devel
$ sudo pacman -S yajl
2. Download, build and install package-query
$ curl -O https://aur.archlinux.org/packages/pa/package-query/package-query.tar.gz
$ tar zxvf ./package-query.tar.gz
$ cd ./package-query
$ makepkg -si
3. Download, build and install Yaourt
$ wget https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
$ tar zxvf ./yaourt.tar.gz
$ cd ./yaourt
$ makepkg -si
</pre>
b. Install yaourt from repository.
<pre class="prettyprint lang-html">
1. setup repository
$ sudo su
# cat >> /etc/pacman.conf <<EOF
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
EOF
2. update repository and install yaourt
# pacman -Syu
# pacman -Ss yaourt
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-89480596088840642282014-08-15T23:09:00.004+08:002014-08-15T23:09:30.975+08:00[Level 1] Create git repository by command.A script for creating git repository quickly.
<a href="http://viget.com/extend/create-a-github-repo-from-the-command-line">http://viget.com/extend/create-a-github-repo-from-the-command-line</a>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-11160872990608953682014-08-14T08:52:00.001+08:002014-08-14T08:52:50.073+08:00[ Level 1 ] Go installation and "Hello World" sample.A friend of mine told me, if you could choose the programming language, choose the fashion one.
I tried to use Go becuase it's "Go fashion"(Chinglish, means, fashion enough).
The following script is the way to install Go in CentOS, you could refer to it if you also used CentOS.
<pre class="prettyprint lang-py linenums:1">
#!/bin/bash
# install Go, gcc for Go
rpm -q golang >/dev/null 2>&1 || sudo yum -y install golang libgo gcc-go
# Hello World
[ -e ./HelloWorld.go ] || cat > ./HelloWorld.go <<EOF
package main
import "fmt"
func main() {
fmt.Println("Hellow World!")
}
EOF
# run as interpreter script
go run ./HelloWorld.go
# compile script and run it.
gccgo -g -o ./HelloWorld.out ./HelloWorld.go && ./HelloWorld.out
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-64181769582784223902014-08-12T15:01:00.002+08:002014-08-12T15:01:40.246+08:00[ Level 1 ] Tips for sublime text.Good tips for sublime.
<pre class="prettyprint lang-html">
http://nipunbatra.wordpress.com/2014/01/30/plugins-for-python-development-in-sublime-text/
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-86306721943150563622014-07-23T09:12:00.000+08:002014-07-23T09:12:28.358+08:00[Level 1] Install skype in CentOS 7.If you want to install skype in CentOS 7.
You need to download 32 bit library.
Or you could lookup nux-desktop and it already has made for 32 bit libraries that required by skype.
<pre class="prettyprint lang-html">
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm;
sudo yum localinstall http://download.skype.com/linux/skype-4.3.0.37-fedora.i586.rpm;
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-69609233940981236902014-07-18T13:46:00.001+08:002014-09-06T22:06:15.435+08:00[Level 1] How to install 32 bit java for Juniper VPN in CentOS.<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint lang-py linenums:1">##
## Precondition: you have to download 32 bit openjdk first!
##
compat_32="compat-libstdc++-296"
libs_for_vpn="xterm ld-linux.so.2 libstdc++.so.6 libz.so.1 libXext.so.6 libXrender.so.1"
java_64_rpms="java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64 icedtea-web-1.4.1-0.el6.x86_64"
libs_for_java_32="giflib.i686 nss.i686 libpng12.so.0 libpulse.so.0 rhino"
java_32_rpm_url="ftp://ftp.muug.mb.ca/mirror/centos/6.5/os/i386/Packages/java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.i686.rpm"
java_32_rpm="`basename $java_32_rpm_url`"
download_dir="/tmp"
## download 32bit java
cd $download_dir; wget $java_32_rpm_url
## remove native openjdk
sudo yum -y remove java-1.7.0-openjdk
## install 32 compatible libraries
for app in $compat_32
do
sudo yum -y install $app
done
## install libraries for vpn
for app in $libs_for_vpn
do
sudo yum -y install $app
done
## install 64 bit java
for app in $java_64_rpms
do
sudo yum -y install $app
done
## setup alternative java
sudo update-alternatives --set java /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
## install libraries for 32 bit java
for app in $libs_for_java_32
do
sudo yum -y install $app
done
## install 32 bit java
sudo rpm -ihv $java_32_rpm
</pre>
Wish this helps.<br />
<br />
regards,<br />
Stanley Huang
</div>
Stanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-26698658350516307582014-07-17T22:39:00.000+08:002014-07-17T22:39:10.437+08:00[Level 1] How to yum to install specific version in CentOS.<div dir="ltr" style="text-align: left;" trbidi="on">
If you want to use yum to install specific version in CentOS.
First, you have to use option "--showduplicates" to get duplicate versions
<br />
<pre class="prettyprint lang-html"># yum --showduplicates list java-1.7.0-openjdk
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* elrepo: ftp.ne.jp
* epel: ftp.cuhk.edu.hk
* extras: mirror01.idc.hinet.net
* remi: remi.kazukioishi.net
* rpmforge: ftp.riken.jp
* updates: mirror01.idc.hinet.net
Available Packages
java-1.7.0-openjdk.x86_64 1:1.7.0.45-2.4.3.3.el6 base
java-1.7.0-openjdk.x86_64 1:1.7.0.45-2.4.3.4.el6_5 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.51-2.4.4.1.el6_5 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.55-2.4.7.1.el6_5 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.65-2.5.1.2.el6_5 updates
</pre>
After you got the information of versions, then you could install option of yum to install specific version.
<pre class="prettyprint lang-html"># yum install java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* elrepo: ftp.ne.jp
* epel: ftp.cuhk.edu.hk
* extras: mirror01.idc.hinet.net
* remi: remi.kazukioishi.net
* rpmforge: ftp.riken.jp
* updates: mirror01.idc.hinet.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.45-2.4.3.3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
java-1.7.0-openjdk x86_64 1:1.7.0.45-2.4.3.3.el6 base 26 M
Transaction Summary
======================================================================================================================================
Install 1 Package(s)
Total download size: 26 M
Installed size: 90 M
Is this ok [y/N]: y
...
</pre>
<br />
Wish this helps.<br />
<br />
regards,<br />
Stanley Huang</div>
Stanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-8115321085684765552014-06-18T22:50:00.000+08:002014-06-18T22:50:05.074+08:00[Level 2] Python reverse engineering.If you want to reverse engineering of python source code,
you could use pylint to get class diagram.
ref:
http://manpages.ubuntu.com/manpages/saucy/man1/pyreverse.1.html
http://www.logilab.org/6883
http://planet.logilab.fr/index.php?post_id=74
<pre class="prettyprint lang-html">
$ apt-cache search pyreverse
pylint - python code static checker and UML diagram generator
...
$ sudo apt-get -y install pylint
$ pyreverse ./*.py
$ dotty ./classes_No_Name.dot
$ doggy ./packages_No_Name.dot
or
$ pyreverse -o png ./*.py
$ eog ./classes_No_Name.png
$ eog ./packages_No_Name.png
</pre>
related projects:
http://floss.zoomquiet.io/data/20041231094746/index.html
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-65179160375328985352014-06-18T22:09:00.000+08:002014-06-18T22:50:19.672+08:00[Level 1] How to trace the source code more efficient.If you want to trace python call stack,
you could get call sequence by using call_seq module.
You could download call_seq from pypi website.
https://pypi.python.org/pypi/call_seq/0.0.1
After you download it, you could prepare the python script like following.
<pre class="prettyprint lang-py linenums:1">
python from call_seq import CallSeq
trail = CallSeq()
trail.set_trace()
# the code you want to trace.
trail.unset_trace()
trail.dump_to_file('output.json')
</pre>
After you create the output json file,
then you could use browser module of call_seq to get visualization of call sequence.
<pre class="prettyprint lang-html">
$ python -m call_seq.browser ./output.json
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-72282576865362401182014-04-08T19:04:00.003+08:002014-04-18T14:03:43.262+08:00[ Level 2 ] Test Singleton Implementation in Python.Days ago, just search how to use implement "Singleton" design pattern.
(<a href="http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python">http://stackoverflow.com/questions/6760685/crea(ing-a-singleton-in-python</a>)
And today, I just need to implement for it.
In my case, I need to create mutliple loggers and I also want to use "Singleton" to reduce system resource usage.
Therefore, I create a Singleton meta class and also use a parameter called "singleton_id" to define the instance category.
Source Code:
<pre class="prettyprint lang-py linenums:1">
#!/bin/env python
class Singleton(object):
_singleton_key = 'singleton_id'
_instance = {}
def __new__(class_, *args, **kwargs):
if class_._singleton_key not in kwargs.keys():
kwargs[class_._singleton_key] = ''
if class_._singleton_key in kwargs and kwargs[class_._singleton_key] not in class_._instance.keys():
class_._instance[kwargs[class_._singleton_key]] = object.__new__(class_)
return class_._instance[kwargs[class_._singleton_key]]
class mySingleton(Singleton):
def __init__(self, name, singleton_id=None):
self.name = name
pass
a0 = mySingleton('a')
print a0
print a0.name
a1 = mySingleton('a', singleton_id='a')
print a1
print a1.name
a2 = mySingleton('a', singleton_id='a')
print a2
print a2.name
a3 = mySingleton('b', singleton_id='a')
print a3
print a3.name
a4 = mySingleton('b', singleton_id='a')
print a4
print a4.name
print '----'
print a0
print a0.name
print a1
print a1.name
print a2
print a2.name
</pre>
Output:
<pre class="prettyprint lang-html">
<__main__.mySingleton object at 0x7f2248065f10>
a
<__main__.mySingleton object at 0x7f2248065f50>
a
<__main__.mySingleton object at 0x7f2248065f50>
a
<__main__.mySingleton object at 0x7f2248065f50>
b
<__main__.mySingleton object at 0x7f2248065f50>
b
----
<__main__.mySingleton object at 0x7f2248065f10>
a
<__main__.mySingleton object at 0x7f2248065f50>
b
<__main__.mySingleton object at 0x7f2248065f50>
b
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-63858751478865423442014-04-07T17:07:00.001+08:002014-04-07T17:07:48.610+08:00[Level 2] pstree implementation with Python.Because I couldn't find pstree command in our company's product.
Therefore, I just search from internet and found someone implement pstree layout with Python.
(http://stackoverflow.com/questions/16395207/create-a-process-tree-like-pstree-command-with-python-in-linux)
And I just modify it and create a pstree.py system utility.
<pre class="prettyprint lang-py linenums:1">
#!/bin/env python
'''
## Implement pstree in Python
## data structure of tree, cmd_list
tree = {
0: [1],
1: [2, 3],
2: [5, 6, 7, 8],
...
}
cmd_list = {
0: '/sbin/init',
1: '[kthreadd]',
...
}
'''
import os
import sys
import re
tree = {}
cmd_list = {}
def printTree(parent, tree, cmd_list, indent=''):
print '%s:%s' % (parent, cmd_list[parent])
if parent not in tree:
return
for child in tree[parent][:-1]:
sys.stdout.write(indent + '|-')
printTree(child, tree, cmd_list, indent + '| ')
child = tree[parent][-1]
sys.stdout.write(indent + '`-')
printTree(child, tree, cmd_list, indent + ' ')
## __main__
for l in [ re.sub('[ ]+', ' ', l.lstrip().rstrip()) for l in os.popen('ps -e -o pid,ppid,command --no-heading').readlines() ]:
pid = int(l.split(' ')[0])
ppid = int(l.split(' ')[1])
cmd = ' '.join(l.split(' ')[2:])
if ppid not in tree.keys():
tree[ppid] = []
tree[ppid].append(pid)
cmd_list[pid] = cmd
# print tree
# print cmd_list
pid = 1
if len(sys.argv) > 1:
pid = int(sys.argv[1])
printTree(pid, tree, cmd_list)
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-81555926677572719162014-04-02T22:09:00.001+08:002014-04-03T11:17:12.506+08:00[Level 1] Create secure web for iPython notebook.The default protocol for iPython notebook is http and you didn't passphrase to enter notebook.
If you want your notebook be secure, you could follow the steps to enable SSL and passphrase for it.
1. create profile:
<pre class="prettyprint lang-py linenums:1">
In [1]: ## create profile for secure web
!ipython profile create secureweb
</pre>
2. create passphrase:
<pre class="prettyprint lang-py linenums:1">
In [2]: ## create passphrase
from IPython.lib import passwd
passwd(passphrase='passphrase')
</pre>
Out[2]: 'sha1:24be7c5ab59a:b8b7d3c691b2db67a5ef855b625cb560e125e5e1'
3. Create SSL certificate
<pre class="prettyprint lang-py linenums:1">
$ cd /home/stanley/iPython_notebook/certs
$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
Generating a 1024 bit RSA private key
..............++++++
..........++++++
writing new private key to 'mycert.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:TW
State or Province Name (full name) [Some-State]:Taiwan
Locality Name (eg, city) []:Taipei
Organization Name (eg, company) [Internet Widgits Pty Ltd]:StanleyHuang
Organizational Unit Name (eg, section) []:Stanley
Common Name (e.g. server FQDN or YOUR name) []:Stanley
Email Address []:wenlien1001@gmail.com
$
</pre>
4. Modify iPython notebook config.
<pre class="prettyprint lang-html">
$ cat ~/.config/ipython/profile_secureweb/ipython_notebook_config.py
c = get_config()
c.IPKernelApp.pylab = 'inline'
c.NotebookApp.certfile = u'/home/stanley/iPython_notebook/certs/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:24be7c5ab59a:b8b7d3c691b2db67a5ef855b625cb560e125e5e1'
c.NotebookApp.port = 9999
...
$
</pre>
5. Restart iPython notebook, login with https protocol and enter the passphrase.
<pre class="prettyprint lang-html">
$ ipython notebook --profile=secureweb
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-45637326446195348542014-04-02T21:55:00.000+08:002014-04-03T11:17:25.819+08:00[Level 1] Install slideshow support in iPython notebook.Just found an iPython notebook extension support slideshow
and you could install by the following steps.
Precondition:
Because this introduction would try to clone a github project,
you have install git utility first.
<pre class="prettyprint lang-html">
$ sudo apt-get -y install git
</pre>
1. Use the following commands to install slideshow support.
<pre class="prettyprint lang-py linenums:1">
## get porfile directory
profile_dir = get_ipython().profile_dir.location
## clone extension from github
import os
tgt = os.path.join( profile_dir, 'static', 'custom')
!git clone https://github.com/ipython-contrib/IPython-notebook-extensions.git $tgt
%cd $tgt
## create a javascript for supporting slideshow
%%writefile custom.js
// we want strict javascript that fails
// on ambiguous syntax
"using strict";
// do not use notebook loaded event as it is re-triggerd on
// revert to checkpoint but this allow extesnsion to be loaded
// late enough to work.
//
$([IPython.events]).on('app_initialized.NotebookApp', function(){
/** Use path to js file relative to /static/ dir without leading slash, or
* js extension.
* Link directly to file is js extension.
*
* first argument of require is a **list** that can contains several modules if needed.
**/
// require(['custom/noscroll']);
// require(['custom/clean_start'])
// require(['custom/toggle_all_line_number'])
// require(['custom/gist_it']);
/**
* Link to entrypoint if extesnsion is a folder.
* to be consistent with commonjs module, the entrypoint is main.js
* here youcan also trigger a custom function on load that will do extra
* action with the module if needed
**/
require(['custom/slidemode/main'],function(slidemode){
// // do stuff
})
});
</pre>
2. restart iPython Notebook and reload page to get slideshow button. (Just on the right of cell type)
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-91374794221480320512014-04-01T22:59:00.000+08:002014-04-03T11:16:56.296+08:00[Level 1] How to auto restore when start iPythoniPython have a magic command call "alias".
This command just command "alias" in unix shell could help you to create alias command in iPython environment.
How could we save the alias that we created before, you could use "store" magic command.
The alias would be saved in iPython internal db.
ex.
<pre class="prettyprint lang-html">
In [1]: %alias ipython_alias echo 'hello world'
In [2]: %store ipython_alias
</pre>
After you exit iPython and restart it again,
you need to restore the aliases from internal db.
<pre class="prettyprint lang-html">
In [1]: %store -r
</pre>
And how could we make iPython auto-restore when we launch it?
You could modify ipython_config.py in profile.
ex. If you use default profile
<pre class="prettyprint lang-html">
$> cat /home/stanley/.config/ipython/profile_default/ipython_config.py
...
# StoreMagics configuration
c.StoreMagics.autorestore = True # uncomment this line and assign autorestore as 'True'
...
</pre>
You could also create a script to add alias automatically.
<pre class="prettyprint lang-py linenums:1">
## Add often use commands.
security_commands = 'chmod chown scp ssh sudo'
network_commands = 'ifcofig netstat ping route'
system_commands = 'iostat ps top vmstat'
common_commands = 'cat grep head nohup tail'
editor_commands = 'meld soffice vi'
sourcecode_commands = 'apt-cache apt-get easy_install git p4 pip'
## prepare command list
command_list = ' '.join([security_commands, network_commands, system_commands, common_commands, editor_commands, sourcecode_commands])
for cmd in command_list.split(' '):
%alias $cmd $cmd
%store $cmd
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-72169374637927713982014-02-06T21:41:00.002+08:002014-02-06T21:50:57.136+08:00[ Level 1 ] Install libraries for juniper vpn in 13.10<pre class="prettyprint lang-py linenums:1">
$ sudo apt-get remove sudo apt-get remove openjdk-6-jdk icedtea-6-plugin
$ sudo apt-get install openjdk-7-jdk icedtea-7-plugin
$ sudo apt-get install openjdk-7-jre:i386
$ sudo apt-get install libstdc++6:i386 lib32z1 lib32ncurses5 lib32bz2-1.0 libxext6:i386 libxrender1:i386 libxtst6:i386 libxi6:i386
</pre>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-29955694537855379922013-06-28T18:36:00.001+08:002013-06-28T18:37:38.081+08:00[Level 1] Synergy -- Multi hosts share the same keyborad/mouse.There is a software call "Synergy" that could let mutli hosts share the same keyborad/mouse (virtual-KVM).<br>
<a href="http://synergy-foss.org">http://synergy-foss.org</a><br>
It's funny, try it.<br>
<br>
Wish this helps.<br>
<br>
regards,<br>
Stanley HuangStanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0tag:blogger.com,1999:blog-8444186573141677286.post-70036156053712607532013-06-26T17:42:00.002+08:002013-06-26T17:42:47.989+08:00[ Level 1 ] Assign external python path to program.<div dir="ltr" style="text-align: left;" trbidi="on">
Sometimes, you want to assign external python path to program, then you could use "PYTHONPATH" environment variables for this purpose.
ex.
<br />
<pre class="prettyprint lang-py linenums:1">$ PYTHONPATH=/tmp/my_python_path python - <<EOF
> import sys
> print sys.path
> EOF
['', '/tmp/my_python_path', '/usr/lib/python2.7', ...]
$
</pre>
Wish this helps.<br />
<br />
regards,<br />
<br />
Stanley Huang</div>Stanley Huanghttp://www.blogger.com/profile/08590821090529939664noreply@blogger.com0