Skip to content

Instantly share code, notes, and snippets.

View akirad's full-sized avatar

akirad akirad

  • Kawasaki, Japan.
View GitHub Profile
@akirad
akirad / Snmpwalk.java
Last active June 11, 2019 08:57
An example of snmpwalk by java. It needs snmp4j. [Compile] javac -cp <path to a snmp4j.jar> Snmpwalk.java [Execute] java -cp <path to a snmp4j.jar>;. Snmpwalk If there is not the current dir in the path of -cp, java can't find Snmpwalk class...
import java.io.IOException;
import java.util.List;
import org.snmp4j.CommunityTarget;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
@akirad
akirad / detectNodes.conf
Created May 22, 2013 05:03
A perl script which detects running nodes in networks. It also can get MIB. It is necessary to specify conf file(detectNodes.conf) and binary of Snmpwalk.java.
IPaddr: 192.168.0.1-20
IPaddr: 192.168.0.30-40
oid: .1.3.6.1.2.1.1.3
com: public
@akirad
akirad / getJavaCodeCnt.pl
Last active December 17, 2015 18:29
A perl script which gets line number of Java codes.
use strict;
use warnings;
#---------------------------------------
# Arg check.
#---------------------------------------
my $dir = $ARGV[0];
my $usage = << "END_USAGE";
Usage: $0 directory
END_USAGE
@akirad
akirad / ThreadTest.java
Last active December 17, 2015 18:48
A thread test sample for java. It shows the differece between runnable.run() and thread.start(). This code is originally from a J2EE community. I modified it for me.
public class ThreadTest {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Start!");
Runnable r1 = new Runnable() {
public void run() {
try {
@akirad
akirad / FutureSample.java
Last active December 17, 2015 19:19
A sample program using "Future" of Java. The result of this program is (e.g.) as follows. Execute a task... Execute other task. Task started. Task Ended. Other task finished. Time(Task result) is Mon May 27 19:43:41 MDT 2013
import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class FutureSample {
public static void main(String[] args) {
@akirad
akirad / detectLF.pl
Last active December 17, 2015 22:29
A perl script which detect "LF" in files.
use strict;
use warnings;
my $dir = $ARGV[0];
if(! -d $dir){
die "Invalid argument.";
}
$dir =~ s|\\|/|g; # Just in case.
my @fileList;
@akirad
akirad / replaceTabToSpace.pl
Created June 7, 2013 04:50
A perl script which can replace tab to 4 spaces in source files under an argument(dir).
use strict;
use warnings;
use File::Basename 'fileparse';
my $dir = $ARGV[0];
if(! -d $dir){
die "Invalid argument.";
}
$dir =~ s|\\|/|g; # Just in case.
@akirad
akirad / printAllUnderDir.pl
Last active December 18, 2015 14:09
A perl script which can show files and dirs under a dir. It can also show dot files. It should work when a path of a dir is long.
use strict;
use warnings;
my $dir = $ARGV[0];
if(! -d $dir){
die "Invalid argument.";
}
$dir =~ s|\\|/|g; # Just in case, change '\' to '/' in the Windows path.
getFileList($dir);
@akirad
akirad / extractRecursively.pl
Last active December 19, 2015 10:59
Specified a dir as a argument, this script extracts archive files(zip/ear/war/jar files) in the dir recursively. It means if a zip file contains another zip file, both zip files are extracted. Then, if "-d" option is specified, the original archive files are removed.
use strict;
use warnings;
use Archive::Zip;
use File::Basename;
use Getopt::Long;
my $DEF_OF_ARC = '(\.zip$)|(\.jar$)|(\.war$)|(\.ear$)|(\.sar$)';
my $deleteArchiveFile;
GetOptions(
@akirad
akirad / ExternalClass.java
Last active December 21, 2015 15:28
Java inner class test.
package innerClassTest;
public class ExternalClass {
String str = "external";
class InnerClass {
String str = "inner";
}
InnerClass createInner(){