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

投稿

Bash Script for Back Up Files to Subversion

Introduction There are 2 ways to control files on multiple machines in the software development world. Deploy or build file from version control system Backup files to version control system In my opinion, ideally, everything should be done by the way 1 because it ensures the files are same across the all machines. However in the real world, sometime it is hard to deploy all files from version control system because of the various reasons - such as linux/unix permission or organization structure or too difficult to automating deployment or etc. etc.... In that case, we should take the way 2. In this post, I will introduce simple bash script for back up files to Subversion. Of course you can use your favorite version control system such as Git instead of Subversion ;) If you are a software developer, you can easily refine my bash script and create git version quickly ;) Bash Script for Back Up Files to Subversion See below script! You just save the script and simply execut

Java: Remove Comments, Annotations and Extra Spaces From Source Code

I have written Java code for removing comments, annotations and extra spaces from Java source code. package com.dukesoftware.utils.text; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import com.dukesoftware.utils.io.IOUtils; public class JavaSourceUtils { public static void main(String[] args) throws FileNotFoundException, IOException { String cleanedUpSource = removeCommentAndAnnotation(IOUtils.userDirectory( "workspace2/DukeSoftwareUtils/src/main/java/com/dukesoftware/utils/text/JavaSourceUtils.java" )); System.out.println(cleanedUpSource); } public static final String removeCommentAndAnnotation(File file) throws IOException { try(BufferedReader br = new BufferedReader(new FileReader(file))) { return removeCommentAndAnnotation(br); } } private final static int COD

PHP: Process Each File in Directory

PHP Code function processEachFileIn($path, callable $callback) { $objects = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach ($objects as $object) { if (!$object->isDir() && $object->getFilename() != '.' && $object->getFilename() != '..') { $callback($object); } } } Example Usage The below code demonstrates print all file names in directory /tmp recursively. processEachFileIn('/tmp', function($file){ echo $file->getFilename()."\n"; });

Java: Get Sorted Array Index

As you know, if you would like to sort array, you should use Arrays.sort method. But if you would like to get sorted index, you should use your a brain a bit. In this post, I will show you the code snippet for getting sorted array index. The following is the simplest way to get sorted index. The disadvantages of the following code are autoboxing in compare process and returned array type is not int[] but Integer[]. /** * The most common & general way. But this method use autoboxing and need Integer[] not int[]. */ public static final <T>void sort(T[] array, Comparator<T> comparator, Integer[] sorted) { Arrays.sort(sorted, (i1, i2) -> comparator.compare(array[i1], array[i2])); } To solve these advantage, I wrote following array sort helper class which can get sorted array index as int[] type. You can call getSortedIndex method with source array and comparator as the arguments. The code uses lambda expression which was introduced in Java 8. packa

Java: Count String Occurrence

Here is the code for count up string given as a second parameter appears on string given as a first parameter. public final static int countOccurrence(String src, String search) { for(int count = 0, fromIndex = 0;;) { fromIndex = src.indexOf(search, fromIndex); if(fromIndex < 0) return count; fromIndex++; count++; } }