Archive for October, 2015

Oct
23

sublime text 2 build configuration

Sublime is a great editor, it can deal with nearly all programming languages and expecially fit for web developer.

I tried the sublime for Python. For beginner, you should do the following settings:

  • Install the package control
    • usage: ctrl+shift+p  -> install packages
  • configure the your build system:
    • For example python 3:
      Tools -> Build System -> New Build System -> (create file: python3)

      {
          "cmd": ["python3", "-u", "$file"],
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python",
          "encoding": "utf8",
          "path": "/Library/Frameworks/Python.framework/Versions/3.3/bin/"
      }
      
      • The file is in : %AppData%\Roaming\Sublime Text 2\Packages\User
    • or just install the package: ctrl+shift+p -> install packages -> python 3 & cython+
    • The customed build system file is located in %AppData%\Roaming\Sublime Text 2\Packages\Python3.sublime-build
  • If you want to delete the file, you can directly delete it or install a package with: PackageResourceViewer

References:

https://packagecontrol.io/packages/Python%203

http://stackoverflow.com/questions/23161604/how-to-set-which-version-of-python-sublime-text-uses

http://stackoverflow.com/questions/27338255/sublime-text-3-removing-build-systems

Oct
23

Configure Git for RStudio

There is an article from RStudio explained how to configure Git for RStudio. But it is not very detailed. I ran into many problem during the configuration and wasted a lot of time just for configuration.  So I decided to write down all the steps.

For https connection:

  1. install git
  2. RStudio -> Tools -> Global options -> Git/SVN -> configure the git: C:/Program Files/Git/mingw64/bin/git.exe
  3. RStudio -> Tools -> Project options -> Git/SVN  -> Choose Git
  4. Restart RStudio
  5. In this project, open the Shell: RStudio -> Tools -> Shell, configure your remote repository adress
    git remote add origin https://{username}:{password}@github.com/{username}/project.git
    or https://{username}@github.com/{username}/project.git
    git push -u origin master
  6. Notice: If you already setted the adress, you can change it with:
    git remote set-url origin https://{username}:{password}@github.com/{username}/project.git

For ssh connection:

  • do the same 1 to 4 steps like the https connection.
  • open shell: git remote add origin git@github.com/{username}/project.git
  • generate SSH key: Tools -> Global options -> Git/SVN -> SSH RSA Key -> Generate RSA Key
  • view public key -> copy it
  • Open your github etc repositories -> add the public key to your account
  • If you installed the Putty, you will get a big problem, the RStudio can not find the ssh.exe, So you have to specify the ssh path:
    set the evironment variable: systemsteuerung -> system und sicherheit -> system -> erweiterted Systemeinstellungen -> Erweitert -> Umgebungsvariablen -> “GIT_SSH”: C:\Program Files\Git\usr\bin\ssh.exe

There are several useful links for the configuration problems:

Oct
16

Animating a point walking flow with python

Using the SimpleGUICS2Pygame can animate the walking path easily. (The SimpleGUICS2Pygame is a implementation of simplegui.)

I wrote an small code for the simulation in codeskulptor, you can run it directly and see the effect:

http://www.codeskulptor.org/#user40_o37gkz7Wyy_11.py

But you need to install and import it at first:

  • installation:
    >>> pip install SimpleGUICS2Pygame
  • import:
    import SimpleGUICS2Pygame.simpleguics2pygame as simplegui

 

The most important part of this code is the timer_handler() function: which frequently updates the circle position.

Settings:

line 15: input your walking flow points

line 18: set your background image

line 21: set the smoothing of the animation: from 1 to 1000

Oct
16

solution for installing pygame

I have two computers, the one has windows system at home, the other has ubuntu system in my office. In each computer, I have two python, the one is normal python, the other is anaconda.

I try to install the pygame on both computer, then I got in chaos. My computer can not find it, even I installed pygame with pip several times.

After some effort, I got the solution:

download the pygame binary distribution for your operating system:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

Windows:

  • For normal python: pip install your_download_path\downloaded_pygame
  • For anaconda python:
    • use the anaconda pip
    • pip install your_download_path\downloaded_pygame

Linux:

Setting in Eclipse:
In eclipse, you can set the python interpreter by yourself

  • In menu: Project -> Properties ->  pyDev-Interpreter/Grammar -> Click here to configure an interpreter not listed -> New -> …
  • you can also set PYTHONPATH: Project -> Properties -> pyDev-PYTHONPATH (you can also set the external library here)

check the loaded packages in project:

  • In the “PyDev Package Explorer” viewer:
    • under all the project file, your can see your python interpreter name, double click, all the installed packages are listed here. 🙂