vendredi 24 octobre 2014

[Python] pip install : gcc: error: unrecognized command line option '-mno-cygwin'

If you are on Windows and get this message :
gcc: error: unrecognized command line option '-mno-cygwin'
when you type pip install greenlet (or another lib)

Then you must :
- edit or create C:\PythonXX\Lib\distutils\cygwinccompiler.py and remove any traces of -mno-cygwin

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

Have fun
:o)

mardi 14 octobre 2014

JSON Schema

The official documentation for the JSON Schema (the specification for the JSON Schema is currently published as draft) :
http://json-schema.org

An online JSON validator, using schema :
https://json-schema-validator.herokuapp.com/


A wonderful tutorial explaining the JSON Schema :
http://spacetelescope.github.io/understanding-json-schema/

mardi 23 septembre 2014

[Python] __code__ and decorator



http://stackoverflow.com/questions/1166118/how-to-strip-decorators-from-a-function-in-python

http://stackoverflow.com/a/1167248

[iOS] viewDidLoad viewDidAppear viewWillAppear

viewWillLoad/viewDidLoad - called when the view is constructed (via the first call to retrieve the view controller's UIView via it's view property - aka lazy loading)
viewWillAppear: - when the view is being prepared to appear either immediately (animated == NO) or view a transition (animated == YES)
viewDidAppear: - if the view appearance wasn't cancelled and the view controller's view fully appears
viewWillDisappear: - complements viewWillAppear:
viewDidDisappear: - complements viewDidAppear:

viewWillUnload/viewDidUnload - deprecated APIs when the view is unload due to memory constraints (don't worry about these anymore)

Source : http://stackoverflow.com/questions/22214843/ios-7-difference-between-viewdidload-and-viewdidappear

dimanche 21 septembre 2014

[iOS 8] Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead

If you have this message :
<<
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
>>


then just write :
<<
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
>>

vendredi 22 août 2014

[Bootstrap] Sticky left sidebar

Apply affix (http://getbootstrap.com/javascript/#affix) and scrollspy (http://getbootstrap.com/javascript/#scrollspy)


body {
   position: relative;
}

<body data-spy="scroll" data-target=".mynav">
   <div class="row">

      <div class="col-md-3 mynav">
         <ul class="nav nav-pills nav-stacked" data-spy="affix" data-offset-top="60" data-offset-bottom="200">
            <li>
               <a href="#menu1">menu1</a>
            </li>
            <li>
               <a href="#menu2">menu2</a>
            </li>
         </ul>
      </div> <!--div col-md-3-->

      <div class="col-md-9">
         <div id="menu1">
            blabla
         </div>
         <div id="menu2">
            blabla
         </div>
      </div> <!--div col-md-9-->

   </div> <!--div row-->
</html>

jeudi 21 août 2014

[Bootstrap] Sticky footer

http://stackoverflow.com/a/25075517


 $(document).ready(function () {
//http://stackoverflow.com/a/25075517
            var $docH = $(document).height();
            // The document height will grow as the content on the page grows.
            $('.my-footer').css({
                /*
                The default height of .navbar is 50px with a 1px border,
                change this 52 if you change the height of your footer.
                */
                top: ($docH - 52) + 'px'
            });
        });



 <div id="footer" class="my-footer">
      <div class="container">
        <p class="text-muted credit">toto.com</p>
      </div>
    </div>

[Bootstrap] How to create a sticky left sidebar menu

http://www.bootply.com/82265#
http://www.bootply.com/90936#

mercredi 20 août 2014

[Python] How to check if an object has an attribute : hasattr vs __dict__

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

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)

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"),
})

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".

Categories