Aug 2010

Tue, 24 Aug 2010

Pretty list of database and table sizes with PostgreSQL

A very handy way to estimate the on-disk size of your databases in PostgreSQL:

> SELECT datname,pg_size_pretty(pg_database_size(datname)) FROM pg_database;
    datname    | pg_size_pretty
---------------+----------------
 template1     | 4144 kB
 template0     | 4144 kB

And the same for individual tables:

> SELECT tablename,pg_size_pretty(pg_total_relation_size(tablename))
    FROM pg_tables WHERE schemaname NOT IN ('information_schema','pg_catalog');

         tablename          | pg_size_pretty
----------------------------+----------------
 django_content_type        | 40 kB
 django_session             | 152 kB
 django_site                | 24 kB

Now go and bug your application developers to save your resources.

posted at 10:20 | path: /unix | permanent link to this entry

Fri, 20 Aug 2010

Javascript based Picasa photo roll on your webpage

From the department of 5-minute Javascript hacks comes this little gem, which handles the 'Random photo' to the right. It uses the JSON-API Google API to get the data from the Picasa-Web-Albums.

<script><!-- //http://code.google.com/apis/gdata/docs/json.html
// Creative Commons Attribution-ShareAlike 3.0 Unported License
// http://creativecommons.org/licenses/by-sa/3.0/
// (c) Jan Dittmer <jdi@l4x.org> 2010
var es = [];
function r() {
       var idx = Math.floor(Math.random()*es.length);
       var m = es[idx]['media\$group'];
       var i = document.getElementById("i");
       document.getElementById("t").innerHTML = m['media\$description']['\$t'];
       i.src = m['media\$thumbnail'][0]['url'];
       setTimeout("r();",10*1000);
}
function j(p) {
       es = p['feed']['entry'];
       r();
}
function picasa() {
       var url='http://picasaweb.google.com/data/feed/base/user/jan.dittmer' +
               '?kind=photo&thumbsize=160c&access=public&alt=json&callback=j';
       var s = document.createElement('script');
       s.src = url; document.body.appendChild(s);
}
window.onload = picasa;
//--></script>
<a href="http://picasaweb.google.com/jan.dittmer"> <img id="i"> </a>
<div id="t"></div>

posted at 20:56 | path: /web | permanent link to this entry

How to use glutBitmapCharacter in Perl

glutBitmapCharacter is an OpenGL function used to display a single character. The C function signature looks like this:

void glutBitmapCharacter(void *font, int character);
Seeing this, it should be clear that you have to call it from perl with a numeric character value:
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ord('J'));
The trick is to use ord to convert the character to the character code. Don't try without or you'll just the the background color and no error message, I just lost nearly an hour over this simple thing, which is not so obvious if you just look at C examples. But 'J' are two very different things in Perl and C.

posted at 11:35 | path: /gl | permanent link to this entry

Sun, 01 Aug 2010

RF MEMS Literature

posted at 12:00 | path: /personal | permanent link to this entry

Personal bibliography

posted at 12:00 | path: /personal | permanent link to this entry

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.