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

投稿

Create Stack Trace String from Java Exception

Maybe many times you would like to generate stack trace string from Exception thrown. The code below will help you! public final static String createStackTraceString(Exception e){ StringWriter sw = new StringWriter(); PrintWriter writer = new PrintWriter(sw, false); e.printStackTrace(writer); return sw.toString(); }

File Clean Up and Archiving Linux Command Tips

If you would like to delete files whose name ends with "batch.log" older than 30 days, Use the following command. find /var/log/ -name "*batch.log" -mtime +30 -type -f -delete If you would like to archive files whose name ends with "batch.log" older than 30 days, Use the following command. The archived file will have timestamp at the end of the filename. find /var/log/ -name "*batch.log" -mtime +30 -type -f -pront0 | tar -czvf /var/log/batch.log.tar.gz.`date +\%Y%m%d%H%M%S` -T - --null --remove-files

Solve Local Capistrano Deployment Issue

Local Capistrano Deployment Issue I have an inssue when deploying PHP application on "local" machine (e.g. deploying app to same machine where executing capistrano deploy.) using Capistrano. The cause is when capistrano creates temporary directory for destination (remote) directory and directory for source (local) directory point to same directory. This problem does not happen when you deploy to different machine. Solution Add the below code to your deploy.rb!! Just change the name for temoprary directory used during deployment name. # put this line at the top of app.yml in order to use SecureRandom methods require "securerandom" # set flag true when local deployment set :deploy_to_self, "true" # hook tasks before :deploy, "local:create_dir" after :deploy, "local:clean_dir" #################################### # setup copy_dir, copy_remote_dir # when deploying to machine which this script is running on to avoid copy issue # na

Java: Extract img src from HTML

Here is an code snippet for extracting image src from html. private static final Pattern IMG_SRC_PATTERN = Pattern.compile("<img\\s+.*src\\s*=\\s*('|\")(.+?)\\1.+?>"); public static List<String> extractImgSrces(final String content) { List<String> list = new ArrayList<>(); final Matcher matcher = IMG_SRC_PATTERN.matcher(content); while(matcher.find()){ list.add(matcher.group(2)); } return list; } The example usage is below. In this example, you should only prepare HttpUtils.getStringContentsFromURL method, which is getting html from given url, for your self. public static void main(String[] args) throws URISyntaxException, IOException { extractImgSrces(HttpUtils.getStringContentsFromURL("http://www.google.com/", "utf-8")).stream().forEach(System.out::println); }

Set Specific Revision Number for SVN External

Sometimes, You might want to set revision number for svn-external repository explicitly. In that case, you should just set svn-external with "-rXXXX" on your svn property (XXXX is the revision number you want to set)! I confimred it worked perfectly on windows, linux svn client. lib -rXXXX [svn-external target url]

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("&");