スキップしてメイン コンテンツに移動

投稿

Get Original Hi-res image from Zoomable image on Amazon

Some pages in amazon provide images which user can zoom on, like this page. The question is "Where is the original hi-resolution image?". You can easily find the explanation page for how to construct url for original hi-res image. (See this stack overflow page .) In this post I will show you the code snippet for getting original hires imgae from ASIN code. Note!: This method might be unavailable if amazon change the implementation of zoom and hires image url construnction. Code Actually code is nothing special. Just find " DynAPI.addZoomViewer( " . // pattern for extracting image code used for retrieving original image. private static Pattern AMAZON_ZOOM_IMAGE_PATTERN = Pattern.compile("DynAPI\\.addZoomViewer\\(\".+/(.+?)\",\\s*(.+?),\\s*(.+?),\\s*(.+?),\\s*(.+?),\\s*(.+?),.*\\)"); public static String findOriginalZoomImageUrl(String asin, String country) { String url = getAmazonZoomImageWindowUrl(asin, country); try{

Build Get Parameter String from Javascript Object or Map

This is just a quick tips... I think you can easily understand whole thing from the code below. // example data used for get parameters. You can use plain javascript object if you want. var map = ["name1":"value1", "name2":"value2"]; // Ok, let’s build string... var parameters = []; for(var prop in map) { // if the name part (prop) contains the characters to uri encode, // use encodeURIComponent as well for the name part. parameters.push(prop + "=" + encodeURIComponent(map[prop])); } var parametersStr = parameters.join("&");

How to pick up Hi-Resolution Image from Amazon product page

Recently I realized that Amazon offers high resolution photos in some products. I have found the way to extract these hires images. Note Note!: This method might be unavailable in the future because Amazon may not like this kind of hack or change the implementation :P Basic Strategy For example, this page: http://www.amazon.com/Silver-Violin-Nicola-Benedetti/dp/B008CYV046/ If you see the html source of this page, you can find the following json string. var colorImages = {"initial":[{"large":"http://ecx.images-amazon.com/images/I/XXXXXXX.jpg",.... It represents the urls of various size of images. If you would like to see the hi-resolution image, you should pick up the url which is defined in hiRes property. Source Code You know I still like Java, I will show you the simple Java code. I use Jackson for parsing JSon string. import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; imp

Java: How to Set Proxy on HttpURLConnection

If you need to set proxy address on Java HttpURLConnection. Do something like below. public static String getString(String urlStr) throws Exception { HttpURLConnection connection = null; InputStream is = null; try { URI uri = new URI(urlStr); // settin proxy String proxyHost = ""; // your proxy serever address int proxyPort = 8080; // your proxy port Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); // open connection with passing Proxy Object connection = (HttpURLConnection)uri.toURL().openConnection(proxy); connection.connect(); is = connection.getInputStream(); String content = toString(is); return content; } finally{ closeQuietly(is); if(connection != null) { connection.disconnect(); } } } private static String toString(InputStream is) throws IOException { byt

Restrict Html Tags which User Can Input (PHP)

I tried to implement very simple html edit text area which has available tags user can input are restricted. So I needed to implement a validator which detects tags not allowed to use. The proper (but a bit heavy) implementation approach is using Tidy . It can validate entire html and also fix and clean up html source! However in my case using tidy is a bit overkill solution. Instead of using tidy, I decided to use strip_tags function. The disadvantage is that the function does not validate html syntax. e.g. inaccurate than using tidy.- "strip_tags function does not actually validate the html, partial or broken tags can result in the removal of more text/data than expected." as the official PHP document says. Okie, as long as we understand the disadvantage, we can use this function. Let's show you the code. function validateOnlyAllowedTags($html, $tags) { $stripped = strip_tags($html, $tags); // if no tags are stripped, the length of html contents

Creating SVN Tag in Bash

In this post, I will show you an example bash script for creating svn tag. First, if you would like to create tag on svn, you simply execute the following command. svn copy 'source_url' 'tag_url' Okay then, we simply call the above command in bash script. I use revision number and time stamp as tag name. Instead of using revision number, maybe you can prepare version number file and count up it when creating tag. #!/bin/bash SVN_USERNAME=dukesoftware SVN_PASSWORD=some_password SVN_INFO_COMMAND="svn info --username $SVN_USERNAME --password $SVN_PASSWORD --non-interactive" SVN_COPY_COMMAND="svn copy --username $SVN_USERNAME --password $SVN_PASSWORD --non-interactive" svn_project_trunk="http://somewhere.svn/project/trunk" svn_project_base=${svn_project_trunk/trunk/} # Getting revision from svn info command # Need this line for displaying message of svn info command in English forcibly. export LC_MESSAGES=C revision=`$SVN_INFO_CO