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

投稿

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...

Html Layout by JSP

Introduction In this post, I will introduce how to achieve html layout by jsp. You just define layout and put piece of elements in each actual jsp. I won't explain details but just show you an quick example for sharing "header & footer" in all jsp pages. If you are interested in how & why it works, please refer jsp documentation (or googling). Code Simply you need to prepare a layout tag file and actual jsp files. Prepare layout.tag (actually name is not so important) and put it under WEB-INF/tags. Put header.jsp and footer.jsp under WEB-INF/views/ Create actual jsp which include taglib you previously defined above step. Ok now I will show you the actual codes. layout.tag A key part is using fragment feature. <%@tag description="Layout template" pageEncoding="UTF-8"%> <%@attribute name="main" fragment="true" %> <%@attribute name="head" fragment="true" %> <%@attribu...

URI Encode for Java

I always forget and struggling about the behavior of Java methods and classes for encoding uri. To clear my heads I will post small test codes. import java.net.URI; import java.net.URLEncoder; import java.util.BitSet; import org.apache.commons.httpclient.util.URIUtil; public class URIEncodeExample { // hehe using Japanese :p private static final String INPUT = "あいうえお/"; public static void main(String[] args) throws Exception { // java.net.URI // slash is not encoded because it is detected as a path separator // %E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A/ System.out.println(URI.create(INPUT).toASCIIString()); // java.net.URI + relativize // slash is not encoded because it is detected as a path separator // %E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A/ URI root = new URI("http", "dummy.com", null, null); URI uri = new URI("http", "dummy.com", ...

Regex: Detect Repeated String Chunks

Target strings I am trying to detect string which contains repeated string pattern like below. .....ABCDABCDABCD..... "ABCD" is just an example, it can be any fixed length of string chunk. Solution Regex Thinking for a bit and finally reached the solution regex which meets my demand is something like below. (.{4,})\\1{3,} The above regex matches string whose length of the chunk is more than 4 and it should be repeated equal or more than 4 times. In more general regex is below (using pattern formatting). String.format("(.{%d,})\\1{%d,}", minChunkLen, times-1) Java Code Ok you know I am Java lover, I will show you full regex code with test cases. If you found any bugs on the code please feel free to comment. public static final boolean isRepeatedStrIn(String input, int minChunkLen, int times) { return input.matches(String.format("(.{%d,})\\1{%d,}", minChunkLen, times-1)); } package com.dukesoftware.utils.common; import java.util.Array...

Check window.opener permission

Issue I tried to access some properties (or call methods) defined in http parent window via window.opener in pop-upped https window, which is created from the parent window. But it simply fails when accessing window.opener.a_property in the child window because the protocol is different between the child and parent window. e.g. http and https Remember this browser behavior is absolutely correct. The point of this post is how to avoid simply stopping javascript when accessing properties in window.opener. Browsers I confirmed this permission issue happens FireFox 17.0.1 and Internet Explore 9. Somehow Chrome doesn't complain it at all. the code simply passed. Solution In order to avoid this, I wrote the following conditions to detect the window.opener is accessible or not before accessing window.opener, but all of them don't return expected result at all. if(window.opener) // return true :( if(window.opener == undefined) // return true :( Finally I have reached at...

Calculate DENSE_RANK for MySQL

In this post, I will show you SQL query for calculateing dense rank for MySQL . You know Oracle and SQL Server have the function called DENSE_RANK, which is for returning rank of the value. Unfortunately MySQL doesn't have the built-in function. We can calculate dense rank by nested select for same table with count function. However this strategy is toooo slow because calculating rank by counting number of rows above the target row for every rows. Anyway here is the query for calculating dense rank for MySQL. SELECT id, @rnk:=IF(@preval score, @rnk, @row + 1) AS dns_rnk, @row:= @row+1 AS rnk, @preval:=score as score FROM table # be careful for NULL handling. # if all the values of score column are null, then dns_rank will zero. # please set proper initial value for @preval based on your data. JOIN (SELECT @rnk := 0, @preval :=null, @row := 0) r ORDER BY score DESC The result should be something like this. id dns_rnk rnk score 1 1 1 100 4 2 2 81 ...