Saturday, November 1, 2014

Python Threading Module Walkthrough

Python Threading Module

This is a walk through of python module Threading .It is built on top of the lower-level thread module, it is a short read: https://docs.python.org/2/library/thread.html. Threading module is a higher level module that wraps around thread and provides friendly API.


Lock

Lock is for resource management, at one time, only one thread can have the lock. Python thread module lock can be released from another thread:

lock.release()
Releases the lock. The lock must have been acquired earlier, but not necessarily by the same thread.

In threading

a document

The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel.

Switch to another document

All your local documents are listed in the document panel. You can switch from one to another by clicking a document in the list or you can toggle documents using Ctrl+[ and Ctrl+].

Rename a document

You can rename the current document by clicking the document title in the navigation bar.

Delete a document

You can delete the current document by clicking Delete document in the document panel.

Export a document

You can save the current document to a file by clicking Export to disk from the menu panel.

Tip: Check out the Publish a document section for a description of the different output formats.


Synchronization

StackEdit can be combined with Google Drive and Dropbox to have your documents saved in the Cloud. The synchronization mechanism takes care of uploading your modifications or downloading the latest version of your documents.

Note:

  • Full access to Google Drive or Dropbox is required to be able to import any document in StackEdit. Permission restrictions can be configured in the settings.
  • Imported documents are downloaded in your browser and are not transmitted to a server.
  • If you experience problems saving your documents on Google Drive, check and optionally disable browser extensions, such as Disconnect.

Open a document

You can open a document from Google Drive or the Dropbox by opening the Synchronize sub-menu and by clicking Open from…. Once opened, any modification in your document will be automatically synchronized with the file in your Google Drive / Dropbox account.

Save a document

You can save any document by opening the Synchronize sub-menu and by clicking Save on…. Even if your document is already synchronized with Google Drive or Dropbox, you can export it to a another location. StackEdit can synchronize one document with multiple locations and accounts.

Synchronize a document

Once your document is linked to a Google Drive or a Dropbox file, StackEdit will periodically (every 3 minutes) synchronize it by downloading/uploading any modification. A merge will be performed if necessary and conflicts will be detected.

If you just have modified your document and you want to force the synchronization, click the button in the navigation bar.

Note: The button is disabled when you have no document to synchronize.

Manage document synchronization

Since one document can be synchronized with multiple locations, you can list and manage synchronized locations by clicking Manage synchronization in the Synchronize sub-menu. This will let you remove synchronization locations that are associated to your document.

Note: If you delete the file from Google Drive or from Dropbox, the document will no longer be synchronized with that location.


Publication

Once you are happy with your document, you can publish it on different websites directly from StackEdit. As for now, StackEdit can publish on Blogger, Dropbox, Gist, GitHub, Google Drive, Tumblr, WordPress and on any SSH server.

Publish a document

You can publish your document by opening the Publish sub-menu and by choosing a website. In the dialog box, you can choose the publication format:

  • Markdown, to publish the Markdown text on a website that can interpret it (GitHub for instance),
  • HTML, to publish the document converted into HTML (on a blog for example),
  • Template, to have a full control of the output.

Note: The default template is a simple webpage wrapping your document in HTML format. You can customize it in the Advanced tab of the Settings dialog.

Update a publication

After publishing, StackEdit will keep your document linked to that publication which makes it easy for you to update it. Once you have modified your document and you want to update your publication, click on the button in the navigation bar.

Note: The button is disabled when your document has not been published yet.

Manage document publication

Since one document can be published on multiple locations, you can list and manage publish locations by clicking Manage publication in the menu panel. This will let you remove publication locations that are associated to your document.

Note: If the file has been removed from the website or the blog, the document will no longer be published on that location.


Markdown Extra

StackEdit supports Markdown Extra, which extends Markdown syntax with some nice features.

Tip: You can disable any Markdown Extra feature in the Extensions tab of the Settings dialog.

Note: You can find more information about Markdown syntax here and Markdown Extra extension here.

Tables

Markdown Extra has a special syntax for tables:

Item Value
Computer $1600
Phone $12
Pipe $1

You can specify column alignment with one or two colons:

Item Value Qty
Computer $1600 5
Phone $12 12
Pipe $1 234

Definition Lists

Markdown Extra has a special syntax for definition lists too:

Term 1
Term 2
Definition A
Definition B
Term 3

Definition C

Definition D

part of definition D

Fenced code

GitHub’s fenced code blocks are also supported with Highlight.js syntax highlighting:

// Foo
var bar = 0;

Tip: To use Prettify instead of Highlight.js, just configure the Markdown Extra extension in the Settings dialog.

Note: You can find more information:

  • about Prettify syntax highlighting here,
  • about Highlight.js syntax highlighting here.

Footnotes

You can create footnotes like this1.

SmartyPants

SmartyPants converts ASCII punctuation characters into “smart” typographic punctuation HTML entities. For example:

ASCII HTML
Single backticks 'Isn't this fun?' ‘Isn’t this fun?’
Quotes "Isn't this fun?" “Isn’t this fun?”
Dashes -- is en-dash, --- is em-dash – is en-dash, — is em-dash

Table of contents

You can insert a table of contents using the marker [TOC]:

MathJax

You can render LaTeX mathematical expressions using MathJax, as on math.stackexchange.com:

The Gamma function satisfying Γ(n)=(n1)!nN is via the Euler integral

Γ(z)=0tz1etdt.

Tip: To make sure mathematical expressions are rendered properly on your website, include MathJax into your template:

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

Note: You can find more information about LaTeX mathematical expressions here.

UML diagrams

You can also render sequence diagrams like this:

Created with Raphaël 2.1.0AliceAliceBobBobHello Bob, how are you?Bob thinksI am good thanks!

And flow charts like this:

Created with Raphaël 2.1.0StartMy OperationYes or No?Endyesno

Note: You can find more information:

  • about Sequence diagrams syntax here,
  • about Flow charts syntax here.

Support StackEdit


  1. Here is the text of the footnote.

Thursday, October 30, 2014

thread safe generator.

Generators are not thread safe, this example triggers the error:


You can fix it with a lock, which is considered cheaper than using a queue.

Wednesday, October 29, 2014

Decoration, Pickle, Closure.

What is closure? What it has to do with pickle-able ? 

A closure occurs when a function has access to a local variable from an enclosing scope that has finished its execution.
Here is an example, test2 doesn't work because pickle works with name. test3 doesn't work because it conflicts with top-level function 'foo'



Pickle, Decorator. 

The decorated function has the same name as the original function, makes it un-pickle-able.

the right way to write a decorator function is to always use 'wraps'. Be able to pickled is crucial when you programming multiprocess.


Sunday, October 26, 2014

Solution of over sensitive touch pad, Linux

Install ubuntu on VAIO ultrabook. The large touchpad is too sensitive that it often register my palm.

The palm detection can be fine-tuned, but here is a solution if you don't need that large a touchpad, and you want to 'tap-to-click'

open a terminal, use the 'synclient' command to find the current setting of your touchpad. The LeftEdge, RightEdge, TopEdge, and BottomEdge tells you roughly the dimension of your touchpad.

then you can use 'synclient AreaRightEdge=5000' to reduce the dimension of your touch pad. You may want to finetune it yourself. If the number is too small, that might deactivate your touchpad, don't worry, just set it to a larger number.



Tuesday, July 8, 2014

Uninstall YouCompleteMe vim without root.

I have been experimenting with auto-completion for vim, YCM is very popular but somewhat unfriendly for someone don't have root privilege.

Its git site doesn't say how to uninstall it. Here is an easy way to do so:

  1. "rm -rf .vim/bundle/YouCompleteMe/" 
  2. go into vi and do "PluginInstall" to install YCM again.
  3. repeat 1, this time you remove the uncompiled YCM. 

basically, you replace the compiled YCM with uncompiled one and remove the uncompiled one.


so what I am using now ? jedi-vim much easy to install and satisfies all my needs. (personal opinion)

Going to explore supertab.



Monday, July 7, 2014

svn1.8.9 with HTTP support.

In new SVN 1.8.9, when you
"svn co http://..."
This will give you an error: 
"svn: .... Unrecognized URL scheme for...."

What is missing? 
try: 
"svn --version" 

you will find "ra_dav" is not there. Older version of SVN need "neon" to support HTTP. But this version needs "serf" .

Install serf

unfortunately you need to first install scons

wget http://prdownloads.sourceforge.net/scons/scons-2.3.2.tar.gz
tar vxf scons-2.3.2.tar.gz
cd scons-2.3.2/
python setup.py install

now you need to the scons you just installed. Mine is in: $HOME/env/bin/scons

wget http://serf.googlecode.com/svn/src_releases/serf-1.3.6.tar.bz2
tar vxf serf-1.3.6.tar.bz2 
cd  serf-1.3.6
 ~/env/bin/scons PREFIX=$HOME/.local
 ~/env/bin/scons install

 install svn.

 just cd into the untarred folder: 
./configure --prefix=$HOME/.local
make 
make install 


Monday, June 23, 2014

Build python virtual environment.

You don't need root previledge at all. This tutorial will help you understand how to install software on linux without root.

What is virtualen: 

This article is very helpful.

Install virtualenv +pip : 

follow this stackoverflow post, answer by Walker-Hale IV.
after you install the virtualenv, your prompt should look like:
and you "which python" should be the one in your virtualenv, because it made a copy of it.

NOTE, don't move the folder of the virtualenv ( py-en0 ) around, some setting are using ABSOLUTE path.


Install openblas: 

NUMPY and SCIPY are optimized using blas, lapack package, you can install openblas to get everything, and openblas has many other favorable features. 

I need to install a local library of openblas, so first thing is to make a .local directory:
"
cd
mkdir .local
"
then in any folder, download openblas from github ( to do this you need to have git)
"
git clone git://github.com/xianyi/OpenBLAS
"
then cd into openblas folder: 
make FC=gfortran
sudo make PREFIX=$HOME/.local install 
after this your openblas library is install in $HOME/.local/lib

install numpy: 

From this point on, I follow this post:

for the site.cfg: 
[default] 
library_dirs=$HOME/.local/openblas-base

[atlas]
atlas_libs=openblas
"
and you can aslo install scipy following it. 

To test, you can do: 
"
python -c "import numpy.core._dotblas"
"
if the import is successful, your numpy is using the right openblas .