Search

Coder's notes

For your infomation

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

Basic LaTeX for beginners

Editors

Online editors

Tools

Tutorials

Packages

Presentation Slides

Generate a time stamp in bash

echo `date +%Y-%m-%d_%H%M%S`

Blog at WordPress.com.

Up ↑