Tuesday 21 April 2015

Use .wgetrc for default wget settings.

I use wget quite a lot and in the end I always end up using a large number of common options like

-c (to continue/resume a wget process)
--no-check-certificate (ignore ssl certificate check over https)

which eventually make it look very ugly but thanks to .wgetrc I no longer has to do it.

Create a .wgetrc file onto your home directory

JFI, Here how my current .wgetrc look.

continue=on     ## equivalent to -c options
check_certificate=off  ## equivalent to --no-check-certificate

Noting it down here so I just don't forget it future.

Thanks








Friday 10 April 2015

Using HTTPProxy in Net/HTTP globally.

There comes a time when you want to Proxy your Net/HTTP request/response in Ruby.

One of the easy ways to do this in NET/HTTP is by passing proxy parameters in '.new'  method (during initialization)

proxy_addr = 'your.proxy.host'
proxy_port = 8080

Net::HTTP.new('example.com', nil, proxy_addr, proxy_port).start { |http|
  # always proxy via your.proxy.addr:8080
}

Obviously, this works but then querying the website using GET or GET BY URI method there is no provision to pass any proxy parameters altogether(at least that's what I found out.)

Thankfully Ruby-2.0+ (not available in lower versions though, can be seen over here) has a feature with which you can provide proxy as your ENV variable (http_proxy environment variable) and ruby take care of the rest.

So, upon setting  http_proxy in ENV I found, BAAM!!!  it worked and it worked globally (i.e it works even on GET and GET BY URL methods mentioned above.)

BTW, I had the following declaration inside my .bash_profile.


export http_proxy= 'http://127.0.0.1:8080'  (8080 is the port where my Squid Proxy is functional)


Thanks




What did I learn today?

Welcome to the what did I learn today series. The intention of this blog spot is to compose the stuff that I learnt day-to-day basics and jo...