The Littlest JupyterHub - TLJH

The Jupyter project is a free software, open standards, and web services for interactive computing across all programming languages. It provides: Jupyter Notebook: the classic notebook interface JupyterLab: the next-generation notebook interface Voilà: share your results with a secure, stand-alone web applications. JupyterHub: the multi-user server for Jupyter Notebook and JupyterLab The littlest JupyterHub(TLJH): the simplest JupyterHub for a small group running on a single machine. Zero to JupyterHub with Kubernetes(Z2JH): Provides user-friendly steps to deploy JupyterHub on a cloud using Kubernetes and Helm. I was confused by the JupyterHub and TLJH since they can run on a single server with the multiple users feature but after reading The Littlest Jupyterhub by Yuvi ...

October 20, 2024 · 3 min · oopsmonk

pyenv Quick Start (Utunbu 14.04)

installation Requirements $ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm install pyenv $ cd ~ $ git clone git://github.com/yyuu/pyenv.git .pyenv $ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc $ echo 'eval "$(pyenv init -)"' >> ~/.bashrc install pyenv-virtualenv $ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv $ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc $ exec $SHELL Common Usage (Command Reference) List all available versions $ pyenv version -l Install python2.7.8 to pyenv $ pyenv install 2.7.8 List installed versions $ pyenv versions * system (set by /home/oopsmonk/.pyenv/version) 2.7.8 3.4.2 Creating a virtualenv $ pyenv virtualenv 2.7.8 mypy-2.7.8 List virtualenvs $ pyenv virtualenvs mypy-2.7.8 (created from /home/oopsmonk/.pyenv/versions/2.7.8) mypy-3.4.2 (created from /home/oopsmonk/.pyenv/versions/3.4.2) # current versions $ pyenv versions * system (set by /home/oopsmonk/.pyenv/version) 2.7.8 3.4.2 mypy-2.7.8 mypy-3.4.2 Use python via virtualenv # show current version oopsmonk@VBox:~/markdown-note$ python --version Python 2.7.6 # Change to other version oopsmonk@VBox:~/markdown-note$ pyenv activate mypy-2.7.8 (mypy-2.7.8)oopsmonk@VBox:~/markdown-note$ python --version Python 2.7.8 # Deactivate (mypy-2.7.8)oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv deactivate oopsmonk@oopsmonk-VBox:~/markdown-note$ python --version Python 2.7.8 # Why current version is 2.7.8? it's supposed to 2.7.6. oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv activate mypy-3.4.2 (mypy-3.4.2) oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv deactivate oopsmonk@oopsmonk-VBox:~/markdown-note$ python --version Python 3.4.2 oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv versions system 2.7.8 3.4.2 mypy-2.7.8 * mypy-3.4.2 (set by PYENV_VERSION environment variable) # delete a virtualenv $ pyenv uninstall mypy-2.7.8 # Go back to original system version $ alias pyenv_deactivate='pyenv deactivate && unset PYENV_VERSION' oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv activate mypy-3.4.2 (mypy-3.4.2) oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv_deactivate oopsmonk@oopsmonk-VBox:~/markdown-note$ python --version Python 2.7.6 Use python via pyenv # Global python version $ pyenv global # python version in current folder oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv local mypy-3.4.2 oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version mypy-3.4.2 (set by /home/oopsmonk/markdown-note/.python-version) oopsmonk@oopsmonk-VBox:~/markdown-note$ cd .. oopsmonk@oopsmonk-VBox:~$ pyenv version system (set by /home/oopsmonk/.pyenv/version) oopsmonk@oopsmonk-VBox:~$ cd - /home/oopsmonk/markdown-note oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version mypy-3.4.2 (set by /home/oopsmonk/markdown-note/.python-version) oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv local --unset oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version system (set by /home/oopsmonk/.pyenv/version) # python version in current shell oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv shell mypy-3.4.2 oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version mypy-3.4.2 (set by PYENV_VERSION environment variable) oopsmonk@oopsmonk-VBox:~/markdown-note$ cd - /home/oopsmonk oopsmonk@oopsmonk-VBox:~$ pyenv version mypy-3.4.2 (set by PYENV_VERSION environment variable) oopsmonk@oopsmonk-VBox:~$ pyenv shell --unset oopsmonk@oopsmonk-VBox:~$ pyenv version system (set by /home/oopsmonk/.pyenv/version) oopsmonk@oopsmonk-VBox:~$ cd - /home/oopsmonk/markdown-note oopsmonk@oopsmonk-VBox:~/markdown-note$ pyenv version system (set by /home/oopsmonk/.pyenv/version)

December 10, 2014 · 2 min · oopsmonk

Web dev example : JSON & jQuery Mobile & Bottle

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. jQuery Mobile base on jQuery for mobile device. jQuery vs. jQuery Mobile vs. jQuery UI Install bottle: $ sudo apt-get install python-setuptools $ easy_install bottle Demo server deployment file structure: BottlejQuery ├── bottleJQuery.py └── index.html run command: $ ./bottleJQuery.py connect to server: http://localhost:8080/bottle Building simple web server use bottle bottleJQuery.py #!/usr/bin/env python from bottle import route, static_file, debug, run, get, redirect from bottle import post, request import os, inspect, json #enable bottle debug debug(True) # WebApp route path routePath = '/bottle' # get directory of WebApp (bottleJQuery.py's dir) rootPath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) @route(routePath) def rootHome(): return redirect(routePath+'/index.html') @route(routePath + '/<filename:re:.*\.html>') def html_file(filename): return static_file(filename, root=rootPath) @get(routePath + '/jsontest') def testJsonGET(): print "GET Header : \n %s" % dict(request.headers) #for debug header return {"id":2,"name":"Jone"} @post(routePath + '/jsontest') def testJsonPost(): print "POST Header : \n %s" % dict(request.headers) #for debug header data = request.json print "data : %s" % data if data == None: return json.dumps({'Status':"Failed!"}) else: return json.dumps({'Status':"Success!"}) run(host='localhost', port=8080, reloader=True) Test GET request: $ curl -i -X GET http://localhost:8080/bottle/jsontest HTTP/1.0 200 OK Date: Wed, 07 Aug 2013 16:03:53 GMT Server: WSGIServer/0.1 Python/2.7.3 Content-Length: 25 Content-Type: application/json {"id": 2, "name": "Jone"} bottle debug message: ...

August 7, 2013 · 4 min · oopsmonk

Sending HTML Mail Using SMTP With Authorization

Here is a text/plain MIME type parts in official exmaple code. I remove it from my sample code, because it’s not show up in mail at Office Outlook 2010. #!/usr/bin/env python """ File name: sendMail.py Python send HTML mail using SMTP with authorization Usage : ./sendMail.py to@gmail.com Subtitle [ FilePath | txt ] """ import smtplib import sys,traceback from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from time import gmtime, strftime #log file location log_path = "./mail-log"; #log timestamp format logger_tstamp = "%Y-%m-%d %H:%M:%S" #SMPT server smtp_server = "smtp.gmail.com" #gmail 465 or 578 smtp_port = 587 #mail from user = "from@gmail.com" pwd = "password" # log method class Logger: file = 1 err = 2 class ContentType: file = 1 txt = 2 #select log method debug_log = Logger.err #select content type content_type = ContentType.txt def debug(msg): if debug_log == Logger.file: with open(log_path, 'a') as log_file: log_file.write(strftime(logger_tstamp, gmtime()) + msg) log_file.close() elif debug_log == Logger.err: sys.stderr.write(strftime(logger_tstamp, gmtime()) + msg) else: print(strftime(logger_tstamp, gmtime()) + msg) #check argument number arg_count = len(sys.argv) if arg_count !=4: debug("[Error]: invalid argument\n") sys.exit(1) try: mail_to = sys.argv[1] subject = sys.argv[2] if content_type == ContentType.file: content_path = sys.argv[3] with open(content_path, 'r') as f_content: content = f_content.read() f_content.close() else: content = sys.argv[3] serv = smtplib.SMTP(smtp_server, smtp_port) # serv.ehlo() serv.starttls() # serv.ehlo() serv.login(user, pwd); msg = MIMEMultipart('alternative') msg['Subject'] = subject msg['From'] = user msg['To'] = mail_to part1 = MIMEText(content, 'html') msg.attach(part1) serv.sendmail(user, mail_to, msg.as_string()) serv.quit() debug("[Debug] subject : " + subject + "\n") except: debug("[Error]: send mail error\n") debug("[Error]:\n" + traceback.format_exc()) sys.exit(2); Reference: email: Examples smtplib How to send email in Python via SMTPLIB ...

July 31, 2013 · 2 min · oopsmonk

Nginx Error - 413 Request Entity Too Large

nginx version: nginx/1.1.19, OS: Ubuntu12.04 Default nginx accepted body size limitation is 1MB. You can add client_max_body_size in nginx.conf. This parameter can put in http, server and location sections of configutation file. Enlarge body size to 10MB client_max_body_size 10M Or just disable it client_max_body_size 0 For example enlarge body size to 10MB Add to http section: $ sudo vi /etc/nginx/nginx.conf http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; client_max_body_size 10M; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ... } Or modify server and location section ...

June 5, 2013 · 1 min · oopsmonk

Web Micro Framework Battle

WSGI Micro Framworks 這陣子一直在找適合的Micro Framwork玩第一次的Web Application. 最後選擇用Bottle, 原因是: Single file module, no dependencies with other library. Document 但是好不好用又是另一回事, 用了就知道..XD 以下是由WSGI.org列出的Micro Framwork: bobo Bobo is a light-weight framework. Its goal is to be easy to use and remember. Bottle Bottle is a fast and simple micro-framework for small web-applications. It offers request dispatching (Routes) with url parameter support, Templates, key/value Databases, a build-in HTTP Server and adapters for many third party WSGI/HTTP-server and template engines. All in a single file and with no dependencies other than the Python Standard Library. ...

May 27, 2013 · 1 min · oopsmonk