Wednesday, May 9, 2012

Ruby: Get input from console

You can use the STDIN to get the input from console(shell/cmd/commandline).

to get a single character from the user.
chr = STDIN.getc

This is useful to implement something like "Press Enter to exit program." kind of things.

you can use gets, readline, etc with the STDIN.

FYI: for writing output to the screen, you need to use STDOUT.




Ruby: uploading image problem, getting Internal server error

There is one thing you need to remember while uploading image using Ruby. You have to read the file in binary mode. Otherwise for some server, you'll get Internal server error. I am giving you an example using the Ruby/Mechanize.

File.open(imgFile, "rb") do|binaryImage|
content = a.post('http://example.com/uploadImage.php',
{
:img => binaryImage,
:imgTitle => 'some title'
});
end

Here,
imgFile is the path to your image.
"rb" used inside file open for reading file as binary mode.




Ruby: OpenSSL::SSL::SSLError with Mechanize

Have you ever seen an error like below while playing with Ruby/Mechanize with HTTPS links?


`connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)


The simple solution to overcome this error by setting SSL verification is false. You can do this like this way with your mechanize agent


a.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE




Saturday, May 5, 2012

How to install Ruby Mechanize?

To install the ruby mechanize gem, you can use the gem of ruby. the command is like below.

gem install mechanize
 
this works for windows, linux, whatever you use. 




Tuesday, May 1, 2012

how to escaping the URL for the Japanese characters

how to escaping the URL for the Japanese characters? I found a simple way to bypass this problem when i was using shift_jis. example:



$japanese_chars = "チタン";
$encoded_japanese_chars = uri_escape(encode('shiftjis', $japanese_chars));
my $url = "http://www.example.com?param=$encoded_japanese_chars";




Friday, April 20, 2012

Making transparent desktop icon for text.

Not sure why, but suddenly i found my desktop icon changed from transparent to black. Tried with several methods from internet forums, but nothing worked. Finally the below solution worked for me. I just coppiced from a forum to here at my blog.


Step1: Right click My Computer and choose Properties. Go to Advanced Tab and click
on Settings button under Performance frame and deselect the Use drop shadows for
icon labels on the desktop checkbox and then click OK two times.

Step 2: Start -> Run -> gpedit.msc

Step 3: Go to User Configuration -> Administrative Templates -> Windows Components
-> Windows Explorer. Double click on Turn on Classic Shell and select Enabled option.
Click Apply and OK. Close the Policy Editor.

Step 4: Follow the Step 1 but select the checkbox and click OK.

Step 5: Now go to Desktop to enjoy the Drop-Shadow effect.

Thats it :-)




Sunday, April 8, 2012

How to identify the penny pinching buyers

There are several common dialogs available for the cheap buyers who don't like to pay but want to make you work hard. They don't know how to respect a freelancers. Here are few tips which will help you to identify those idiots.

1) when you'll see a common dialog "those who knows what they are doing...". for a massive difficult work, still they are uttering this fucking bullshit.

2) when you'll see another common dialog "its a busy task, but right now i am busy and want to hire a coder". another fucking bullshit. they are saying this for not paying much, nothing else.

3) a project having highlighted "lowest bid will be the winner". just ignore the project. let him hire the cheapest freelancer. they don't look for quality, so they don't give you respect for your work.

4) china, india, pakistan, romania, when these are the country of the buyer, just kick those assholes. they are middleman, and won't pay much.

that's it so far. make your steps clear before bidding on a project.