Create a custom application launcher in GNOME3

On Arch, the system-wide shortcuts are stored in /usr/share/applications. Each one is a .desktop file with a few parameters. user-specific icons are stored in ~/.local/share/applications. I downloaded eclipse and extracted it in my home directory, so I’ll use eclipse as the example application.

  1. Create the .desktop file:
    nano ~/.local/share/applications/Eclipse.desktop

    Paste this in:

    [Desktop Entry]
    Encoding=UTF-8
    Version=1.0
    Type=Application
    NoDisplay=false
    Exec=/path/to/eclipse/eclipse
    Name=Eclipse Comment=Launcher for Eclipse

    Each line is pretty self-explanatory. Edit to suit your needs. As soon as you save the file, you will be able to see your new shortcut in the list.

  2. (Optional) Give the shortcut a nice-looking icon:
    You probably noticed that your icon is an ugly diamond. To pretty it up, you simply have to add one more line to the desktop file.

     Icon=/path/to/eclipse/eclipse.

    Your application may have included a png icon, but to make it really look nice, you should grab an SVG file of the logo from somewhere. Arch has a very simple packaging process which lets you examine all of the package building elements through their webpage at http://www.archlinux.org/packages/. I was able to grab the SVG which the package uses like this:

    wget -O eclipse.svg http://projects.archlinux.org/svntogit/packages.git/plain/trunk/eclipse.svg\?h\=packages/eclipse

WordPress HTTPS secure login

Back when I started with , I had to create server rewrites to force my browser to use HTTPS. That changed back in 2008, but this is the first i’ve heard of it.

WordPress 2.6 (released in July, 2008) and newer include the tools do do this out of the box! Using this documentation, you can get rid of some old .htaccess or nginx rewrite rules: http://codex.wordpress.org/Administration_Over_SSL.  All you have to do is add the declaration in wp-config.php:

define('FORCE_SSL_ADMIN', true);

This forces logins and administrative sessions to use SSL.

Now, you can remove the old nginx rewrites. They aren’t needed anymore:

rewrite ^/wp-login.php(.*) https://www.surlyjake.com/wp-login.php$1 permanent;
rewrite ^/wp-admin(.*) https://www.surlyjake.com/wp-admin$1 permanent;

WordPress Redirection Plugin

This blog is undergoing some changes.There is some content (like the zabbix pages) that I can no longer maintain since I no longer use them in my day-job. To keep everything working seamlessly, I wanted to create some 302 (permanently moved) redirectors for the content that I was taking down. In the past, I used a plugin called “smart 404” to intelligently redirect visitors to a good page instead of the dummy standard 404 page. Unfortunately, It looks like smart 404 is having some trouble in newer versions and wouldn’t create a smart suggestions on my 404 page.

Enter Redirection. Redirection gives you a menu in the admin interface which allows you to easily create and maintain 301 and 302 redirections (among other features). Here is a screenshot of what it looks like once activated:

From the screenshot, you can see that I was able to create a simple 301 redirect from a page on my WordPress instance to an external website where the content will live from now on.  The second rule allowed me to match the URL using a regular expression and redirect it to another page on my site. This is a great piece of software.

One issue I ran into when testing the plugin was that edits I made did not seem to be taking effect. This turned out to simply be my browser caching the 301 response. I recommend that you either manually clear the cache or download the web developer toolbar and disable cache.  I should also note that my server runs nginx and not the Apache web server. I simply deleted the redirection ‘module’ for Apache which attempts to create .htaccess rules to perform the redirections. Without the Apache module, WordPress handles the redirections.

Redirection Plugin documentation: http://urbangiraffe.com/plugins/redirection/

Prevent samba from creating home directory for machine accounts.

Since this setup automatically creates a home directory for a user as soon as they access the machine (via samba, ssh, console), I noticed some directories being created for computer accounts.  To prevent this,  I have added a line that only “Domain Users” are allowed to authenticate.  To add this:

wbinfo -n "Domain Users"

It will spit out the SID for the Domain Users group. Something like this:

S-1-5-21-((some number))-((some number))-((some number)) Domain Group (2)

Take that number and change the Pam_winbind.so line in /etc/pam.d/common-session to look like this:

session sufficient pam_winbind.so require_membership_of=S-1-5-21-((some number))-((some number))-((some number)

Create a single standalone .exe from a Python program

I have been working on a small command line tool that I wanted to distribute it as a single executable file on . I tried cx_freeze and py2exe. Both of these tools worked well, but I couldn’t find an easy way to compress make the whole program into a .exe file. py2exe and cx_freeze both create working programs, but there are always some dependent .zip archive or .dll’s somewhere that need to be distributed with it. Pyinstaller, I found, actually compresses everything into a single .exe. This makes a pretty big executable (my small command line utility created a 5MB .exe file), but it’s simple and it works.

To use pyinstaller:

  1. grab pyinstaller 1.5rc (1.4 doesn’t work with 2.7). extract the zip file anywhere.
  2. change directories to the pyinstaller folder you just created.
  3. Before you create your first executable, you will have to run this once.
  4. python .py
  5. Now, pyinstall needs to scan through your program and create what they call a spec file.
  6. python makespec.py --onefile path\to\program\program.py
  7. Now, run this command to generate the executable.
  8. python build.py program\program.spec

Once the command has finished, the standalone executable will be available in the program\dist folder inside of pyinstaller.
Instructions for how to do this for a executable on ubuntu can be found here: http://excid3.com/blog/2009/12/pyinstaller-a-simple-tutorial/. You can find more info on pyinstaller at their website: http://www.pyinstaller.org/.