Categories
Emacs GNU/Linux Free Software & Open Source Tutorials & Tips

Post to WordPress blogs with Emacs & Org-mode

Recently I’ve discovered Org2blog, an Emacs mode to write your blog posts locally using org-mode post them to your WordPress blog in a very fast and easy way.

I’ve written before on how to write your blog posts and publish them using Emacs. Previously, my method of choice was using Weblogger mode. I even wrote some enhancements to it.

The problem I found with this method is that it uses message-mode as its base mode. So you’re basically writing an email. The shortcomings of it were that whenever I wanted to write links, bold text, or any custom formatting generally done through HTML tags, I had to either type out the HTML or temporarily switch to html-mode. That sometimes gave me some problems converting the HTML code into entities, and ended up with a mess to fix at the WordPress editing textarea.

Org-mode (included in Emacs since about version 22.1), if you haven’t heard about it already, is a very good way to take notes, organize your tasks, among other day to day useful things. You also get some basic formatting like bold text and italics, as well as links among many other useful things. Nowadays, I find myself typing things in org files constantly throughout my day, and with all its long list of qualities, it became a more suitable way for me to write blog posts.

Org2blog provides a way to post your Org files or post a subsection of your file with a few keystrokes. All you need to do is clone the repository on your load path directory

git clone http://github.com/punchagan/org2blog.git

Then, add this to your .emacs file

  (setq load-path (cons "~/.emacs.d/org2blog/" load-path))
  (require 'org2blog-autoloads)

Finally set up you blog(s) settings in you .emacs file

     (setq org2blog/wp-blog-alist
           '(("wordpress"
              :url "http://username.wordpress.com/xmlrpc.php"
              :username "username"   
              :default-title "Hello World"
              :default-categories ("org2blog" "emacs")
              :tags-as-categories nil)
             ("my-blog"             
              :url "http://username.server.com/xmlrpc.php"
              :username "admin")))

To start wrigint a new post, you can now use
M-x org2blog/wp-new-entry

Or, as I more frequently use, post a subtree of an existing org file using:
M-x org2blog/wp-post-subtree

I hope you enjoy writing and posting your blog posts within Emacs and Org-mode. I certainly do and has turned out to be a very fast way to quickly draft and later on (even offline) elaborate on the blog post details in a comfortable editing environment. Also you get the added benefit of having a local copy (backup) of your blog posts as Org files.

Categories
GNU/Linux Free Software & Open Source Tutorials & Tips

Restore Samsung Galaxy S to Original ROM from Telcel Mexico

Flash Samsung Galaxy S with Odin

Two weeks ago, I messed up my Galaxy S phone. I was having trouble with the back key activating by itself without touching it. As I’ve said before, I use Darky’s ROM instead of the crappy Samsung/Telcel default one. So searching for a possible solution, I found out that you could update your touchkeys firmware.

Well, I went ahead and updated it. To my surprise, it completely disabled my touch keys (the back and menu buttons). So, if you have the same problem with you back button key, DO NOT upgrade your firmware if you’re using a custom or unofficial ROM…or keep reading… Now my problem was worse than before! I then searched for a solution on that, and the only answer was: return to the default ROM and upgrade the touchkeys again, then revert back to your custom ROM.

That’s when my long journey began. Back when I changed to Darky’s ROM, I used Clockwork Recovery to do so. And of course, I made a backup of my current ROM. Turns out that, to restore from a backup, you need to be on the original ROM (or the ROM that backup has). And well, I had no other place to get that, since I thought my backup would solve it all. So I ended up spending almost all saturday looking for the original Samsung Galaxy S ROM from Telcel Mexico, until I finally found it!

To flash your Android device, you’ll need a program called Odin which is a leaked Samsung application that unfortunately runs only on Windows machines. There’s an open source, cross platform flashing software called Heimdall, but I couldn’t get it to work correctly, there’s not much documentation, so I couldn’t figure out my problem. I hope that project grows and evolves into a more stable alternative to Odin. So, I had to borrow a Windows XP netbook from a co-worker for a day so I could use the Odin software to Flash my phone.

I wanted to share my finding with some friends who have asked me about the same problem. So follow this forum post if you need to revert back to the original ROM, or recover your phone from a backup and you have a Galaxy S from Telcel. The post makes reference to this unofficial guide to upgrade to Froyo in case you loose your 850Mhz band.

I hope this solves your problems and helps you save all the time I had to invest to get to this solution. Changing the original ROM on your Android device is a risky move, but I find it worth it.

Photo is Creative Commons by fraencko on Flickr.
Categories
GNU/Linux Free Software & Open Source Tutorials & Tips

Quick search and replace recursively in multiple files

Lately I’ve been working with a lot of static HTML files with lots of repeating text structures. In the past I’ve talked about editing multiple files with Emacs. This approach works very well when the number of multiple files and text matches in each file is manageable or you need to make sure every match to replace is correct, since you need to confirm pressing y on every text match in each file.

In other cases, like the one I had to solve, you can have 84,000 text files where each file can have more than 5 matches. This case, doing it with Emacs wouldn’t reduce much time. It also helps that the pattern I was looking for was consistent without me needing to check every match.

So to do a quick search and replace recursively in multiple files, another “old school” tool comes very handy.

GNU Sed

Quoting from the GNU Sed project page:

Sed (streams editor) isn’t really a true text editor or text processor. Instead, it is used to filter text, i.e., it takes text input and performs some operation (or set of operations) on it and outputs the modified text. Sed is typically used for extracting part of a file using pattern matching or substituting multiple occurrences of a string within a file.

The way to tell sed to do a search and replace on some given text, the syntax is the following:

sed -n -e 's/regex/text/g' filename

The -n switch makes Sed not to output its results to the standard output and overwrite the file with the results. The -e switch specifies that the following string is a command to perform on the file. The regex part is the regular expression to use for searching in your text. The text part is the text you want to replace your search with.

So Sed receives streams of text as input, makes some operations on it and outputs the results. This way of seeing it, makes it very obvious to understand that the natural way to use it is through bash calls using pipes.

The find tool will help us get a list of all the files that we need to pipe into sed. In the same way we used find from within Emacs, we can call it from bash:

$ find path/to/folder -iname "filenamepattern"

So a combination of find with sed can be used in the following way:

$ find myprojectfolder -iname "*.html" | sed -n -e 's/searchregex/replacementtext/g'

As easy as that, and you have edited 84,000 files with one single line of bash.

Hope its useful for anyone. It has been very useful to me. If you have other methods or other sed tips, I’d like to know in the comments.

Categories
GNU/Linux Free Software & Open Source Programming & Web Development Tutorials & Tips

How to install latest Git on Ubuntu

Git Logo

Git is a distributed version control system. I won’t go into much details of what Git is or why use Git instead of other VC systems. There’s plenty other sites where to check that information.

I love Git, but there’s a slight problem with Ubuntu’s repositories (feisty, gutsy): its an old version.

Git’s version on the repositories is 1.5.2.5. Its an old version and it lacks many of the new cool features like git stash and git citool and many others. So to get the latest version with all the cool features, you have to compile from source.

To do that, you will need the following packages:

First install the all the basic tools for compiling source:

sudo aptitude build-essential


sudo aptitude install libc6 libcurl3-gnutls libexpat1 zlib1g perl-modules liberror-perl libdigest-sha1-perl cpio openssh patch
gettext curl tk8.4 tcl8.4

Download the tarball from http://git.or.cz and uncompress it.

$ tar xvzf git*.tar.gz

Then, run the compilation steps and install:

$ ./configure
$ make
$ sudo make install

And there it is! Run the following to check your version.

$ git --version

The only thing that I still don’t know how to get is git command autocomplete on bash. If you install from repositories, then install from source, you’ll have it all.

Categories
Programming & Web Development Tutorials & Tips

Animate your webpage fast and easy with Facebook Animation Library

Today Facebook released an animation javascript library that modifies CSS properties on the fly. You can download it and use it on your webpages.

Its a very light (10.4 Kb compressed version) animation library and its very easy to use. You can chain events or animations to create the effects you want. You can download it on the facebook developer’s resources page.

A typical effect used in websites is the flash effect to alert or notify of some action.

Here’s all you need to accomplish that:


<a href="#" onclick="Animation(this).to('background', '#fff').from('background', '#ffff4b').go(); return false;">Flash</a>

The syntax is easy. All you need to do is call Animation(this) on your element and then specify what CSS property you want to change on the .to and .from methods. In this case: go from yellow background to white background. The last .go() method tells Animation to run the specified animation.

You can also mix animations or transitions instead of playing one animation after another. For this you have to use .checkpoint() function and .duration() to specify how long the transition will take (in milliseconds). The checkpoints indicate when the second animation will start playing, allowing you to tweak the default behavior of playing one animation after the other one stopped.

So you can basically change anything: colors, widths, lengths, margins, positions, etc. For complete documentation of the library, go to the Facebook Developers Wiki. Its worth checking out.

Its a very simple syntax, with familiar terms (CSS properties) and very lightweight compared to using Prototype and Scriptaculous. Maybe Scriptaulous syntax for doing some animations is simpler or shorter, but you must load Prototype in order to use it, so that makes it heavier. Plus, you need to know the Scriptaculous effects functions and sometimes they are not that tweakable.

Its also nice to see Facebook releasing some open source code (BSD licensed) and contributing back.

Categories
GNU/Linux Free Software & Open Source Tutorials & Tips

Como enviar videos al Xbox360 desde Linux

Por fin encontre la forma de enviar videos a mi Xbox360 sin tener que usar Windows.

Muy sencillo, solo instala ushare

Vas a necesitar libupnp
sudo aptitude install libupnp2

ejecuta el siguiente comando para iniciar el servicio de ushare:

ushare -p 49153 -D -x -c /home/usuario/videos/

Esto lo puedes poner en un script que se ejecute al iniciar la sesion lo como quieras.

Ahora, si el Xbox360 se queja de que no soporta el tipo de archivo o que no encuentra ningun video, puedes convertir tus videos facilmente con Avidemux.

sudo aptitude install avidemux

Abres el video, en el lado derecho seleccionas Mpeg4(lavc) como codec de video, FAAC como codec de Audio y MP4 como Formato. Guarda el proyecto y Avidemux empezara a convertir tu video a MP4.

Esta informacion la saque del Linux HowTo Blog. Habia estado varias semanas buscando una forma de hacer esto hasta que por fin he visto la luz.

Para mas detalles y paquetes deb para Ubuntu, chequen el post del Linux HowTo Blog.