Search

Coder's notes

For your infomation

Screen tutorial (Fedora Linux)

If you work on terminal a lot, you might find screen is useful. Screen provides a virtual terminal which supports multiple windows, copy paste, etc. and it’ll continue to run after you have closed the real terminal you are working on. It’s distributed with most Linux distro so it’s most likely that you won’t have to install it. Just type screen to run. If it was not pre-installed or you want to update it to latest version you can try:

Fedora: sudo -c “yum install -y screen”

Ubuntu: sudo apt-get install screen

After you have started screen just type echo $STY. If you see something like 3002.pts-0.localhost you’ll know that you are inside a screen.

The features that I find most useful of screen are creating/switching/closing windows and copy paste. Let’s try these first.

Multiple windows

If you press Ctrl+a Ctrl+c (keep pressing Ctrl while you press a and then c) you can create a new screen. To switch between windows, you can try Ctrl+c Ctrl+” (double quotes) to show windows list, use arrow keys to navigate around, and then press Enter to select the windows that you want. An alternative method is to press Ctrl+[0-9] to activate the windows you want to (start from 0).

Copy paste & screen scrolling

If you want to copy paste a part on the screen, press Ctrl+a Ctrl+[ to activate copy-paste mode. After that you can use arrow keys to move around. You may use space to mark the start point and the end point. After you have marked the end point copy-paste mode will be deactivated. You also can deactivate this mode using ESC key (I often use this to scroll up and down the current window). Pasting can be done simply by pressing Ctrl+a Ctrl+]

Starting, detach and resume a screen session

To detach from a screen session, you can press Ctrl+a Ctrl+d (detaching). The screen will continue to run in the background. You can quit screen completely by Ctrl+a Ctrl+\

If you want to resume a screen session that running in the background, type screen -dr into the terminal.

Further reading

Now you knew enough to use screen. There are many more features in screen user manual at: http://www.gnu.org/software/screen/manual/screen.html

Advertisements

Javascript Game Engines

More ways to write Javascript

Javascript Design Patterns

Create Excel File with Python

Install Xlsx

$ git clone https://github.com/jmcnamara/XlsxWriter.git
$ cd XlsxWriter
$ sudo python setup.py install

Code:

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()

Create a simple site with Python, CGI, Apache 2 on Fedora

  • su to become root
  • Create the following directory structure
    • /var/www/mysite
      • cgi-bin
        • index.py
      • html
        • index.html
  • Sample content for index.py
    #!/usr/bin/python

    print(“Content-type: text/html\n”)
    print(“””
    <html>
    <body>
    Hello Python CGI <br/><a href=’../’>Home</a>
    </body>
    </html>
    “””)

  • Sample content for index.html
    <html>
    <body>
    Home <br/>
    <a href=’cgi-bin/index.py’>CGI</a>
    </body>
    </html>
  • If you use SQLite, create a sample database file.
  • edit /etc/httpd/conf/httpd.conf, add the following code to the end of the file
    ScriptAlias /mysite/cgi-bin/ /var/www/mysite/cgi-bin/
    Alias /mysite/html /var/www/mysite/

    <Directory “/var/www/mysite/cgi-bin/”>
    AddHandler cgi-script .py
    AllowOverride None
    Options +Indexes +ExecCGI
    Order allow,deny
    Allow from all
    </Directory>

    <Directory “/var/www/mysite/”>
    AllowOverride None
    # Allow open access:
    Require all granted
    </Directory>

  • Run the following code in the terminal
    chcon -h -t httpd_sys_content_t /var/www/mysite/cgi-bin/
    # You need this line if you want to write to a database file
    chcon -h -t httpd_sys_content_rw_t /var/www/mysite/cgi-bin/database.db
    chcon -h -t httpd_sys_script_exec_t /var/www/mysite/cgi-bin/*.py
    chgrp apache /var/www/mysite/html -R
    chmod uo+r /var/www/mysite/html -R
    chmod uo+x /var/www/mysite/cgi-bin -R
  • Now try to start server by typing
     service httpd start
  • Go to your website from your browser at: http://localhost/mysite/

Using Git

Clone project `foo’ of user `user‘ from Github

git clone --recursive https://github.com/user/foo

Add a submodule into a repository

git submodule add https://github.com/user/foo.git
git submodule init
git submodule update

Undo modification

git checkout -- [filename]

Update submodule to latest version

git fetch && git checkout master && git merge origin/master

Generate SSH key for passwordless push to Github

Source: https://help.github.com/articles/generating-ssh-keys/

ls -al ~/.ssh
ssh-keygen -t rsa -C "account@gmail.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

# Now add key to Github account (~/.ssh/id_rsa.pub)
https://github.com/settings/ssh

# Test connection
ssh -T git@github.com

# Update the repository remote URL to SSH
git remote set-url origin git@github.com:username/REPO.git
git remote -v

LaTeX on Windows

  • Install MikTeX
    http://miktex.org/download
  • Install TeXMaker
  • Use embedded PDF viewer
    Option > Configure TexMaker > Commands > PDF viewer > Embed (click photo to zoom)texmaker embedded

LaTeX for linguistics

Blog at WordPress.com.

Up ↑