Thursday, July 31, 2014

Using YQL servers as proxy to load resources cross domain

To load a HTML5 file from another domain use this query.

select * from html where url="https://www.yahoo.com/" and compat="html5" and xpath='*'

This will return the whole HTML page in the results tag of the generated XML. If you want to use JSONP just add a "callback=[funcName]" query parameter in the end and instead of an XML a JSON will be sent out. Here is an example of how it will be sent out. I am using callback function as "test". Depending on which framework or library you are using you will need to set it accordingly.

Also the YQL servers support CORS so it won't be that difficult if you do a direct XHR to get the file instead of using script tags for JSONP. I also tested it using text files and they can also be downloaded using this method.

If you want other types of resources which are less than 25KB you can use another YQL query to get the results.

select * from data.uri where url="http://l.yimg.com/a/i/us/pps/yql32.png"

This only works for resources which are less than 25KB. But here it could be an image or any other resource and it will work.

Tuesday, September 24, 2013

Using CONNECT method on a http proxy using telnet

The simplest way to connect to an external server using a proxyserver.

C:\Work>telnet proxyserver 8080
Trying 192.168.1.20...
Connected to proxyserver.
Escape character is '^]'.
CONNECT irc.freenode.org:6667 HTTP/1.1

HTTP/1.1 200 Connection established

:kornbluth.freenode.net NOTICE * :*** Looking up your hostname...
:kornbluth.freenode.net NOTICE * :*** Checking Ident
:kornbluth.freenode.net NOTICE * :*** Found your hostname
:kornbluth.freenode.net NOTICE * :*** No Ident response

In this case we are connecting to a proxyserver on port 8080. After that we open a http tunnel to irc.freenode.org on port 6667. Then you need to press enter twice to establish the connection. After that you have an open socket and you can send the commands accordingly based on the protocol being used. Here we connect to an IRC server.

We could do the same thing by connecting to a HTTP server. You can apply the logic by opening a socket to the proxy server and then sending and receiving over the socket if you are doing socket programming. The only extra things you need to take care is to open the tunnel the rest of the logic remains the same.
 
C:\Work>telnet proxyserver 8080
Trying 192.168.1.20...
Connected to proxyserver.
Escape character is '^]'.
CONNECT www.google.com:80 HTTP/1.0

HTTP/1.1 200 Connection established

GET / HTTP/1.0

HTTP/1.0 200 OK
Date: Tue, 24 Sep 2013 08:34:43 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: [a dozen cookies]
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic
.
.
.

Friday, May 10, 2013

The best tool for clipping backgrounds

Been using this amazing tool to clip backgrounds which otherwise is a real pain to do in most other software.

Really like the simplicity of the application. Visit  http://clippingmagic.com to see it in action. Only 4 steps after that.


  1. Upload photo
  2. Select background
  3. Select object to extract 
  4. Wait for magic and you are done.