jeudi 15 mai 2014

[JS] Worker en Javascript

Juste pour mémo, rédigé vite fait le soir. Cet article sera normalement réécrit plus tard, et en anglais.

Un script JS s'execute en mono-thread.

Du coup, gros problème quand il s'agit d'executer un "batch" js en tache de fond sur sa page HTML.

Avec HTML5 apparait une nouvelle notion : "Worker". Grace à ca, il est possible de travailler dans une thread isolée de la thread principale gérant l'IHM. Du coup, on n'est plus bloqué par les events JS de l'IHM et on peut lancer des taches en background.

Possibilté d'utiliser setTimeout() et setInterval()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers

Un article sur htmlrocks (très bon point de départ):
http://www.html5rocks.com/en/tutorials/workers/basics/

Doc Worker sur MDN :
https://developer.mozilla.org/en-US/docs/Web/Guide/Performance/Using_web_workers

Doc sur l'open working group:
http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html

Un post sur stackoverflow d'un gars qui se demande comment checker un server avec du JSON toutes les 5 mins en JS:
http://stackoverflow.com/questions/11291637/daemon-thread-in-javascript

Et ensuite tout un tas d'articles en francais (par exemple) en tapant simplement "html5 worker" sous google.

jeudi 8 mai 2014

WeasyPrint : Type str doesn't support the buffer API

Under Windows, if you type weasyprint http://www.google.com test.pdf and get this message : 
 File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 293, in _select_source 
    base_url = path2url(filename) 
  File "C:\Python34\lib\site-packages\weasyprint\urls.py", line 87, in path2url 
    path = pathname2url(path) 
  File "C:\Python34\lib\nturl2path.py", line 46, in pathname2url 
    if not ':' in p: 
TypeError: Type str doesn't support the buffer API

You must edit C:\PythonXX\Lib\site-packages\weasyprint\urls.py and comment these lines :
    if isinstance(path, unicode): 
        path = path.encode(FILESYSTEM_ENCODING)

[Python] pip install : expecting string instruction after `rep'

If you are on Windows and get this message :
Error: expecting string instruction after `rep' 
when you type pip install greenlet (or another lib)

Then you must :
- verify under the MinGW Installation Manager that you have only these two packages installed : mingw32-base et mingw32-gcc-g++
- type under cmd : mingw-get upgrade binutils
- open an new cmd and type again your pip install greenlet (or another lib)

Have fun
:o)

[Python] pip install : unable to find vcvarsall.bat

If you are on Windows and get this message :
Unable to find vcvarsall.bat
when you type pip install greenlet (or another lib)

Then you must :
- install MinGW (after the installation, run the MinGW Installation Manager and install only these two packages : mingw32-base et mingw32-gcc-g++)
- add the mingw's bin directory to your path
- edit or create C:\PythonXX\Lib\distutils\distutils.cfg and write :
[build] 
compiler=mingw32

- open an new cmd and type again your pip install greenlet (or another lib)

Have fun
:o)

Categories