Recursive delete on Windows

I spent a stupid amount of time writing a batch script for something 10 minutes later I found out I could accomplish with one line.

Dreamweaver creates files called dwsync.xml inside every directory you syncronize after your first sync and I wanted to delete them all.

My batch file wasn’t too crazy, but the spaces in the file path caused some uglyness.

Anyway, the command to do this, once you’re in the highest directory you want to delete from is:

del /AH /S dwsync.xml

The hardest thing about figuring this out, is that in Windows, even a command prompt (even an Administrator command prompt) hides hidden files — so you need the /AH switch.

You could also add a prompt for each file, which is what I did for the first few to make sure everything was working as expected with the /P switch.

Leave the first comment

Keeping aliases with sudo (sort of)

I have an alias for vi that runs vim instead — simply:

alias vi='vim'

The problem was, aliases aren’t kept when running sudo (see man sudo and man sudoers).

So my natural tendency to write “sudo vi /etc/group” would end up calling vi, not vim — and I’d loose the syntax coloring I’ve fell in love with.

I’ve found some ugly work arounds over time, but after resetting my configuration after a reformat, I checked again and came across a beautiful alternative:

alias sudo='sudo '

Since the last character in the alias is a space, the next command is checked for alias expansion.

So now my

sudo vi /etc/group

expands to

sudo vim /etc/group

calling vim and my syntax coloring is restored.

Much thanks to shellperson.net for this one.

PS I say “sort of” because it will only work if your alias is the command immediately following sudo (which I expect most are).

Leave the first comment

Day-of-the-week function for Google Spreadsheets

Figured out this handy and compact (meaning its not a string of =IF statements) function for turning a date into a day of the week.

=MID("SaSuM TuW ThF ", (mod(int(B2), 7)*2)+1, 2)

This just takes advantage of Google Spreadsheet’s substring-like MID() function and will result in a two-letter date code. You could change this to the whole word if you wanted, by changing the first argument of MID() to be something like “Monday Tuesday Wednesday…”, with each word padding to the same amount of characters (I think 9 would be the shortest), changing the multiplier in the second argument to that number (say, 9) and changing the last argument to the number.

In the provided code, B2 is the cell that has the date.

Leave the first comment

Installing Adobe Dreamweaver CS4 using Wine 1.40 on Fedora 12 x64

These are the steps I used to install Adobe Dreamweaver CS4 with Wine 1.40 on Fedora 12 x64.

I don’t have a ton of time to go into the details, but I’ll show you the commands and annotate them quickly now and update the page when I get a second.

This is not for inexperienced users at this point — hopefully in the future it will be — however currently it is very rough and should only be attempted by those familiar with their Linux distro (hopefully if you’re reading this, F12 x64_86).

NOTE: The code below does not wrap long lines. There is a considerable amount of text that extends past the right side of the code viewer. To get the entire line, hover over the top right of the code viewer and click the far left button that says “view source”.

# Ensure you have the right packages to do this
sudo yum install git cabextract util-linux-ng

# Install Libraries
# -- x86_64 Libraries
sudo yum install arts audiofile bison bzip2-libs cairo compat-expat1-1.95.8-4 compat-libstdc++-33-3.2.3-63 compiz cups-devel cyrus-sasl-lib dbus dbus-devel dbus-glib dbus-libs directfb esound-devel esound-libs flex fltk fontconfig-devel freeglut freetype-devel giflib-devel glib2-devel glibc-devel gnutls-devel gphoto2 gpm-libs gsm gsm-devel gtk2 gvfs-gphoto2 hal hal-devel hal-libs imlib isdn4k-utils-devel jack-audio-connection-kit jack-audio-connection-kit-devel kernel-devel lcms-devel lcms-libs lesstif libacl libaio-0.3.106-4.2 libao libattr libcap libdrm libexif libgcrypt-1.4.0-3 libgnomecanvas libgphoto2 libgphoto2-devel libICE libICE-devel libieee1284 libjpeg-devel libmpeg2-devel libmpeg3-devel libmpeg3-utils libogg libogg-devel libpng libpng-devel libsigc++20 libSM libSM-devel libstdc++-devel libtool-ltdl libusb libusb-devel libv4l libv4l-devel libwmf libwmf-lite libX11 libX11-devel libXau libXau-devel libXaw libxcb-devel libXcomposite libXcomposite-devel libXcursor-devel libXdamage libXdmcp libXext libXext-devel libXfixes libXi-devel libXinerama-devel libxkbfile libxml2 libxml2-devel libXmu libXp libXpm libXrandr-devel libXrender-devel libXScrnSaver libxslt libxslt-devel libXt libXt-devel libXtst libXv libXv-devel libXxf86vm libXxf86vm-devel lzo mesa-libGL mesa-libGL-devel mesa-libGLU mesa-libGLU-devel mesa-libGL mesa-libGLw-devel mpg321 nas-libs ncurses-devel nss_ldap openal openal-devel opencdk openldap openldap-devel openssl-devel pam pkgconfig popt pulseaudio-libs sane-backends-devel sane-backends-libs sane-backends-libs-gphoto2 SDL svgalib unixODBC xine-lib xmms xmms-devel xmms-mp3 xorg-x11-proto-devel zlib zlib-devel
# Compile and Install Wine
setarch i686
# Install libraries
# -- i868 Libraries
sudo yum install ...

# Download and Install libmpg123
# http://sourceforge.net/projects/mpg123/files/
# !!-- This actually doesn't work -- !!
# Skip these steps and continue at "Download and Patch Wine"
# !!
mkdir /tmp/mpgsrc
cd /tmp/mpgsrc
wget http://downloads.sourceforge.net/project/mpg123/mpg123/1.10.1/mpg123-1.10.1.tar.bz2?use_mirror=cdnetworks-us-2
tar -xvf mpg123-1.10.1.tar.bz2
cd mpg123-1.10.1
setarch i686
./configure CC="gcc -m32"

# Download and Patch Wine
mkdir /tmp/winesrc
cd /tmp/winesrc
git clone git://source.winehq.org/git/wine.git ./
wget http://bugs2.winehq.org/attachment.cgi?id=22139 -O patch.diff
patch -p1 < patch.diff
cat dlls/msi/action.c.rej
echo "Consider lines 7282 and 7316"
gedit dlls/msi/action.c &>/dev/null &

# Compile and Install Wine
cd /tmp/winesrc
./configure
./make
sudo ./make install

# Install Winetricks
cd /usr/local/bin
sudo wget http://www.kegel.com/wine/winetricks
sudo chmod +x winetricks
cd ~

# Install Gecko
# Alternatively, you can try to automatically install Gecko by running winecfg and accepting the auto-install option.
# The first time I tried that, it didn't work, the second time, it worked perfectly.
rm -rf ~/.wine/drive_c/windows/system32/gecko/
sudo mkdir -p /usr/share/wine/gecko
cd /usr/share/wine/gecko
sudo wget http://downloads.sourceforge.net/wine/wine_gecko-1.0.0-x86.cab
cd ~

# Install other stuff
#   XML Parser
#   gdiplus.dll
#   MSVC++ 2005 SP1 Redistributable
#   MS Core Fonts
#   MSIE6
winetricks msxml6 gdiplus vcrun2005 corefonts ie6

# Install CS4 Specific Needs
winetricks atmlib

# Install DreamWeaver
cd ~/.wine/drive_c/...
wine Setup.exe

# Fix Fonts
# http://ubuntuforums.org/showthread.php?t=1009930
cd /tmp
vi settings.txt
# Alternatively, gedit settings.txt
# In this file, enter:
#   [HKEY_CURRENT_USER\Software\Wine\X11 Driver]
#   "ClientSideWithRender"="N"
regedit settings.txt

# Change gdiplus from native to built-in
winecfg

# Start Dreamweaver!
cd ~/.wine/drive_c/Program\ Files/Adobe/Adobe\ Dreamweaver\ CS4/
wine Dreamweaver.exe

Good luck and check back soon for a better explanation!

Screenshots

Leave the first comment

Adobe Air on Fedora 12 x64

I support Pandora and like the Pandora One desktop app (info and download, blog post).

Trying to get it to run successfully on Fedora was kind of a hassle.

Also, I’ve done this twice now and have had to do different things, so I’ll list them all.

First I downloaded the Adobe Air Installer.

wget http://airdownload.adobe.com/air/lin/download/latest/AdobeAIRInstaller.bin

… you could also have downloaded it through Firefox or whatever.

Now change the permissions and attempt to run it:

chmod u+x AdobeAIRInstaller.bin
./AdobeAIRInstaller.bin

Here I got a little dialog window, it looked like it began to install but then failed when it said that I needed gnome-keyring-daemon to be running.

The fact is, I had the gnome-keyring-daemon running. A simple ps confirmed this:

ps aux | grep keyring

The problem, it turned out, was that I had the x64 version of the keyring daemon running and was missing some x86 libraries.

I installed the x86 version of the gnome-keyring:

sudo yum install gnome-keyring.i686

… but that didn’t seem to do it — I was still missing something.

After some googling I came across a forum post saying these packages were also necessary:

yum install ld-linux.so.2 gtk2-devel.i686 libxml2.i686 libXt.so.6
yum install xterm rpm-libs.i686 nss.i686 libcanberra-gtk2.i686

This helped run the installer and it completed but threw an error that didn’t seem to cause any problems. For good measure I installed this package too to address the error:

sudo yum install PackageKit-gtk-module.i686

So now I had Adobe Air successfully installed, but whenever I tried to install an Air application, I would get a segfault.

Application crashed with an unhandled SIGSEGV

I was able to see this message by running “Adobe AIR Application Installer” from command line, not the Application menu. Otherwise, the installer would pop up for a split second and immediately disappear.

Anyway, after some more googling, I came across a forum post regarding certificates and a fix.

The command basically goes through the Adobe certificates and marks them as trusted (aucm is the Adobe Unix Certificate-Store Manager)

for c in /etc/opt/Adobe/certificates/crypt/*.0; do sudo aucm -n $(basename $c) -t true; done

(I added the sudo because I wasn’t running as root and that gave me a ton of “Root permissions are required to modify the certificate store.” errors.)

After running that, I got a lot of “Certificate Found, processing… Property changed.” messages.

Once that was complete, I was able to install the Pandora Air Application and run it without problems.

To summarize without the details:

cd /tmp
wget http://airdownload.adobe.com/air/lin/download/latest/AdobeAIRInstaller.bin
chmod u+x AdobeAIRInstaller.bin
./AdobeAIRInstaller.bin
sudo yum install gnome-keyring.i686 ld-linux.so.2 gtk2-devel.i686
sudo yum install libxml2.i686 libXt.so.6 xterm rpm-libs.i686
sudo yum install nss.i686 libcanberra-gtk2.i686 PackageKit-gtk-module.i686
for c in /etc/opt/Adobe/certificates/crypt/*.0; do sudo aucm -n $(basename $c) -t true; done
Leave the first comment

Create new Google Doc Bookmark

I wanted to bookmark a link to bypass the whole google docs page and go straight into a new google doc.

I found it:


https://docs.google.com/MiscCommands?command=newdoc&redirectToDocument=true&hl=en_GB

Just make sure to add a new bookmark and paste that as the address, don’t navigate there and try to bookmark the page, the URL will have changed and you will probably end up bookmarking that specific document.

Source: Pain in the Tech

2 comments so far, add yours

Force Apache2 to redirect from HTTP to HTTPS

Want to redirect requests for http://www.yoursite.com to https://www.yoursite.com?

There are many suggestions out there to add a .htaccess file with rewrite conditions[1] but I figured I’d suggest a second, through a simple change to your httpd.conf file (or if you are running Ubuntu or another distro that splits the httpd.conf file into multiple files, in your /etc/apache2/sites-available/{yoursite} configuration file. (If you are running a pretty Ubuntu install, the file is /etc/apache2/sites-available/default)

This technique still uses the rewrite engine (so you’ll need mod_rewrite module) but it places the configuration in the httpd.conf file (or its equivalent) and out of the .htaccess file.  There are many reasons you might want to do this, such as prevent it from being changed (many site configurations allow users to edit all .htaccess files but prevent them from editing the httpd.conf file) or to prevent it from being overwritten by certain web application packages (many application packages including WordPress and MediaWiki employ custom .htaccess files to provide more friendly URLs).

The change is simple, in your httpd.conf file, change the following part of your virtual host section:

<VirtualHost *:80>
        ServerAdmin contact@yourwebsite.com

        DocumentRoot /var/www/public

        <Directory />

… to something resembling the following:

<VirtualHost *:80>
        RewriteEngine on
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

<VirtualHost *:443>
        ServerAdmin contact@yourwebsite.com

        DocumentRoot /var/www/public

        SSLEngine On
        SSLCertificateFile    /etc/apache2/ssl/mycert.pem
        SSLCertificateKeyFile /etc/apache2/ssl/mycert.key

        <Directory />

The important things here are that the port 80 Virtual Host has been changed to listen on port 443 (Line 7), there is a new Virtual Host that has been added above our existing Virtual Host that is set to listen on port 80 and only contains the rewrite code (Lines 1-5), and finally, there are lines added that enable and configure the SSLEngine (settings may differ based on implementation)(Lines 12-14).

Restart Apache and your browser should redirect requests to http://www.yoursite.com/ to https://www.yoursite.com.  In case you’re wondering, a request for http://www.yoursite.com/staff/about.php will also redirect to https://www.yoursite.com/staff/about.php.

Leave the first comment

Clearing Subversion information from a project

Subversion stores its information in hidden folders named “.svn” inside each added directory. Sometimes, you might want to remove all off these .svn directories, and start fresh. There are any number of reasons to want to do this, but in my case I wanted a quick way to reset a working copy on a windows machine.

I found a good batch script (source) that does exactly what I needed:

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"

I just threw that line in a text file, and saved it as rmsvn.bat in the highest directory that I wanted to strip .svn files from.

Opening up a command prompt, changing to the directory I saved the batch file in (with cd) and then running the file (with rmsvn.bat) worked perfectly.

Leave the first comment

Moving a Subversion Repository

Sometimes it is necessary to move a subversion repository. In this case, it was because I wanted to consolidate a few subversion repositories into one directory on a dedicated hard drive.

Moving a subversion repository usually consists of two steps:

  1. Moving the repository
  2. Updating the working copy to reflect the repository move

This post will handle both steps.

Move the repository

Instead of actually moving the repository as one would expect, we’re going to backup our existing repository, import out backup into a newly created one.  First we’ll list the commands, then break down what we’re doing.

svnadmin dump /path/to/old-repository > ~/repo.dmp
svnadmin create /path/to/new-repository
(Update file/directory permissions)
(Update repository permissions)
svnadmin load repository-name < ~/repo.dmp
  1. L1: We dump the repository into a backup file.
  2. L2: Create a new repository.
  3. L3: Update file / directory permissions (by using some combination of chown, chgrp and chmod)
  4. L4: Update repository permissions (by editing files like /path/to/new-repository/conf/passwd and /path/to/new-repository/conf/svnserve.conf)
  5. L5: Extract the backup into the new repository.

Update the working copy

Once we’ve moved our repository, we now need to update the working copy so that commits and updates will reference our new repository.

cd /path/to/working-copy
svn info
svn switch --relocate svn://hostname/path/to/old-repository svn://hostname/path/to/new-repository
svn info
  1. L1: We change to the path of the working copy.
  2. L2: Display the path to the old repository through the svn info command.
  3. L3: Switch the working copy’s repository.
  4. L4: Display the path the the working copy’s repository (verify that the switch worked) through the svn info command.

Clean up

Now that we’re done moving the repository, we want to verify the move and clean up.  To verify the move, we can just check the output of the svn info command.  To further verify, we can run svn update to ensure that nothing is updated.

We will probably also want to remove both the old repository and the backup file.  A simple rm -r for the repository and rm for the backup file is fine.

Lastly, its possible that you would want to use a trimmed down set one of these steps. For example, if you didn’t care about keeping the version history and just wanted to move the repository location, you could skip steps 1 and 5 in the first section. Also, if you didn’t care about moving the working directory but just wanted to make a complete copy of the repository including the version history, you could complete the whole second section.

Leave the first comment

ping fails but dig / nslookup works?

I’ve now run into two scenarios where this happened. The most recent was after I had to kill a vpnc process (used to connect to a cisco VPN).

It looks like this:

[james@workstation ~]$  ping google.com
ping: unknown host google.com

[james@workstation ~]$  dig google.com +short
72.14.204.147
72.14.204.99
72.14.204.103
72.14.204.104

What ended up happening was that the VPN was configured to tunnel all traffic through it, so when it re-wrote the /etc/resolv.conf file, it didn’t append the VPN nameservers to the nameservers provided to us by our DHCP lease, but completely overwrote them. I’m assuming that when you closed the VPN it would replace the resolv.conf file with the one containing the non-VPN nameservers but since I killed it, it was not restored.

Anyway, the fix was easy but finding it out was annoying.

All you have to do is release and renew your DHCP lease.

You could try:

dhclient -r; dhclient

… but I was on an SSH connection and I didn’t quite trust the second command to be run after I lost the connection when the lease was released (this seems like a silly fear but whatever).

Instead I wrote a bash script and put it in a file:

#!/bin/bash
#refreshlease.sh
IFACE="eth0"

dhclient -r ${IFACE}
dhclient ${IFACE}

… and ran that over the SSH connection. The connection seemed to get dropped for a few seconds but then came back up. Checking /etc/resolv.conf showed that my original nameservers were, in fact, back and I was able to resolve DNS queries:

[james@workstation ~]$  ping google.com
PING google.com (64.233.169.105) 56(84) bytes of data.
64 bytes from yo-in-f105.1e100.net (64.233.169.105): icmp_seq=1 ttl=238 time=31.1 ms
Leave the first comment