Wednesday, 28 May 2014

Disable automatic printer adding in Ubuntu

In Ubuntu there is a service which scans the network for printers and adds them automatically. If your computer is in a large network and you really do not use most of the network printers, but just a few of them, then this feature really becomes annoying. To disable this feature, the easiest way is to prevent the service from running automatically.
So first stop the service:
Then edit/add the new configuration file for the service:

Then put 'manual' in the new config file (the config file should have only a single line with single word: 'manual' - of course without quotes) and start the service again:

Saturday, 10 May 2014

How to mount a remote file system through an intermediate machine?

Suppose that you've a remote machine from which you want to mount a file system on your local machine. However, your local machine can not connect directly to the remote machine. If you could connect directly, then you could have used sshfs to mount the file system without any problem.
In the current situation all you need to do is to create a tunnel to a third machine which will act as the middle-man. The tunnel is created with ssh command, as shown below. Before that, for further clarification on this scenario, the machines which are involved are: localpoint (which is your current local machine), endpoint (which is you machine of interest that you want to mount a file system from it) and middlepoint (which is the machine in between that have access to both machines).
First you need to create the tunnel:

ssh -f username@middlepoint -L 111:endpoint:22 -N

which basically tells to forward the local port 111 to port 22 of endpoint machine. You can use any port on your local machine as far as it is available for use.
Then mounting is performed through the tunnel:

sshfs -p 111 username@ /local_path

That's it! You've now mounted endpoint:/remote_path on your local machine localpoint:/local_path via middlepoint.

Mac users may have some issues when actually trying to access the mounted file system, most probably 'Permission Denied' problems. That could happen when Mac tries to infer the permission. To resolve this issues, when mounting the fs, ensure to pass -defer_permissions as a parameter to sshfs. Also it would be beneficial to add noappledouble option as well to tell the Mac not to write the .DS_Store files on the remote file system. In short, the final call to sshfs would be something like:

sshfs -p 111 -defer_permissions,noappledouble username@ /local_path

Further note for Mac users: it is assumed that FUSE for OS X is being used.

Monday, 28 October 2013

How to add JAR library to the Android project in Android Studio?

Some times trivial things like adding a lib references becomes a big pain! Adding jar lib to an Android project in Android Studio on Mac was very problematic for me and of course, many other guys!
After checking different web sites and reading through a bunch of questions in stackoverflow, I managed to get it working.
The steps are:
Create a lib folder in your project folder (the inner one) and copy your jar file there.
Edit the build.gradle file (the inner one) and add: compile files ('lib/ks2.jar')
Close the project and open a terminal and go to the folder of your project. There you'll find a file named gradlew, change that to be executable (chmod +x gradlew), then execute it: ./gradlew clean
It would take a while to finish and you should see a 'BUILD SUCCESSFUL' message upon completion. Once done, open the project, and you're done!

Thursday, 10 October 2013

LaTeX: Make Bibliography appear in "Table of Contents"

Normally in report/book classes of documents, Bibliography will not appear in "Table of Contents", there are many workarounds for that; the easiest would be using the "tocbibind" package in preamble...

Saturday, 5 October 2013

Restart Ubuntu Desktop

Linux core is very stable, but that does not necessarily means that Ubuntu desktop is stable as well!
Many times Unity (Ubuntu's shell interface for GNOME) becomes totally unresponsive (at least for me!), since the core is stable and it is running, you can easily restart the desktop (without even having your running programs closed). If the desktop is totally unresponsive, then press Alt+Ctrl+F1 (to F6) to bring the console window. There you can run unity by (remember to detach the process by adding & disown, also redirect the output and error &> /dev/null. After it, simply hit Alr+Ctrl+F7 (or F8) to come back to the graphical desktop.
An alternative way is to restart compiz (since unity is a plugin of it): compiz --replace and if you're running from Alt+Ctrl+F1 terminal, then specify the display: compiz --display :0 --replace. You still need to add & disown.

Monday, 13 May 2013

Simple Events in Python

Having C# background and moving newly to Python, I was trying to find the easiest way to have some kind events in my Python classes and found this post very simple and useful.

All you need is to add this 'EventHook' class to your code and add events and event handlers to your code, exactly the same way as you did for your C# code.

Saturday, 9 February 2013

Focus method equivalent

In Windows Forms Application, when you wanted to set the focus to a specific control (e.g. a TextBox), you just needed to call its .Focus() method. The Objective C way of doing it on MonoMac and Xamarin.Mac world is to call: