Skip to main content

Jeremy Gollehon

Jeremy Gollehon's Public Library

  • Product  ManyDesigns Portofino   Description 

    Create a webapp from an existing database in 30 seconds!


    Portofino is a free and open source web framework that helps developers create outstanding enterprise applications by addressing three specific needs: productivity, features and architecture.


    Among its features: content management, CRUD, database connectivity, calendars, charts, security and easy customization using Groovy.


    A wizard allows the developer to create a web application by connecting to an existing.database quickly and easily

       Licence  Open source   Pricing info  Free   Publisher  ManyDesigns S.r.l.
  • Product  Vertabelo   Description 

    Vertabelo is a visual database design tool available through a web browser. It supports the physical data modeling. Vertabelo offers SQL generation, team work support, public link to model, model versioning, and import/export in XML format.

       Licence  Multiple   Pricing info  Free for small projects, academics, students, open-source projects and non-profit organizations. Paid plans start from $9/month   Publisher  e-point

  • So how does PostgreSQL handle updates? It simply inserts a new row for each row to be updated and marks the old row as out-of-date. The transactions that started before this updating transaction finishes will still see the old values. The same applies to a delete statement – the row being deleted is just marked as out-of-date. Actually, an update operation is a combination of delete and insert operations.


    This approach, however, also has a negative consequence. The space occupied by the old rows is not reused even after all reading and modifying transactions finish. Why? Because every insert operation would need to scan the whole table in order to find this kind of free space in the middle of the table. This would be highly ineffective.


    So, in short, that's why the PostgreSQL database uses much more space than it really needs.

  • In the same fashion, dictionaries can deliver keyword arguments with the **-operator:

    >>> def parrot(voltage, state='a stiff', action='voom'): ...     print "-- This parrot wouldn't", action, ...     print "if you put", voltage, "volts through it.", ...     print "E's", state, "!" ... >>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"} >>> parrot(**d) -- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !

  • Some practice:

    Python 3.4.0 (default, Apr 11 2014, 13:05:11)  >>> class Person(): ...     name = 'Victor' ...     def say(self, what): ...         print(, what) ...  >>> getattr(Person, 'name') 'Victor' >>> attr_name = 'name' >>> person = Person() >>> getattr(person, attr_name) 'Victor' >>> getattr(person, 'say')('Hello') Victor Hello >>> 

    • I've been playing with this problem and have ended up with a fairly robust solution:

      def get_one_or_create(session,                       model,                       create_method='',                       create_method_kwargs=None,                       **kwargs):     try:         return session.query(model).filter_by(**kwargs).one(), True     except NoResultFound:         kwargs.update(create_method_kwargs or {})         created = getattr(model, create_method, model)(**kwargs)         try:             session.add(created)             session.flush()             return created, False         except IntegrityError:             session.rollback()             return session.query(model).filter_by(**kwargs).one(), True

      I just wrote a fairly expansive blog post on all the details, but a few quite ideas of why I used this.

      1. It unpacks to a tuple that tells you if the object existed or not. This can often be useful in your workflow.

      3. The function gives the ability to work with @classmethod decorated creator functions (and attributes specific to them).

      5. The solution protects against Race Conditions when you have more than one process connected to the datastore.


      EDIT: I've changed session.commit() to session.flush() as explained in this blog post. Note that these decisions are specific to the datastore used (Postgres in this case).


      EDIT 2: I’ve updated using a {} as a default value in the function as this is typical Python gotcha. Thanks for the comment, Nigel! If your curious about this gotcha, check out this StackOverflow question and this blog post.

  • Unique Object


    Various patterns for instantiating an object that may or may not correspond to an existing row, kept unique on some field or set of fields.

  • the most succinct way to pull out a list of 1-element tuples into a list is:

    result = [r[0] for r in result]


    result = [r for r, in result]
      answered Nov 6 '12 at 22:23 

       <script type="text/javascript"> var elmSearchAll = $('#search-allblogs-container').hide(); var elmSearchThis = $('#search-thisblog-container');  // try to get the blog id, if we fail, then we aren't on a blog and just use the regular search approach  (15054 === -1) && $('#search-switch-container').hide();  $(document).ready(function() {  $('#ThisBlog').click(function () {  var self = $(this);  if (':checked')) {  elmSearchAll.hide();;  }  });    $('#AllBlogs').click(function () {  var self = $(this);  if (':checked')) {  elmSearchThis.hide();;  }  }); }); </script> <script type="text/javascript" src="" language="javascript"></script> <script type="text/javascript" src="" language="javascript"></script> 

Mar 28, 15

time python code execution speed

1 - 20 of 4386 Next › Last »
20 items/page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo