2010
05.25

Here is a quick reference to default in-built formatting options available in Ruby on Rails:

If you need anymore formatting support, then strftime is your friend. Since the examples listed above are realized using the same strftime method.

2010
05.24

Here is a short quick tutorial that can help you setup your Apache to sever application through Passenger, instead of Mongrel Cluster. You need the following (Both come with superb installers, that you can easily follow):

  • Install Ruby Enterprise Edition (Optional) (Recommended)
  • Install Phusion Passenger

Once you have gone through the steps listed here, you will prompted to configure Apache through config files. Here is what you need to do:

  1. Enable the mod_rails module:

    LoadModule passenger_module /path/to/passenger/module/mod_passenger.so
    PassengerRoot /path/to/passenger/source/root/passenger-2.2.11
    PassengerRuby /path/to/ruby/executable/generally/ree/ruby

    In my case (since I use RVM):

    LoadModule passenger_module /Users/swanand/.rvm/gems/ree-1.8.7-2010.01/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
    PassengerRoot /Users/swanand/.rvm/gems/ree-1.8.7-2010.01/gems/passenger-2.2.11
    PassengerRuby /Users/swanand/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby
  2. Create a virtual server for your application (Recommended way)
    Find your Apache configuration file. Commonly known locations:

    • (Fedora & Redhat based OS) /etc/httpd/conf.d/httpd.conf
    • (Mac OS X) /etc/apache2/httpd.conf
    • (Ubuntu and Debian based OS) /etc/apache2/apache2.conf

    In this file, find the line that includes other conf files. Something like:

    Include /private/etc/apache2/other/*.conf

    Now, create a file in this /private/etc/apache2/other/, name it application_name.conf

    Following are the contents of this file:

    Update the /somewhere according to your project path.

2010
05.23

iPhone: How to set a custom background for the navigation bar

By Satish Natarajan

Just add this section to the top of your app delegate

@implementation UINavigationBar(MyCustomBackground)
- (void)drawRect:(CGRect)r
{
[[UIImage imageNamed:@"header.png"] drawInRect:self.bounds];
}
@end

2010
05.20

iPhone: How to set a custom image for a navigation bar button

By Satish Natarajan

UIButton *simpleButton = [[UIButton alloc] init];
UIImage *buttomImage = [UIImage imageNamed:@"button.png"];
[simpleButton setImage: buttomImage forState:UIControlStateNormal];
simpleButton.frame = CGRectMake(0, 0, buttomImage.size.width, buttomImage.size.height);
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:simpleButton];

2010
05.19

package com.kaveri.sample.opengl;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;

public class VortexRenderer implements GLSurfaceView.Renderer {

private float _red = 0f;
private float _green = 0f;
private float _blue = 0f;

// a raw buffer to hold indices allowing a reuse of points.
private ShortBuffer _indexBuffer;

// a raw buffer to hold the vertices
private FloatBuffer _vertexBuffer0;
private FloatBuffer _vertexBuffer1;
private FloatBuffer _vertexBuffer2;
private FloatBuffer _vertexBuffer3;
private FloatBuffer _vertexBuffer4;

private short[] _indicesArray = {0, 1, 2, 3, 4};

private float[] _verticesArray0 = {
0f, 0f, 0f,
0.1f, 0f, 0f,
0.1f, 0.1f, 0f,
0f, 0.1f, 0f
};

private float[] _verticesArray1 = {
0f, 0f, 0f,
0.2f, 0f, 0f,
0.2f, 0.2f, 0f,
0f, 0.2f, 0f
};
private float[] _verticesArray2 = {
0f, 0f, 0f,
0.3f, 0f, 0f,
0.3f, 0.3f, 0f,
0f, 0.3f, 0f
};
private float[] _verticesArray3 = {
0f, 0f, 0f,
0.4f, 0f, 0f,
0.4f, 0.4f, 0f,
0f, 0.4f, 0f
};
private float[] _verticesArray4 = {
0f, 0f, 0f,
0.5f, 0f, 0f,
0.5f, 0.5f, 0f,
0f, 0.5f, 0f
};

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// preparation
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
initTriangle();
}

@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}

@Override
public void onDrawFrame(GL10 gl) {
// define the color we want to be displayed as the “clipping wall”
gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
// clear the color buffer to show the ClearColor we called above…
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

gl.glLineWidth(2f);

gl.glColor4f(_red, _green, _blue, 0f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer0);
gl.glDrawElements(GL10.GL_LINE_LOOP, 4 , GL10.GL_UNSIGNED_SHORT, _indexBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer1);
gl.glDrawElements(GL10.GL_LINE_LOOP, 4 , GL10.GL_UNSIGNED_SHORT, _indexBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer2);
gl.glDrawElements(GL10.GL_LINE_LOOP, 4 , GL10.GL_UNSIGNED_SHORT, _indexBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer3);
gl.glDrawElements(GL10.GL_LINE_LOOP, 4 , GL10.GL_UNSIGNED_SHORT, _indexBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer4);
gl.glDrawElements(GL10.GL_LINE_LOOP, 4 , GL10.GL_UNSIGNED_SHORT, _indexBuffer);
}
protected static FloatBuffer makeFloatBuffer(float[] arr)
{
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(arr);
fb.position(0);
return fb;
}

protected static ShortBuffer makeShortBuffer(short[] arr)
{
ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 2);
bb.order(ByteOrder.nativeOrder());
ShortBuffer sb = bb.asShortBuffer();
sb.put(arr);
sb.position(0);
return sb;
}

private void initTriangle() {

_vertexBuffer0 = makeFloatBuffer(_verticesArray0);
_vertexBuffer1 = makeFloatBuffer(_verticesArray1);
_vertexBuffer2 = makeFloatBuffer(_verticesArray2);
_vertexBuffer3 = makeFloatBuffer(_verticesArray3);
_vertexBuffer4 = makeFloatBuffer(_verticesArray4);
_indexBuffer = makeShortBuffer(_indicesArray);
}

public void setColor(float r, float g, float b) {
_red = r;
_green = g;
_blue = b;
}
}

2010
05.14

iPhone/iPad: How to set TextView Font Size

By Satish Natarajan

myTextView.font = [UIFont fontWithName:@"Arial" size:12];

2010
04.26

The following code lists out the duplicate elements of any Array:

2010
04.24

OAuth is a simple and secure way to authorize the user on behalf of another application where user is already registered.

OAuth include communication between two applications – consumer application, the application which uses OAuth authorization; service provider application, application who provides OAuth service. Using OAuth we can have access to the protected data of user from the service provider application. So first step towards implementing OAuth is to register with the OAuth service provider and get the token  key and secret key.

How OAuth authorization works,

  1. The consumer application sends a request to the OAuth service provider for a ‘request token’ with parameters as ‘token key’ and ’secret key’.
  2. Once we have ‘request token’, we request the user for Approval from service provider application. Basically this happens with a redirect of user to the service provider application’s login page, with the ‘request token’ as parameter.
  3. If the user is approved, the service provider application makes a callback to the consumer application with ‘authorized key’.
  4. Once we have ‘authorized key’, we can request the service provider for ‘access token’.

Nice, now the user is authorized using the service provider application.

Reference: http://hueniverse.com/oauth/

2010
04.07

When you are using NSLog(string_variable) – you will get an error format not a string literal.

eg:
NSString *message = @”My message is 100% “;
NSLog(message);

To avoid the warning – which is infact correct andmisbehaving of the NSLog statement by dynamic string with characters like % etc. It is better to write the NSLog statements as follows

NSLog(@”%@”, message);

2010
03.31

smtp_tls comes along with ruby 1.8.7and works fine

but you need to tweek a little to get it working

here are the steps

edit line 33 of vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb

#check_auth_args user, secret, authtype if user or secret
if RUBY_VERSION > "1.8.6"
  check_auth_args user, secret # for rails 1.8.7
else
  check_auth_args user, secret, authtype if user or secret # for rails 1.8.6
end

read more : http://blog.inspired.no/smtp-error-while-using-gmail-in-rails-271