class A(object):
foo = 1
class B(A):
pass
b = B()
print( hasattr(b, 'foo') )
True
print( 'foo' in b.__dict__)
False
hasattr : checks on super class
__dict__ : does not include super class
mercredi 20 août 2014
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.
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 :
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)
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 :
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 :
- open an new cmd and type again your pip install greenlet (or another lib)
Have fun
:o)
Unable to find vcvarsall.batwhen 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)
mercredi 29 janvier 2014
lundi 27 janvier 2014
[Bottle + Tornado] From a Bottle application, sending parameters to the Tornado server
When you use Bottle + Tornado (or CherryPy,... etc...), you can give options to the Tornado server, by declaring them inside the Bottle run(...) method.
Here hello_bottle.py :
from bottle import route, run, template
import os
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
data_dir='/'
#we give ssl_options to the Tornado server :
run(host='localhost', port=8080,server='tornado',ssl_options={
"certfile": os.path.join(data_dir, "mydomain.crt"),
"keyfile": os.path.join(data_dir, "mydomain.key"),
})
Here hello_bottle.py :
from bottle import route, run, template
import os
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
data_dir='/'
#we give ssl_options to the Tornado server :
run(host='localhost', port=8080,server='tornado',ssl_options={
"certfile": os.path.join(data_dir, "mydomain.crt"),
"keyfile": os.path.join(data_dir, "mydomain.key"),
})
And when we execute :
python hello_bottle.py
Bottle v0.13-dev server starting up (using TornadoServer(ssl_options={'keyfile': '/mydomain.key', 'certfile': '/mydomain.crt'}))...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
Voila :o)
Source :
SSL with Tornado :
Sending parameters to CherryPy:
Servers allowed with Bottle :
lundi 6 janvier 2014
Comment se compliquer la vie en Java...
Mouaaaaa, je trouve ça marrant, les gens qui veulent montrer qu'ils connaissent les toutes dernières fonctionnalités de Java.
Voilà un exemple concret : suppression basique d'un répertoire temporaire (je dis bien : une simple "SUPPRESSION BASIQUE").
Ça c'est la version "je me la pète je maîtrise Java 7" :
Files.walkFileTree(tempDirectory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir,
IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw exc;
}
}
});
Euhhhh oui, c'est beau, il y a plein d'indentations et ça fait 15-20 lignes quand même...
Pourquoi ne pas implémenter une toute petite méthode récursive (le truc de base que l'on apprend en cours) ou tout simplement faire appel à Apache Commons (FileUtils.deleteDirectory(tempDirectory)) ?
Hormis le fait que je râle sur ce satané bout de code "tout moche" sur lequel je viens de tomber,
il y a derrière un vrai problème de fond : "faire la part des choses entre la maintenance/lisibilité et l'utilisation systématique/radicale/extrême des fonctionnalités évoluées de Java".
Voilà un exemple concret : suppression basique d'un répertoire temporaire (je dis bien : une simple "SUPPRESSION BASIQUE").
Ça c'est la version "je me la pète je maîtrise Java 7" :
Files.walkFileTree(tempDirectory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir,
IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw exc;
}
}
});
Euhhhh oui, c'est beau, il y a plein d'indentations et ça fait 15-20 lignes quand même...
Pourquoi ne pas implémenter une toute petite méthode récursive (le truc de base que l'on apprend en cours) ou tout simplement faire appel à Apache Commons (FileUtils.deleteDirectory(tempDirectory)) ?
Hormis le fait que je râle sur ce satané bout de code "tout moche" sur lequel je viens de tomber,
il y a derrière un vrai problème de fond : "faire la part des choses entre la maintenance/lisibilité et l'utilisation systématique/radicale/extrême des fonctionnalités évoluées de Java".
lundi 30 décembre 2013
addSubview in UIAlertView deprecated in iOS7
There is a solution....
UIAlertView *alertView;
//a simple alert view with a simple message:
alertView = [[UIAlertView alloc]initWithTitle:nil message:@"My message here..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
//a simple activity indicator:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame= CGRectMake(50, 10, 37, 37);
activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;
[activityIndicator startAnimating];
//the magic line below,
//we associate the activity indicator to the alert view: (addSubview is not used)
[alertView setValue:activityIndicator forKey:@"accessoryView"];
[alertView show];
vendredi 1 novembre 2013
Inscription à :
Articles (Atom)
Categories
- /etc/hosts (1)
- 443 (1)
- 80 (1)
- a2dp (1)
- addsubview (1)
- affix (1)
- amazon (1)
- android (6)
- angularjs (1)
- angularjs cross domain json post (1)
- angularjs ionic ng-click twice (1)
- animate (1)
- ansible (2)
- antlr (1)
- apache2 processes (1)
- app (1)
- app store (1)
- apple (1)
- appstore (1)
- avis (2)
- baignoire (1)
- basics (1)
- bitbucket (1)
- blackberry (1)
- bluetooth (1)
- booster (1)
- bootstrap (3)
- bottle (4)
- browsers (1)
- buffer (1)
- cherrypy (3)
- chromebook real life (1)
- coder (2)
- communicator (1)
- config.txt (1)
- creme chocolat (1)
- crepes bretonnes (1)
- crlf (1)
- css (2)
- cuisine (1)
- database (4)
- datatables (1)
- datetime (1)
- delete (1)
- disconnect (1)
- distributing (1)
- english (2)
- flask (1)
- fontawesome (1)
- francais (51)
- futuristic (1)
- game (1)
- gil (1)
- git (9)
- github (1)
- gratuit (2)
- hadopi (1)
- header (1)
- height zero (1)
- hibernate (1)
- hotel (2)
- http (1)
- https (2)
- ionic (2)
- ios (2)
- ios7 (1)
- iOS8 (1)
- iphone (1)
- jaune (1)
- java (7)
- javamelody (1)
- javascript (1)
- json (3)
- kindle (1)
- knockout (3)
- leaflet (1)
- legere (1)
- lf (1)
- life cycle (1)
- linkedin resume builder profile (1)
- linux (9)
- log (1)
- luxembourg (1)
- machine (1)
- maizena (1)
- minecraft (1)
- mobile (1)
- mongo (1)
- mongodb (3)
- mongodb mongo linux (1)
- multiple (1)
- myspace (1)
- mysql (1)
- netbeans cordova android cordova-plugin-file (1)
- nginx (2)
- nintendo (1)
- number (1)
- opensolaris (1)
- openstreetmap (1)
- oracle (15)
- order by (1)
- output (1)
- overclocking (1)
- packaging (1)
- parameters (1)
- personnaliser bootstrap (1)
- photos (1)
- pip (2)
- pipewire (1)
- prime (1)
- problem (2)
- project (1)
- publish (1)
- python (26)
- raspberry pi (2)
- raspi-config (1)
- recette (1)
- redirect (1)
- restful (2)
- schema (1)
- screen (1)
- screencast (1)
- script (1)
- scrollspy (1)
- serialization (1)
- sessions (2)
- shell (1)
- shutdown reboot linux reinstall apt-get (1)
- smartgwt (1)
- sncf (1)
- software (1)
- spring (1)
- sql (1)
- sticky footer (1)
- supervisor (1)
- systeme (1)
- tile (1)
- timestamp (1)
- title (1)
- tornado (3)
- turbo (1)
- ubuntu (2)
- uialertview (1)
- video capture (1)
- viewdidappear (1)
- viewdidload (1)
- viewwillappear (1)
- weasyprint (1)
- web (1)
- web2py (1)
- windows (5)
- worker (1)
- xbox wireless headset (1)
- xdk barcode scanner intel.xdk.device.barcode.scan (1)
- XDK rename project (1)
- xeno galaxies (1)