Posts

XA4PPR with Jabber for in band registration

xmpp4r gem jid = Jabber::JID::new('admin@ejabberd.server.com/res') client = Jabber::Client::new(jid) client.connect client.auth("admin_password") iqr = Jabber::Iq.new(:set) qr = Jabber::IqQuery.new qr.add_namespace('jabber:iq:register') username = 'nishant' password = 'nishant' qr.add(REXML::Element.new('username').add_text(username)) qr.add(REXML::Element.new('password').add_text(password)) iqr.add(qr) client.send iqr

Imagemagick prerequisites

Before installing  Imagemagick  in your system. Make sure you have these dependencies installed 1) PNG library - development libpng12-dev 2) Independent JPEG Group's JPEG runtime library (dependency package) libjpeg8 You can install these dependencies using Ubuntu Software Center.

Difference between PATCH and PUT requests

PATCH does a partial update and PUT is used to update the whole resource. Lets take an example If PATCH request submitted with 2 fields for a resource with 8 fields, then only those 2 fields are updated and for PUT request the 2 fields are updated and others are set to their default/existing values.

Apache Benchmark for load testing

Apache Bench is a great load testing tool for web servers Here are the following steps 1. Install Apache Bench sudo aptitude install apache2-utils 2. Run Apache Bench The following line uses keepalive for 10,000 connections, at a concurrency of 100 and a timeout of 20 seconds. Be sure to end root domains with a slash. ab -k -n 10000 -c 100 -t 20 http://yourwebsite.com/

View logger output in rails console

First you need start the console and then assign rails logger it to use standard out. rails c >> Rails.logger = Logger.new(STDOUT) >> User.class_method_to_debug You can use similar approach to debug rake tasks etc. You can find more information here  Debugging rails applications

Asterix with arguments in Ruby

Lets create a method that accepts number of arguments def my_method(x, *y, **z) return x, y, z end Concept : x is a regular parameter. *y will take all the parameters passed after the first one and put them in an array. **z will take any parameter given in the format key: value at the end of the method call See the following examples: One parameter my_method(1) # => [1, [], {}] More than one parameter my_method(1, 2, 3, 4) # => [1, [2, 3, 4], {}] More than one parameter + hash-style parameters my_method(1, 2, 3, 4, a: 1, b: 2) # => [1, [2, 3, 4], {:a=>1, :b=>2}]

Date Localization and formatting

I18n.l is the easiest way to do it I18n.l(@user.created_at) And in case you want to use a different format : I18n.l(@user.created_at, :format => :short) You will find more documentation here