Archive for October, 2008

Fix Moveable Type Export with Metatag TAGS instead of KEYWORDS

// October 26th, 2008 // 2 Comments » // linux, wordpress

Sometimes a Moveable Type export puts the tags in a Metatag field called TAGS. Sadly this kind of export file does not preserve the keywords/tags when it is imported in Wordpress. Here is a little fix to get these TAGS converted to KEYWORDS.

cat original.txt | sed '/^TAGS/s/ /,/ig' | sed '/^TAGS/s/"//ig' > converted1.txt ;let lines=`cat converted1.txt|wc -l`; let lines=`expr "$lines" : '\([0-9]*\)'`; for i in `seq 1 $lines`; do line=`head -n $i converted1.txt | tail -n 1`; istag=`echo $line|grep -E "^TAGS:"|wc -c`; if [ "$istag" -gt 0 ]; then tags=`echo $line|sed 's/TAGS: \\(.*\\)/\\1/g'`; echo $tags; fi; iskeyword=`echo $line|grep -E "^KEYWORDS:"|wc -c`; if [ "$iskeyword" -gt 0 ]; then let tagline=($i+1); fi; if [ "$i" == "$tagline" ]; then echo $tags; tags=""; tagline=0; else echo $line; fi; done > converted.txt

Simple way to get a diff to a server without subversion

// October 26th, 2008 // No Comments » // linux

I recently ran into the problem that I had to update the changes I made on my subversion sandbox to a shared hosting account.

In general you would just check out the revision you need or run a svn diff.

Sadly this is not only possible and you need to figure out the changed files which you need to copy to the server.

This simple little command creates a tar archive with the changed files.

Note: you should be in the path of the checked out repository.

let revision_start=196; let revision_end=225; tar cfv ../r$revision_start-$revision_end.tar `svn diff -r $revision_start:$revision_end . | grep Index | awk '{print \$2}'`

Getting a sandbox theme running on wordpress.com

// October 15th, 2008 // 9 Comments » // wordpress

At wordpress.com you can get a great blogging platform with very reliable and fast hosting for free. It comes with some restrictions compared to the self hosted wordpress.org version. One of them is that you can not upload your own themes.

Luckily there is the custom css upgrade which allows an easy alteration of the stylesheet of the supported themes. Together with the sandbox theme this still gives you a lot of opportunities to alter your design and get some additional themes running on your wordpress.com blog.

For my blog here I have choosen Sandpress, a winner of the Sandbox Designs Competition

Getting such a theme to run in a wordpress.com blog is quite simple although it takes a little more effort than on a wordpress.org blog.

  • First off you need to pick and download a theme and unpack it on your local machine.
  • Next thing you should do is to make sure that all the image files are in one directory. So if the theme you have choosen has multiple folders for images, take all these images and put them in one folder.
  • Now you need to upload these images to your blog as described in the  FAQ
  • Then go to your media manager (/wp-admin/upload.php) and check for the url of your images (right mouse button and copy link location on one of the thumbnails should do the job).
  • The urls should have something like this structure http://BLOGNAME.files.wordpress.com/YEAR/MONTH/FILENAME for example http://snipplr.files.wordpress.com/2008/10/sandpress.png
  • Now we need to alter the stylesheet of the sandbox theme of our choice to fit the new urls. So we just need to open it with a text editor and make sure all the paths for url() items within the stylesheet are matching the new image urls. Usually main work will be done with a simple search and replace of “images/” with “/files/YEAR/MONTH/”
  • Now it’s time to activate the Sandbox-10 theme (this should be at /wp-admin/themes.php?pa=4 on your blog)
  • Once this is done we are ready to try the altered css file. No need to purchase the css upgrade right away, you can just go to /wp-admin/themes.php?page=editcss on your blog and paste the css file into the textarea. Select the “Start from scratch and just use this” option and hit “preview”.
  • If everything looks like expected you just need to purchase the “custom css upgrade” and you will be able to save the stylesheet and store it for your site.

I hope this is of any use for the one or the other blogger out there. It should be simple enough to get a lot of extra themes running and if you need any help just leave me a comment.

Split up urls in their components

// October 10th, 2008 // 2 Comments » // development

This little call finds urls in a string and splits them up in their components. All with labels for easy usage.

preg_match_all('/(?P<protocol>(?:(?:f|ht)tp|https):\/\/)?(?P<domain>(?:(?!-)(?P<sld>[a-zA-Z\d\-]+)(?<!-)[\.]){1,2}(?P<tld>(?:[a-zA-Z]{2,}\.?){1,}){1,}|(?P<ip>(?:(?(?<!\/)\.)(?:25[0-5]|2[0-4]\d|[01]?\d?\d)){4}))(?::(?P<port>\d{2,5}))?(?:\/(?P<script>[~a-zA-Z\/.0-9-_]*)?(?:\?(?P<parameters>[=a-zA-Z+%&\&amp;\'\(\)0-9,.\/_ -]*))?)?(?:\#(?P<anchor>[=a-zA-Z+%&0-9._]*))?/x',$text,$data)

lighttpd for image hosting

// October 10th, 2008 // No Comments » // linux

In order to take some work of the webserver I recently installed a lighttpd server for delivery of static files.

The following tuning did the job (thanks to the video sharing script)

/etc/lighttpd/lighttpd.conf

server.max-keep-alive-requests = 4
server.max-keep-alive-idle = 4
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
server.max-fds = 8192
server.stat-cache-engine = "fam"

/etc/sysctl.conf

# These ensure that TIME_WAIT ports either get reused or closed fast.
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 1
# TCP memory
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
# For Large File Hosting Servers
net.core.wmem_max = 1048576
net.ipv4.tcp_wmem = 4096 87380 524288

in the apache virtual host we just use proxy pass to forward our static urls to the lighttpd server running on port 8080

ProxyRequests Off
ProxyPreserveHost On
ProxyPass /images http://127.0.0.1:8080/images
ProxyPass /js http://127.0.0.1:8080/js
ProxyPass /css http://127.0.0.1:8080/css
ProxyPassReverse / http://127.0.0.1:8080/