shared items

Monday, December 28, 2009

warbler

http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html

Thursday, November 12, 2009

Removing Stale Rails Sessions

Source : http://www.realityforge.org/articles/2006/03/01/removing-stale-rails-sessions

CGI::Session::ActiveRecordStore

if you upgrade to Rails 2.3, the session management has
changed significantly, per the release notes:

CGI::Session::CookieStore has been replaced by ActionController::Session::CookieStore.
CGI::Session::MemCacheStore has been replaced by ActionController::Session::MemCacheStore.
CGI::Session::ActiveRecordStore has been replaced by ActiveRecord::SessionStore.

soap4r + rails + uninitialized constant error

http://rubyglasses.blogspot.com/2008/10/soap4r-rails-cant-find.html

Will_paginate + ajax

Good tutorial found at http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links

Friday, October 30, 2009

Google charts ( Charts, Maps, ...)

The Google Chart API lets you dynamically generate charts. To see the Chart API in action, open up a browser window and copy the following URL into the address bar: http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
Press the Enter or Return key and - presto! - you should see the following image:
Yellow pie chart

http://code.google.com/apis/chart/

Friday, October 23, 2009

Win32::Service::Error: Access is denied.

Win32 access denied

Rob Stiff
Tue, 19 Aug 2008 07:27:31 -0700

Rob Stiff wrote:
> Using the Win32 HOWTO information, I am attempting to start the service.
> upon the service::install command, I receiving the error 'Access is
> denied. (Win32::ServiceError).
>
> The error is occurring in line 146 of init.rb
>
> Version Information:
> Ruby 1.8.6
> Rails 1.2.0
> Gem 1.2.0
> Win32-Service 0.5.2
> Mongrel_service 0.3.4
> OS - Windows Vista
>
> There is a newer version of Win32 available (0.6.1), but this version is
> incompatible with mongrel_service and issues a version error.
>
> Thanks in advance!

SOLVED.
The issue was with Windows Vista. You must always run the command line
by right-clicking and using the "Run as Administrator" option.

Wednesday, October 21, 2009

classic pagination in Rails

Action Pack pagination for Active Record collections

DEPRECATION WARNING: Pagination will be moved to a plugin in Rails 2.0. Install the classic_pagination plugin for forward compatibility:

script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination

The Pagination module aids in the process of paging large collections of Active Record objects. It offers macro-style automatic fetching of your model for multiple views, or explicit fetching for single actions. And if the magic isn‘t flexible enough for your needs, you can create your own paginators with a minimal amount of code.

The Pagination module can handle as much or as little as you wish. In the controller, have it automatically query your model for pagination; or, if you prefer, create Paginator objects yourself.

Pagination is included automatically for all controllers.

For help rendering pagination links, see ActionView::Helpers::PaginationHelper.
Automatic pagination for every action in a controller

class PersonController < ApplicationController
model :person

paginate :people, :order => 'last_name, first_name',
:per_page => 20

# ...
end


Source : http://api.rubyonrails.org/classes/ActionController/Pagination.html

reverse_proxy

Install via Subversion using the Ruby script/plugin install command. In the root of your Rails application structure
(where you can see the app/ vendor/ and public/ folders)
execute the following command:

ruby script/plugin install http://svn.napcsweb.com/public/reverse_proxy_fix

You will be prompted by the script to specify the version of Rails you're using. Select
the version that best matches your version of Rails and press the Enter key.
You should be prompted to enter the base url of your front-end server when you install
the plugin via script/plugin install. You should not include the trailing slash! For
example:

http://www.mydomain.com/typo

If that doesn't work for some reason, you can run the install.rb script in

vendor/plugins/reverse_proxy_fix

Or you can manually edit the file lib/config.rb and uncomment the BASE_URL line. (It should be the only line in the file. Enter the desired base url
that you would like the plugin to prepend to any generated URLs.


Source : http://www.napcsweb.com/rdoc/reverse_proxy_fix/index.html

Sunday, October 18, 2009

View Your Google Calendar in Outlook 2007

Google Calendar is a phenomenal web application for managing your calendars, but so many of us are still forced to use Outlook at work. The good thing is you can have the best of both worlds by subscribing to your Google Calendar from Outlook.

The first thing you’ll have to do is get your Google Calendar iCal link. Just open your Google Calendar and go to Settings \ Calendar.

Pick the calendar you want to sync with Outlook. Now in the Private Address field click on the ICAL button. This will show you your private Calendar address. Copy this address to the clipboard.

Thursday, October 8, 2009

Installing Ruby 1.8.7 (and other stuff) manually

1. Download the windows binaries for Ruby 1.8.7 here: http://www.ruby-lang.org/en/downloads/ extract that to wherever you would like, I use c:\ruby. Then put c:\ruby\bin in your PATH environment variable.
2. Download the zlib package: http://www.zlib.net/zlib123-dll.zip and extract the zlib1.dll, rename it to zlib.dll and move it into your Windows\System32.
3. Download the iconv package: http://sourceforge.net/project/showfiles.php?group_id=25167&package_id=51458. Find and extract the iconv.dll into your Windows\System32.
4. Download the rubygems package and follow the instructions, basically extracting the package and running ruby setup.rb
5. Verify that everything works properly by trying a gem install rails, once that installs then do: rails test_project



http://stackoverflow.com/questions/390897/installing-ruby-1-8-7-and-other-stuff-manually

Ruby 1.8 missing lib ( SSLEAY.dll , ZLIB.dll)

Update: There is a new effort to create a decent Windows Ruby installer. You can get the new downloadable installers from http://rubyinstaller.org/downloads/ though as of August 2009 these are still in preview form. It seems from my brief experiment that you'll still have to set your PATH manually, as per my manual instructions below. This installer also promises a faster Ruby as it builds using superior tools, so might well be worthwhile if only for that. Below are my original manual instructions for installing Ruby on Windows, which should still be just as valid as they always were. The installer is probably worth a look though.

The following worked for me on Windows XP, but maybe I'm yet to run into problems I don't know I've got:

* Download the Windows binary release from http://www.ruby-lang.org/en/downloads/
* Unzip it, in my case to C:\ruby191\
* Also download readline.dll (e.g. from http://www.econsultant.com/dll-database-r/readline.dll-download.html) and put the DLL in C:\ruby191\bin
* Put C:\ruby191\bin and C:\ruby191\lib on your PATH

That got ruby working in a basic sense for me, but I wasn't able to install gems. If I tried, I got two errors in sequence: "The ordinal 277 could not be located in the dynamic link library SSLEAY32.dll" and "This application has failed to start because zlib.dll was not found."


The ssleay32.dll problem was solved by getting hold of a couple of DLLs and putting them in the right place, as follows:

* Download "Win32 OpenSSL v0.9.8k Light" from http://www.slproweb.com/products/Win32OpenSSL.html.
* Run the installer, but take note of the following:
* You can ignore any initial warning about not having Microsoft Visual C++ 2008 Redistributables.
* You can ignore any warnings about command prompts being open.
* Install to somewhere like C:\OpenSSL - it doesn't really matter, we just need a couple of DLLs.
* When prompted, choose to Copy OpenSSL DLLS to The OpenSSL binaries (/bin) directory.
* Once the installer has completed, you can go to C:\OpenSSL\bin (or wherever you installed it) and copy the two files ssleay32.dll and libeay32.dll to your Ruby bin directory, C:\ruby191\bin in my case.

The zlib.dll problem was solved by in much the same way:

* Download the compiled zlib 1.2.3 DLL from http://www.zlib.net/ (about two thirds of the way down the page).
* Unzip it to get the zlib1.dll file.
* Put that file in your Ruby bin directory, but rename it to zlib.dll

Et voila - gems can now be installed successfully! Note that you may have had copies of some of these DLLs in your \WINDOWS\system32 directory already (I certainly did) but the problem is that they are too old. I prefer to put the newer ones directly in the Ruby bin directory, so only Ruby picks them up and it can't break anything else on the system.

http://alwaysthecritic.typepad.com/atc/2009/03/install-ruby-191-on-windows.html

Thursday, August 27, 2009

Ext Js Tutorial

http://extjs.com/learn/Tutorial:Introduction_to_Ext_2.0

Thursday, August 6, 2009

Rails 2.3 and Mysql 5.1

The title says it all. I wish Ruby on Rails wasn’t so difficult to get set up on Windows. It sounds like most Ruby on Rails developers are Mac OS X or Linux users.

I was just trying to get a basic app set up with MySQL 5.1, Rails 2.3 and Ruby 1.8.6 and got this error when trying to run rake db:migrate:

rake aborted!
undefined method `each’ for #

I found an answer here:

http://www.nabble.com/rake-aborted!-undefined-method-%60each%27-for–%3CMysql:-td20760472.html

Looks like most people uninstalled MySQL 5.1 and went back to 5.0. People also seemed to have better luck with Postgresql.

Source : http://peterskim.org/2009/04/12/mysql-51-with-rails-23ruby-186-on-windows-doesnt-work/

Also Comments :
I’m running MYSQL 5.1 and had a similar problem. I have Ruby 1.8.6. I followed these instructions and the undefined method error was resolved when running rake.
> The problem is that libmysql.dll shipped with Mysql doesn’t play well
> with ruby 2.2..
>
> The solution is to download the libmysql.dll from:
>
> http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

Tuesday, July 28, 2009

Date Time format for Rails Ruby

------------------------------------------------------------------ Time#strftime
time.strftime( string ) => string
---------------------------------------------------------------------------------
Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string.

"
Format meaning:

%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character

t = Time.now
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003"
t.strftime("at %I:%M%p") #=> "at 08:56AM"
"

Sunday, May 31, 2009

magicjack and Win xp issues

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E965-E325-11 CE-BFC1-08002BE10318

Hopefully these simple directions will help those who are not master computer techs like me:) God knows I couldn't get it right to save my life! But a light bulb went off in my head and this is how I did it. Almost embarassing to mention;

When looking for this file in device manager please consider the following Steps:

To resolve this problem, remove the affected filter drivers. To do this, follow these steps:

1. Click Start, type regedit in the Start Search box, and then click regedit in the Programs list.

If you are prompted for an administrator password or confirmation, type your password, or click Continue.

2. Locate, and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}

ie., 1. Go to HKEY_LOCAL_MACHINE and click on it.
2. part of the sub directory will appear
3. then click on SYSTEM
4. You will then see Current Control Set click on it
5. And so on......get the picture now!
Whew! Now follow the rest of the directions and you should have any additional problems


Caution There can be many instances of the registry subkey that is mentioned in step 2. You must make sure that you are in the appropriate registry subkey before modifying the UpperFilters and the LowerFilters values. To verify that you are in the appropriate registry subkey, make sure that the Default data value is DVD/CD-ROM and the Class data value is CDROM.

3. In the right pane, right-click UpperFilters, and then click Delete.

4. Click Yes to confirm the removal of the UpperFilters registry entry.

5. In the right pane, right-click LowerFilters, and then click Delete.

6. Click Yes to confirm the removal of the LowerFilters registry entry.

7. Exit Registry Editor, and then restart the computer.

Source : http://forums.cnet.com/5208-12546_102-0.html?threadID=241915&start=45&tag=forum-w;forums06

Wednesday, May 20, 2009

load files in jar

If you use a filename, then the filename has to refer to a real file. But if you use a "resource name," that resource might be a file or it might be a component of a JAR (or theoretically something else altogether.)
The magic method(s) in this case are the family of loadResource() methods. For example, Class.getResource().
If youve got a class foo/bar/Test.class inside a JAR file, and also a foo/bar/Image.jpg, then inside the Test class you can refer to Image.jpg using
URL theURL = getClass().getResource("Image.jpg");
and then pass the URL to ImageIcon's constructor for example.
Source : http://www.coderanch.com/t/276412/Streams/java/Load-file-inside-JAR

Monday, May 11, 2009

Inflater Deflater

public class Inflater
extends Object
This class provides support for general purpose decompression using popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.

The following code fragment demonstrates a trivial compression and decompression of a string using Deflater and Inflater.

// Encode a String into bytes
String inputString = "blahblahblah??";
byte[] input = inputString.getBytes("UTF-8");

// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);

// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0, compressedDataLength);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();

// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");

Sunday, May 10, 2009

each_hash error with Rails 2.2 and mysql 5.1

Rails 2.2 MySQL removed error SOLUTION
by protech_v2 » Mon Dec 15, 2008 8:04 pm

If at any point when you've upgraded to Rails 2.2. you get the following error on Windows:

"!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql."

the problem is because MySQL 5.1 client library doesn't play well with Rails - the solution is simple however:

- download older MySQL client library, for example one from InstantRails: http://instantrails.rubyforge.org/svn/t ... bmySQL.dll

- copy the downloaded file to C:\Ruby\bin (or wherever you installed Ruby)

- restart MySQL server

That's it! Just thought I'd share this with others, lost me an hour of researching.

Good luck!

REF

Internet Explorer Inner HTML

Reference : http://muffinresearch.co.uk/archives/2006/07/19/bug-when-creating-select-options-using-innerhtml-in-ie/


function helo()
{
var a = document.getElementById('targetDiv');
opt = document.createElement("option");
opt_txt = document.createTextNode("aaaa");
opt.appendChild(opt_txt);
opt.setAttribute("value", "bbbbb"); a.appendChild(opt);
}

< onclick="helo();">Using JavaScript functions
< id="targetDiv" size="5">
< id="'a'">hh< / option >
< / select >

small textbox in IE 8.0

◦In IE8 click “Tools” | “Internet Options” | and choose the “Advanced” tab.
◦Scroll down one full scrolls worth and uncheck the “Enable visual styles on buttons and controls in webpages“
◦Click “OK” - it will take a few seconds, then your browser should display correctly. You should not have to close/reopen the browser for the change to take effect.


http://www.ejabs.com/2009/03/fix-tiny-forms-in-ie8/

Sunday, May 3, 2009

What you do is create a select tag with the “select” method like so: (using the client/project scenario)

f.select(:client_id,

The next value you pass to the select method has to be an array of text/value pairs

like this: [ [ "Jason Johnson", 1], ["Trey Piepmeier", 2], ["Royall", 3] ]

In order to create this array, you do a find on your clients table and use Ruby’s “collect” method.

like so:

Client.find(:all).collect {|c| [ c.name, c.id ]}

So, altogether now:

f.select(:client_id, Client.find(:all).collect {|c| [ c.name, c.id ] })

Reference

Saturday, May 2, 2009

JAXB ignores "@required" fields in validation

Reference Links :

http://www.cowtowncoder.com/blog/archives/cat_java.html
http://kirkwylie.blogspot.com/2008/10/jaxb-2x-and-xmlelementrequiredtrue.html
http://www.nabble.com/JAXB-ingores-@XmlElement(required%3Dtrue)-on-unmarshalling-in-JAX-RS-td22122276.html
http://myarch.com/using-schema-validation-with-jaxb-and-xfire
https://jaxb.dev.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.html

Thursday, April 9, 2009

WSDL2ruby

1. Download soap4r from SVN.
svn co http://dev.ctor.org/svn/soap4r/trunk/bin soap4r
This will result in two files being downloaded - wsdl2ruby.rb and
xsd2ruby.rb. The one I used was the wsdl2ruby.rb.
2. Generate sample SOAP client file
ruby wsdl2ruby.rb --wsdl http://location_of_WSDL --type client
This will result in the creation of three files - default.rb,
defaultDriver.rb and WSClient.rb. The sample client file is
WSClient.rb. Inside this file, I found all the remote methods and "nil"
arguments being passed to them. For e.g., I had a remote method defined
as follows in my web-service:
string observe (string req_id, string[] names, string[] values);
The second and third argument for this file were vectors of strings.
In the ruby client file, this method was exposed as follows:
obj = WSSoap.new(nil)
parameters = nil
puts obj.observe(parameters)
So, even though my remote method should have three arguments, here
there is only one. According to nahi's email, I needed to construct a
hash table and pass that as the single argument.
3. Pass actual arguments.
name = ['CENTER', 'SPAN', 'SCALE', 'YREF', 'INTERVAL']
val = ['5.18 GHz', '2.95 MHz', '4.00', '-68.70', '30000']
parameters = {
'req_id' => '1',
'names' => {:string => name},
'values' => {:string => val}
}

result = obj.observe(parameters)
puts result.inspect

UUID Ruby link

http://wiki.github.com/assaf/uuid

ruby UUID installation

gem install UUID
create ENVironment variable "HOME" in windows. Set it to any Directory.

require 'UUID'

p UUID.generate

Wednesday, March 18, 2009

DOM to BLOB to DOM


private void test1() throws ParserConfigurationException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(5120);
DocumentBuilderFactory doc1 = DocumentBuilderFactory.newInstance();
DocumentBuilder doc2 = doc1.newDocumentBuilder();
Document doc = doc2.newDocument();
org.w3c.dom.Element elem1 = doc.createElement("name1");
doc.appendChild(elem1);
org.w3c.dom.Node node = doc.getFirstChild();
TransformerFactory tfact = TransformerFactory.newInstance();
try {
Transformer tf = tfact.newTransformer();
StringWriter sw = new StringWriter();
Result rs = new StreamResult(sw);
Source src = new DOMSource(node);
tf.transform(src, rs);
baos.write(sw.toString().getBytes());
Object a = baos.toByteArray();
baos.flush();
baos.reset();
baos.close();

sw.close();
System.err.println(sw.toString());
System.err.println(a.toString());
String n = new String((byte[])a);
try {
Document doc12 = doc2.parse(new InputSource(new StringReader(n)));
System.err.println(doc12.toString());
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.err.println("........."+n);

} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}