This blog contains anything related to programming that I find in mailing lists, on the web or in other feeds. It is heavily biased by my opinions (what I like) and thoughts (what I would like to have) and in between there are things by myself (what I do)
Quote from the pharo team blog
We are excited to announce our second release of Pharo!
This release contains many bug fixes, improvements, performance optimizations, and new features that didn’t get into version 1.0.
Specific information about what is new in this release can be found on http://www.pharo-project.org/pharo-download/release-1-1.
After putting a lot of effort into it the pharo team released today to 1.0 version of pharo. This is the first public release.
Please check out http://www.pharo-project.org/
Last year I started really motivated with this pier surgery series. Shame on me that I did only this first article. I almost feel like an open source project on sourceforge.
If I lost interest in pier? No, not at all. Quite the opposite happened. Pier is a really generic and complex piece of software. It’s not too easy to understand the internal because it is very generic and sometimes it just appears utterly complex. But it has great potential. At the moment I’m trying more and more to use it as basis for web application development.
There are web applications and there are CMSes. The web applications are programmed to solve some data management issues. A CMS is made to ease the building of a web site structure, uploading images etc. Usually they are quite distinct. Pier offers some things to lower the barrier between the HTML-only and the code-only worlds.
As an illustration I want to do a little component that shows some of the integrative stuff. If you use pier you know already that you can easily embed components into your site. If you write an embedded link (surrounded by +) than you will be asked what you want to embed. One of the choices is component. But what do you need to do in order to have your own component to show in the pull-down?
You need to make your own component a subclass of WAComponent. That would make it a seaside component. To ease some of the steps necessary to deal with pier it is a good choice to make your component a subclass auf PRWidget.
Here we go.
PRWidget subclass: #MyPierWidget
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Pier-Example'
Pier has a notation of abstract and concrete classes. Only concrete ones will be integrated into the component choice. To make it visible we need to add on the class side of our class
isAbstract
^ false
The class is now available in the component pull-down under the category Pier Widgets. The name will be My Pier Widget. Pier derives that name from the class name. You can give the component your own name by implemententig a method on the class side
label
^ 'my first pier widget'
It is now called my first pier widget. But it is still in the category Pier Widgets. It is a good idea to have your own category where you easily find your own components. You can change that by implementing a method on the class side
groupLabel
^ 'My Pier Widgets'
It will now be display in its own category My Pier Widgets
The only thing that is left to do to make it a fully working widget is to implement the seaside rendering method on the instance side
renderContentOn: html
html text: 'this is my first pier widget'
Let’s embed this into our test site. Log into pier and create a page in the top called example1. In the page write the text
this is the example1 page with embedded component
+component+
In the following dialogs chose component and then select your component from the pull-down.
By now we have created a component and embedded it into the web site. With this we can achieve already a lot of things. Just manage the web site with pier and embed your little widgets wherever you need some special functionality.
This covers the things that pier can do with components. But there are also ways how components can do things with pier. The PRWidget has a method context that gives us access to the structure our component is embedded into. I won’t go into detail how this works. This is left as an exercise for you.
Having the access to the pier we can even lookup a strcuture somewhere in the CMS. We can do this by utilizing
PRPathLookup start: self context structure path: '/some/path'
PRPathLookup does a lookup of a structure starting at self context structure (where we are at the moment) to another structure that is denoted by the path string.
Pier extends the anchor tag to utilize this. By writing
html anchor
goto: (self context structure: (PRPathLookup start: self context structure path: '/example2'));
with: 'advance to next page'
we can navigate from inside our component to a different page inside the pier CMS. Just create a page example2 in the root of your CMS and write "this is the target page example2" as text into it. Change the renderContentOn: method to
renderContentOn: html
html anchor
goto: (self context structure: (PRPathLookup
start: self context structure
path: '/example2'));
with: 'advance to next page'
If you now go to your /example1 page you will see the link advance to next page. By clicking it you make pier changing the page to the /example2 page.
We have created a component that is embedded inside a page in the CMS and the component can instruct the CMS from inside to navigate to somewhere else. The link you navigate is not just an external link where "you know" the target and just link to it. No, you have the target in your hand and pier is creating an appropriate link for it. Change you renderContentOn: to
renderContentOn: html
| target |
target := PRPathLookup start: self context structure path: '/example2'.
html anchor
goto: (self context structure: target);
with: target title
The anchor will now show whatever title the page we link to has. You can change the title of /example2 afterwards and the link on /example1 will reflect that. The same way we read the title from the target of the link we could access the target in any thinkable manner. In one of the next articles we’ll explore this.
I hope I could illustrate how pier and programmed components can interact to lower the barrier between components and CMS.
In the last articleyou could read how to do backups using time machine. This article adds encryption to the mix. Backing up and encrypting content are both option offered by Apple. Trying to combine them can be quite unsatisfying. But as always you can make it work the way you want it with just a handful of tweaks.
FileVault
Apple offers you any easy way to encrypt your home directory. It is called FileVault and you can find it in System preferences -> security. If you enable it Mac OS will create an encrypted volume for you and moves your files into it. You will find your home directory replaced by the encrypted volume.
I don’ know exactly what I will find because I never tried to use it. Asking friends or searching the internet unveiled that using FileVault is probably not the best idea. There are a lot of problem descriptions by people that have used it. A lot of the complaints seem to date back to a time when FileVault was still new but you can find still a lot of people that are not satisfied with it.
When it comes to encryption some things become really worse. By flipping a single bit inside an encrypted volume can loose easily 200GB of data. So it works reliable or you are in danger.
And you are even more in need of a backup, right? Unfortunately there are also a lot of complaints about using FileVault in combination with time machine. It seems there are some nuts & bolts that do not work that well. This is all just speculation (I read everything I know in the internet and didn’t try a single bit on my own) but for me it is enough to decide not use FileVault.
disk images
FileVault uses an encrypted disk image to store its data. Disk images are not part of FileVault they are part of Mac OS. So you can just create your own disk image. You can create them encrypted or unencrypted, as image, as sparse image and sparse bundle image. Just have look herehow to create them.
For our purpose it is pretty clear that we want an encrypted disk image. But what type? That is a question of style and what you are heading for. The word "sparse" means that you can create a 50GB disk image that will only use a few megabytes after creation. The image grows when you put data into it. A "sparse image" will be only one big file in the filesystem carrying all the volume data. A "Sparse bundle image" will be organized in whole directory hierarchy consisting of 8MB sized data files.
backuping up the disk image
Some people seem to solve to Encryption-TimeMachine problem in a way that they use a sparse bundle image inside their home directory for the encrypted volume. The rationale behind is that in a bundle image only a few stripes are updated if you write something to your encrypted volume. TimeMachine will pick up only the changed stripes and backups them.
backing up the content of the disk image
The previous approach is very pragmatic and will work most of the time. For sure TimeMachine will give you the right combination of stripes if you go back in time. I just cannot put enough trust into this approach. I suspect there is a good chance to flip that single bit.
I like to have my data encrypted on my Mac but unencrypted when backuped up. Or better if I think I need the backup encrypted then I like to encrypt it again at the location of the backup. This appears more reliable to me.
moving the disk image out of home
While we are not backing up the disk image itself, we don’t want TimeMachine to deal with the whole image. So we are just moving the encrypted sparse bundle image to another place on the disk.
adding the encrypted volume to TimeMachine
When you are using a disk image it is treated like another external drive that has been mounted on your system. Finder will display it side by side with your real harddisk and it will be accessible in the /Volumes/ folder. Unfortunately TimeMachine is ignoring everything in the /Volumes/ folder. With moving the disk images out of the home folder we just made everything being excluded from the backup. TimeMachine itself lets you only specify excludes from the backup not includes.
The configuration of time machine in /Library/Preferences/com.apple.TimeMachine.plistdoes not only contain the excludes you entered via the configuration dialog. It does contain the Volumes to be included, too. The section is called IncludeVolumeUUIDs(TextWrangler is a good tool to edit plist files btw.). In this postyou can read how to get the Volume UUID and the the Volume key. After adding those two keys to the plis time machine includes your encrypted volume into the backup.
Now you are backing up the files within your encrypted volume. You can browse the files in time machine just like any other file and you are able to restore individual files from the encrypted volume as well. I have this running for two month now and it works out well. After reboot I need to double-click the disk image to mount it. Sometimes I forgot to mount it immedialtely and time machine did a backup. As far as I can tell this isn’t a problem. TimeMachine just seems to ignore the volume "for this time". There is no additional data backup through the presence/absence of the encrypted volume.
I use a laptop for my professional work. That means I have stuff on the laptop that I don’t want to lose neither by disk crash nor by theft. So the most basic thing you have to do (and too many people do ignore) is a backup. This at least ensures you that you don’t lose your stuff. Working for other companies you also don’t want others to get the stuff you didn’t lose. Working like this puts encryption next to the backup. It is really essential to protect your customers property while working for them.
Backup and encryption used alone are easy to achieve on a Mac. But if you want the combination of both than you are lost.
This is the first of two blog entries focussing on the backup side. In the next article you can read how you can do encryption on your Mac and how backup and encryption can be combined.
backup
Using time machine for backups is great. The default behaviour of time machine is doing backups every hour as long as your power supply is plugged in (at least this is my case). All of the backups are incremental managed. The behaviour of keeping old backups is a logarithmic one. You have hourly backups for the last day, daily backups for the last week, weekly backups for the last month and monthly backups for the last year. I’m not sure if it is always the last period or the last two but you got the glimpse, right?
Time machine is also an application to access your backups. You select an application window like the Finder and entering time machine shows you a couple of finder windows stacked one after the other. The finder windows display the states of the filesystem at the particular time. You can go into the past and back again. Using the mouse you can select any files you like to restore and voila....easy.
It is really easy to use and therefor the best backup software I’ve ever seen. But it has also drawbacks.
disk space
Time machine is eating up disk space really fast. So you need to have big wallet to upgrade disk drives everytime free space is becoming rare. Or you can be a little careful. Just one example. Let’s assume you copied your 80GB mp3 collection into your home folder into a folder copyFromOldDisk. Than you leave your Mac alone. While it is so magically done in the background you didn’t notice that time machine backuped your folder. Than you move the folder to MyMusic. And magically time machine stores this folder happily, too. A little bit later you decide to put your music folder on your new NAS so the whole family can use it. After copying you remove the MyMusic folder from your drive. The next time you check disk space for the time machine you might wonder that the space time machine occupied is huge.
In such a situation you can clean your backup a bit. Just enter the time machine scroll to the time the MyMusic folder existed. If you do it right the folder will appear in the Finder window. Select it and press right mouse button. There is an option to remove this folder from all backups. Time machine will go though all of the backup states and erase it. Erasing the second folder gives you back your 160GB disk space.
You did that and checked the disk space again and nothing happened? Well, it’s not like that. You need to know that there is a slightly difference between the space time machine uses and the space that is used on your disk. Time machine stores its data in disk image. It is like a virtual hard disk made up of files. This disk image can only grow automatically. If time machine needs more space it grows the image. If you delete the mentioned two folders than there are 160GB free space inside the image but the size of the image on your hard disk stays the same.
shrinking
Bad? No! I just said it can’t shrink _automatically_. But you can shrink it manually. Make sure your disk image isn’t used right now (used over network or locally). Then open a terminal and type
hdiutil compact /path/to/your/time/machine/image
This will shrink the image and frees your disk space.
exclusions
Apple defined for you what you like to back up. A standard set has been defined. You can add things to exclude via the time machine configuration dialog but not in a sophisticated manner. If you want to include something you are lost again.
Exclusions defined by Apple are configured in a file
/System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist
Using an editor that is capable of editing plist file (I use TextWrangler for that) you can alter the set time machine includes/excludes. This hint I’ve found here