Google
 

Friday, October 19, 2012

Adding "Copy as Path" menu item to Nautilus

I use both Windows and Ubuntu Linux. One of the features I miss in Nautilus file manager under Ubuntu is the "Copy as Path" menu item which is available in Windows explorer context menu by holding the Shift key while right-clicking on a file or folder.
I tweaked Nautilus to do have "Copy as Path":



This required two steps:

First step:
A simple Python script to copy the path to clipboard:

#!/usr/bin/python
import gtk
import sys

clipboard = gtk.clipboard_get()
text = sys.argv[1]
clipboard.set_text(text)
clipboard.store()


This script uses gtk Clipboard to copy the path of the file, which is passed as the second parameter, the first is the script itself.
Save the script to a .py file and then move to the:

Second step:
Use Nautilus-Actions to add the menu item that will invoke the script.
It can be installed from Ubuntu Software Center or using terminal:

sudo apt-get install nautilus-actions

Open Nautilus Actions and Add a new action:




In the Command tab, enter python for the Path, and "/path_to_script/script_name.py %f" in the Parameters text box (replace with your own values, where you saved the script).
Note that the %f parameter means the selected file or folder path.

By default, Nautilus Actions creates a sub menu, and adds the custom actions to it. I did not like this behavior, which can be changed from the preferences by un-checking: "Create a root 'Nautilus-Actions' menu".
Changing this setting requires quiting nautilus:

nautilus -q

This simple tweak saved me a lot of time !

Saturday, September 29, 2012

Tip: Sending email to local folder for ASP.NET local development

Many web applications and sites have features that require sending emails. In production, usually mailSettings element of system.net is configured to send emails using SMTP server.
But when developing on a local machine, you want to check the output email quickly and without relying on a SMTP server. Sometimes a local antivirus can make the process harder.
It's better to configure the mail to send to a local folder, this can be easily done by setting the delivery method to SpecifiedPickupDirectory and setting the local directory location:
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp"/>
</smtp>
</mailSettings>
</system.net>

Now, when your code sends an email, a .eml file will be saved to c:\Temp, and you can double click it to check its content.

Wednesday, March 28, 2012

Returning full path of records in tables with recursive relationships

A common requirement when dealing with tables with recursive relationship where a record points to another (parent) record in the same table, is to get the full path of the record name. like the case with full folder paths in a file system hierarchy.
For example: (data from http://www.ida.liu.se/~iislab/projects/secont/main/)


CategoryId Name ParentCategoryId
 1 Asset NULL
2 Countermeasure NULL
3 Cryptography 2
4 Encryption 3
5 SignatureAlgorithm 4
6 CryptographicHashFunction 5
7 DSA 6
8 MD5 6
9 EncryptionAlgorithm 4
10 BlockCipher 9
11 AES 10
12 DES 10

For the above data, we need to get this:

CategoryId Name
1 Asset
2 Countermeasure
3 Countermeasure > Cryptography
4 Countermeasure > Cryptography > Encryption
5 Countermeasure > Cryptography > Encryption > SignatureAlgorithm
9 Countermeasure > Cryptography > Encryption > EncryptionAlgorithm
10 Countermeasure > Cryptography > Encryption > EncryptionAlgorithm > BlockCipher
11 Countermeasure > Cryptography > Encryption > EncryptionAlgorithm > BlockCipher > AES
12 Countermeasure > Cryptography > Encryption > EncryptionAlgorithm > BlockCipher > DES
6 Countermeasure > Cryptography > Encryption > SignatureAlgorithm > CryptographicHashFunction
7 Countermeasure > Cryptography > Encryption > SignatureAlgorithm > CryptographicHashFunction > DSA
8 Countermeasure > Cryptography > Encryption > SignatureAlgorithm > CryptographicHashFunction > MD5

This can be achieved using Recursive Common Table Expressions:

WITH CategoryCTE
AS
(
SELECT C.CategoryId, CONVERT(NVARCHAR(500), C.Name) AS Name FROM dbo.Category C
WHERE ParentCategoryId IS NULL
UNION ALL
SELECT C.CategoryId, CONVERT(NVARCHAR(500), CTE.name + N' > ' + C.Name) AS Name FROM dbo.Category C
JOIN CategoryCTE CTE ON C.ParentCategoryId = CTE.CategoryId
)
SELECT * FROM CategoryCTE 

It works like this:
  • The CTE selects from the base table data, the level which has no parents
  • The result is union-ed with the recursive part, which joins the base table with the last value of the CTE up to the current level of recursion
  • The name field of a record is a concatenation between its parent name and its own name
  • Select the result of the CTE

Monday, February 13, 2012

Hotkeys for Banshee Media Player on Ubuntu without multimedia keyboard

My keyboard lacks multimedia keys. So controlling Banshee media player becomes annoying, because I have to switch to it to pause or resume playing or performing other actions on the play list currently running.
Banshee has shortcut keys for playback (space to play/pause) but the Banshee window must be active.
So here is how to make the hotkeys:

Step 1: Install CompizConfig Settings manager:
Using terminal:

sudo apt-get install compizconfig-settings-manager

Or you can install it from the software center.

Step 2: Know the actions you want to create shortcuts for:
Banshee has a command line interface. To discover the correct shortcut, we use man at terminal:
man banshee
This will let us know that, for example, the --toggle-playing option will toggle from play to pause and vice versa.


Step 3: Use CompizConfig to configure Hotkeys
Open CompizConfig, and click Commands.


In the commands tab write:

banshee --toggle-playing
In the Key Bindings tab, click one of the buttons with Disabled label that corresponds to the command line number you previously edited. In the dialog, check Enabled. Then enter the key combination of your choice.


You can add any other hotkeys for other functions as you need. And that's it.
Enjoy!!

Monday, January 2, 2012

Articles I read in 2011

Welcome 2012 !!
As usual, I'm interested in sharing articles I read during the past year, hopefully you'll find something useful in it.

2010's list can be found here
2009's list can be found here
2008's list can be found here 
2007's list can be found here