When you do a fresh install of Ubuntu 12.04 (Or any version with Unity for that matter), you install Skype and expect it to work as it used to.
But if you close the main window - you soon notice that Skype icon is not being displayed in top panel.
To fix this you will need to run a few commands.
So open up your terminal and run this:
gsettings get com.canonical.Unity.Panel systray-whitelist
You should get something like this:
['JavaEmbeddedFrame', 'Wine', 'Update-notifier']
Basically this means, that Skype is not whitelisted, thus is not allowed by default to display its tray icon. We need to fix this. Append 'Skype' to the list so that you have something like this:
Then wrap it with double quotes (”) and add gsettings set com.canonical.Unity.Panel systray-whitelist in front of it. At this point you should have something like this:
gsettings set com.canonical.Unity.Panel systray-whitelist "['JavaEmbeddedFrame', 'Wine', 'Update-notifier', 'Skype']"
Now just copy this to your Terminal and execute the command. Reboot afterwards. Now you should see the icon.
Design pattern is a general solution to particular problem that is occurring commonly.
However this is not an already implemented source code (you’ll have to do that yourself).
It is not an already finished design either. You can incorporate design patterns into your application design.
It formalizes best practices and describes interactions between objects and classes.
Basically it is a template for how to solve a problem.
If you want to get a better description of what a design pattern is, you can read about it on Wikipedia
Observer pattern
It is a one-to-many push type design pattern, in which an object (“Subject”) maintains a list of dependants (“observers”).
Once the subject changes state, it automatically notifies each observer with its new state.
You can think of it as a mailing list. Mailing list is the subject, you attach to it by sending in your e-mail address. But there can be many subscribers - Observer pattern does not limit the number of observers.
When there is a new email, the state has changed and the server emails it to each of the subscribers, including you!
Example
Let’s build our own simple application that uses the Observer pattern.
In this example we’re going to use PHP.
There will be at least 2 classes - one for the Subject, one for the Observer.
The Subject will have to have at least these three methods:
Attach - a method that the observers will use to register
Detach - observers may want to unregister
Notify - This will change subject’s state
As for the Observer, we can get away with this single method:
Notify - Notification method, which will be called by the subject
Ok, let’s start coding! Let’s start by creating a Subject class:
<?phpclassSubject{private$observers=array();// We will store observers herepublicfunctionattach($observer){if(!in_array($observer,$this->observers)){// Make sure we don't add an observer twice$this->observers[]=$observer;// Add the observerreturntrue;}else{returnfalse;// Observer was not added}}publicfunctiondetach($observer){if(!in_array($observer,$this->observers)){// Make sure the observer is registeredreturnfalse;}else{$key=array_search($observer,$this->observers);// Find observer's keyunset($this->observers[$key]);// Remove the observer$this->observers=array_values($this->observers);// Reindex the observer array, as unset leaves a gapreturntrue;}}publicfunctionnotify($message){foreach($this->observersas$observer){// Notify each observer$observer->notify($message);// Dispatch the message to each observer}}};
Ok, we’ve implemented our Subject class. Observers will register through attach method and unregister through detach method. Notifications will be sent with notify method.
Now let’s build our Observer class:
Observer.php
12345678
<?phpclassObserver{publicfunctionnotify($message){echo"I have received a message: \r\n";var_dump($message);// Just print out any information it may contain: strings, numbers, objects...echo"END OF MESSAGE\r\n";}};
Our Observer class only needs notify method, which will output all received messages.
And lastly, let’s create our demo program that makes use of these classes:
main.php
12345678910111213
<?phprequire_once('Subject.php');require_once('Observer.php');$subject=newSubject();// Create a Subject// Let's try to change state. It should not output anything as it doesn't have any observers registered$subject->notify('This shall not be read!');// Let's create an Observer, register it and send another notification$observer=newObserver();// Create an Observer$subject->attach($observer);// Register Observer to the Subject$subject->notify('Can you see me?');// Send notification to the Observer
If we run this, we should see Can you see me? text. If you do - good work! Now you know the Observer pattern.
I’ve created a Github repository with complete code from this article.
Have you noticed that you spend quite a bit of time on time consuming sites, such as youtube, reddit, Hacker news, CNN.com and etc.?
I certainly did.
When it comes to productivity, such websites don’t help at all. But now that you think of it, maybe it’s worth to block them completely?
Blocking websites with hosts files
Linux has a host file at /etc/hosts, Windows have one as well (but it’s hidden somewhere in Windows folder).
You simply need to add entries in such manner:
127.0.0.1 example.com
127.0.0.1 is your internal localhost IP address and instead of example.com you enter your time consuming site.
Add as many entries as you need.
And when you’re done, you won’t be able to access these sites that easily (but you will still be able to do that by using certain methods).
And that’s it! This change is easily to apply and easy to revert. It blocks access to your most time consuming websites and reminds you your decision not to visit them.
Upon installing the new Ubuntu 12.04 release I noticed terrible inconsistencies in window management.
E.g. to snap window to left half (or right half for that matter) the default hotkey is Ctrl+Alt+Left,
however snapping window to the upper half is Ctrl+Alt+Kp8 (Keypad 8). Let’s fix that.
If you don’t have Compiz Settings Manager installed (it is not installed by default),
type this command into Terminal to install it:
Once installed, launch the Compiz Settings Manager.
Under “Window Management” click “Grid”, then select “Bindings” tab.
Now you can set up your own Window Management hotkeys by clicking on each already defined binding
and modifying it to your own desire.
If you have a keypad, I suggest you to use these key bindings:
Put Center: <Control><Alt>KP5
Put Left: <Control><Alt>KP4
Put Right: <Control><Alt>KP6
Put Top: <Control><Alt>KP8
Put Bottom: <Control><Alt>KP2
Put Top Left: <Control><Alt>KP7
Put Top Right: <Control><Alt>KP9
Put Bottom Left: <Control><Alt>KP1
Put Bottom Right: <Control><Alt>KP3
Maximize: <Control><Alt>KP0
If I remember this correctly, these key bindings were default on Ubuntu 11.10