Klairvoyant infosolution's Blog

Forms in rails, different ways

john

1) Method 1

a) input.html.erb

<form action=”/look/at”>
<input type=”text” name=’text1′>
<input type=”checkbox” name=”checkbox1″>
<input type=”radio” name=”radio1″ value=”red”>Red
<input type=”radio” name=”radio1″ value=”green”>Green
<input type=”radio” name=”radio1″ value=”blue”>Blue
<select name=”select1″>
<option value=’green’/> Green
<option value=’Blue’/> Blue
<option value=’Red’/> Red
<option value=’Orange’/> Orange
</select>
<select name=”select2[]” multiple size=”3″>
<option value=’AC’/> AC
<option value=’Music system’/> Music Syatem
<option value=’Heater’/> Heater
<option value=’auto...

Read more

Amazon Product Advertising API Interface in Rails

john

1) In gem file add the following and bundle it.

gem ‘amazon_product’

2)

configure the request object in controller

a) req = AmazonProduct['us']

b)req.configure do |c|
c.key    = ‘YOURKEY’
c.secret = ‘YOURSECREAT’
c.tag    = ‘YOURTAG’
end

get your key,secret etc…  from

https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key

c) req << {
:operation    => ‘ItemSearch’,
:search_index => ‘All’,
:Keywords => ‘Book’,
:response_group => ['ItemAttributes','Images'],
:Version=> ‘2011-08-01′
}

3) get the results
@resp = req.get

code in view

<% @resp.each(‘Item’) do | item |%>
<%#*http://www.amazon.com/dp/<%= item['ASIN'] %>

<%g =item['MediumImage'].nil? %>

<% if g==false %>
<%item['MediumImage'].each  do | img|%>
<% if img[0]==”URL” %>
...

Read more

Paypal with rails-Using Active merchant

john

) gem install activemerchant

2) create two paypal test accounts 1)Business 2) personal

copy the following information which will be created while creating business account

API Username,API Password and Signature

location:- https://developer.paypal.com/

3) code the following in a ruby file ex “purchase.rb”

require “rubygems”
require “active_merchant”

ActiveMerchant::Billing::Base.mode=:test

gateway=ActiveMerchant::Billing::PaypalGateway.new(
:login=> “API username”,
:password=>”API Password”,
:signature=>”signature”
)
# here the credit card information of the personal test account

credit_card=ActiveMerchant::Billing::CreditCard.new(
:type=>”visa”,
:number=>”4582849457729927″,
:verification_value=>”000″,
:month=>01,
:year=>2013,
:first_name=>”John”,
:last_name=>”M V”
)
if credit_card.valid?
...

Read more

ERROR: Could not find a valid gem ‘1.2.3.’ (>= 0) in any repository

john

Install  as the following form

gem install rack –version=1.2.3.

where rack is the gem we want to install

 

Read more

activated rack ..., but your Gemfile requires rack ..... Consider using bundle exec. (Gem::LoadError)

john

When it says try using bundle exec… it means that you have to prefix the command with that

Example if  “cucumber features” display the error

“bundle exec cucumber features”

 

Read more

uu Decode function

john

function decode64(input) {

var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";

var output = "";

var chr1, chr2, chr3 = "";

var enc1, enc2, enc3, enc4 = "";

var i = 0;

// remove all characters that are not A-Z, a-z, 0-9, +, /, or =

var base64test = /[^A-Za-z0-9\+\/\=]/g;

if (base64test.exec(input)) {

alert("There were invalid base64 characters in the input text.\n" +

"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +

"Expect errors in decoding.");

}

input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

do {

enc1 = keyStr.indexOf(input.charAt(i++));

enc2 = keyStr.indexOf(input.charAt(i++));

enc3 = keyStr.indexOf(input.charAt(i++));

enc4 = keyStr.indexOf(input.charAt(i++));

chr1 = (enc1 << 2) | (enc2 >> 4);

chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);

chr3 = ((enc3 & 3) << 6) | enc4;

output = output + String.fromCharCode(chr1);

if (enc3 != 64) {

output = output + String.fromCharCode(chr2);

}

if...

Read more

Display TCX tracks using Google Maps API

john

This is the modified code which I fetch from the site

http://www.jacquet80.eu/blog/post/2011/02/Display-GPX-tracks-using-Google-Maps-API

The whole code

<!DOCTYPE html>

<!–

Demo put together by Christophe Jacquet in February 2011.
http://www.jacquet80.eu >

Use it and adapt it at your own will.

–>

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″/>
<title>Google Map with GPX track</title>
<style type=”text/css”>
html, body, #map_canvas { width: 100%; height: 100%; margin: 0; padding: 0 }
</style>
<script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false”></script&gt;
<script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js”></script&gt;
<script type=”text/javascript”>
function...

Read more

google map – useful sites

john
Read more

How to make kml files from google map

john

1)   Get the map in google map.
2)   Click the Link to this page link.
3)   Copy the email/IM link.
4)   Paste link back into your browser address bar.
5)   Add &output=kml to the end of the url & hit enter/go.
6)   Save the kml wherever you wish.

source
http://www.gringod.com/2008/02/26/save-google-maps-driving-directions/

Read more

Google Map tools

john

1) convert kml files 

http://kmltools.nobletech.com/csv2kml 

2) To prase kml files

http://econym.org.uk/gmap/egeoxml.htm

Read more

kml tools

john
Read more

Not able to center the google map after resize.

john

1) store location in a global variable var location =  new google.maps.LatLng(info.latitude, info.longitude); loc=location; here “loc” is a global variable

2) call setCenter function with “loc” variable as shown below

function resizeMap() {

google.maps.event.trigger(map,’resize’); map.setZoom( map.getZoom() ); map.setCenter(loc);

}

Read more

Google Map tools

john
Read more

responsive front-end framework

john

http://foundation.zurb.com/

http://getbootstrap.com/

Read more