samedi 5 novembre 2011

A Year In New York


Libellés : ,

lundi 31 octobre 2011

How to disable Resume in Preview

A new feature of Mac OS X Lion is to resume any previously opened document when you launch an application.

For example, open a picture in Preview, quit Preview, open another picture and Preview will try to load the 1st picture you opened before.

This is especially annoying when the previous picture is not available anymore and launching Preview is taking seconds...

Here's how to disable the Resume feature in Lion's Preview:

Paste the following command in your Terminal application (in one line):
defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

Libellés : , ,

lundi 24 octobre 2011

Python import from import usage

Here's a quick note to understand how works the Python module importing engine.

Suppose you have a package with the following hierarchy:
package/subpackage/module.py

Each package and subpackage has an empty __init__.py file to define it as a package, and the module.py has a small function defined:
def function():
    print "Works!"

If you are running a script at the same level as the main package, here's what you can do:
import package.subpackage.module
package.subpackage.module.function()
from package.subpackage import module
module.function()
from package.subpackage.module import function
function()

And what you cannot do:
import package.subpackage
package.subpackage.module.function()
import package.subpackage.module.function
package.subpackage.module.function()

I hope it helps!

Libellés : , ,

dimanche 22 mai 2011

Fourchette et sac à dos à New York

L'intégrale de l'émission culinaire Fourchette et sac à dos a New York en 3 parties de 25 minutes

Libellés : , ,

dimanche 24 avril 2011

Adding swap to an EC2 micro instance on Amazon

Amazon EC2 provides cheap micro instances with a small amount of memory and no swap.
If you need swap on your instance you must add it manually.

See for yourself, no swap:
$ free
total used free shared buffers cached
Mem: 611212 119544 491668 0 42460 36636
-/+ buffers/cache: 40448 570764
Swap: 0 0 0

Here's how to add a 1GB swap to your running micro instance:
$ sudo dd if=/dev/zero of=/var/swapfile bs=1M count=1024
$ sudo mkswap /var/swapfile
$ sudo swapon /var/swapfile

And now you can check that you have 1GB of swap:

$ free
total used free shared buffers cached
Mem: 611212 604092 7120 0 36692 514256
-/+ buffers/cache: 53144 558068
Swap: 1048572 0 1048572

The swap file won't be used on next reboot, but it's there as long as the instance is running. If you want to permanently add the swap file to your micro instance, add this line at the end of the /etc/fstab file:
/var/swapfile none swap sw 0 0
Now you have a micro EC2 instance with a 1GB permanent swap file on your root EBS filesystem.

Libellés : , , ,