Text

Vim Macros - A practical example

I have been using Vim for the last eight months in a daily basis and the more I use it the more I like it. There was some functionality that always seemed like dark to me and I never understood how to use it: Vim Macros. So today I finally learned how to use it and it was really useful. I decided to share my humble enlightenment and in this blog post you will read my findings. Suppose you have very big file with some sort of format that you want to change:
"san francisco", "(californaia)" => "usa"
"san antonio",  "(californaia)" => "usa"
"new york", "(new york)" => "usa"
"seattle", "(washigton)" => "usa"
...
And you would like to change that file to something like this:
'san francisco', 'californaia',  'usa'
'san antonio',  'californaia' , 'usa'
'new york', 'new york' , 'usa'
'seattle', 'washigton', 'usa'

How would you do that? If you are a regular expression magician, maybe you could find one really quickly that will solve your problem. But if you are like me, you wouldn’t like to spend 10-15 minutes figuring out what is the regular expression that is going to solve your problem.

Vim macros are here to save us. In vim, a macro is a sequence of commands that are save for future uses. To start recording a macro you type ‘q’ followed by a letter (called register), to store the macro . Then type the sequences of commands and then ‘q’ again to stop recording.

After that if you want to use the macro, you type ‘@’ followed by the register where the macro is stored. Let’s see this with our text what would the macro look like:

qa0r'ESCf"r'ESCf"r'ESClxESCf)xr'lr,lxxlr'f"r'ESCq
ESC stands for the key “ESCAPE”. So after that we have in register a our macro that transform our line in the desired format. So now we need just to apply that macro in the whole file. Type the following in command mode:
2,158norm! @a

Et voila! Your file is now the way you want it. I know it looks a little bit long the lists of commands that you have to type to transform the text, but if you are familiarized with vim, is something that you would have done anyway. The difference is that you recorded the sequence of commands and now you could repeat it over and over.

NOTE: If you have plugins like vim surrounds, the sequence of keystrokes would have been shorter. However, for the example I just used plain vim commands.

April 03, 2012
0 comments
Link

Mitchell Hashimoto: Lessons Learned Building Open Source Software

mitchellhashimoto:

Having spent a significant amount of time conceptualizing and growing Vagrant into a decently successful open source project, I’ve come away learning quite a bit. I haven’t seen many blog posts about open source maintainers commenting on their lessons learned, so I’d like to share them here. These…

March 31, 2012
0 comments
8 notes
Text

New Relic + Clojure + Heroku: Easy steps integration.

Last week I set up a clojure app in heroku using new relic. The steps are really straight forward (are basically the same that you find for you Java), but given that there are no official instructions for using new relic in a clojure app a decided to write this small post:

0) Add new relic to your instance

Add new relic to your instance via the UI or by terminal using:
$ heroku addons:add newrelic:standard

1) Download new relic

At the moment of this post you could download new relic here.

2) Check gitignore file

If you created the project with lein, make sure that in your .gitignore you don’t have *.jar.

3) Add new relic to your project

$ git add newrelic
$ git commit -m 'add newrelic'
$ git push heroku master

4) Enable the Java Agent

Add the following flag to your JVM_OPTS config var on Heroku: -javaagent:newrelic/newrelic.jar

You can get the current value of your config var with:

$ heroku config
...
JVM_OPTS             => -Xmx384m
...

Add the config var:

$ heroku config:add JVM_OPTS='-Xmx384m -javaagent:newrelic/newrelic.jar'

And thats it!! You should have new relic working now!

Tags: clojure new relic heroku
March 10, 2012
0 comments
Text

Copied ssh-private key not working

Today I was suffering because a problem with a ssh-private key. I had a private/public key properly set and working for deploying an application and for reasons beyond the scope of this project I decided to change it. So I generate the new key and it was working properly. Something like this:

ssh -i private-key user@myserver.com

It was working and I was very happy. But then, I copied this private-key to a another folder and it stopped worked. I check the permissions, check-sums of the file and everything was exactly the same. No clue whatsoever of what was going on.

Then I changed the name of the file from private-key to private-key2 and it worked. At this point I was about to cry. So after a lot of research and pain, I found what was the original issue. It turns out that I had a file called private-key.pub (corresponding to the previous key) in the folder where I copied the new private key. It seems that ssh doesn’t like this, it tries to use this public key to match the private key and because it doesn’t, it refuses to do the authentication.

So the lesson to be learned here is that if you copied a private key (my_private_key) and it happens that you have a file called my_private_key.pub in the same folder, make sure that this public key corresponds to the private_key, otherwise you are not going to be able to connect to the remote machine, even if there is nothing wrong with your private_key.

November 29, 2011
0 comments
Photo
spacer

This was me today!

September 28, 2011
0 comments
1 note
Text

Palabras contra la intolerancia y homofobia

Estimada Maria Denisse,

Mi nombre es Rafael Chacón, soy un venezolano, heterosexual. Acabo de leer el siguiente artículo en el universal. Primero pensé en solo responder por email, pero dado que su artículo es público, decidí hacer una respuesta de la misma forma.

Francamente estoy muy sorprendido por sus palabras. Probablemente usted nunca responda a esta replica y yo este perdiendo mi tiempo al escribirle, pero sin embargo siento la responsabilidad de hacerlo de cualquier forma.

Primero me gustaría decir que siento mucha pena por la señora canadiense que tuvo que pasar por una infancia tan traumática. ¿Pero podría usted afirmar con certeza que la causa fue homosexualismo de su padre? ¿Cuantos padres heterosexuales no malogran la educación de sus hijos también? ¿No le parece que la pregunta pertinente esta relacionada a la educación familiar y la inculcación de valores, independientemente de las preferencias sexuales?

Me preocupa, que queden escritas palabras que promuevan el desprecio hacia a otros seres humanos por sus tendencias sexuales. Hacer un vinculo directo entre homosexualidad y el maltrato infantil, me parece una simplificación tan burda de la realidad, equivalente a otras que ya tanto daño han hecho como: los musulmanes son malos, los judíos son el mal del mundo, todos los afganos son terroristas y pare usted de contar.

De sus palabras se filtra un mensaje de intolerancia y ceguera hacia la diferencia, que quizas sea aun más peligroso que la adopción por parejas no heterosexuales. ¿Es ese el mundo que usted quiere crear?

Cordialmente.

September 28, 2011
0 comments
Text

Can’t upload App - ‘An error occurred uploading to the itunes store’

Yesterday I was trying to upload an application to the appstore and I was getting and getting the following error:

“Can’t upload App - ‘An error occurred uploading to the itunes store’”

I was trying to submit it through xcode 4.3 with organizer. All the validations passed so I didn’t have a clue of what was going on. After a few hours the problem continued and after that I installed a software update that was available for java in the updates center and I also restarted the computer.

I’m not sure if it was the rebooting or the Java update, but after that I was able to submit the app.

I hope this could be useful for someone else…

September 12, 2011
0 comments
Text

Rails + Wordpress + Apache integration

Last week in my work I found with a requirement that took me more time than I expected to solve. We had a wordpress blog running under a subdomain of our main app. Let’s say blog.myapp.com and we wanted to move it to myapp.com/blog. Should be simple right?.

So I started to do some research and I found this post by Ilya Grigorik. I also read this post by Barry Hess that helped me a lot.

I found others that contributed to my solution, but none of them worked for me at the first try. What I did at the end was a combination of rewrite conditions inside wordpress .httaccess file and the use of alias and location inside the VirtualHost configuration.

Configuration Steps

The first thing that you need to do is to add the following to the virtualhost configuration of your main site:


Alias  /blog /path/to/wordpress/blog
<Directory /path/to/wordpress/blog>
  Allow From all
  Options +Indexes
  AllowOverride all
</Directory>

<Location /blog>
  PassengerEnabled off
</Location>

After this, you should go to /path/to/wordpress and edit the .htaccess and change it to:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /blog/
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /blog/index.php [L]
</IfModule>

Now there is an important step that you need to do inside the wordpress application. You must change the URL of the app to point to the new direction. I did this defining two variables in the wp-config.php file:

define('WP_HOME','myapp.com/blog');
define('WP_SITEURL','myapp.com/blog');

The previous step you could do it trough the wordpress settings UI as well if you want

So that should be it, you just need to restart your apache server and your blog is going to be running and working under myapp.com/blog

Corollary

If you don’t want to lost traffic from previous urls pointing to blog.myapp.com you could add the following rewrite rule in the virtual host configuration the app:
  ...
  ServerName blog.myapp.com
  DocumentRoot /path/to/wordpress
  RewriteEngine on
  RewriteRule ^(.*) www. myapp.com/blog$1 [R=301,L]
  ...
Tags: rails wordpress apache
September 06, 2011
0 comments
9 notes
Text
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.