Skip to content

Instantly share code, notes, and snippets.

View akirad's full-sized avatar

akirad akirad

  • Kawasaki, Japan.
View GitHub Profile
@akirad
akirad / SnmpTrapClient.java
Created April 24, 2016 10:56
A sample to send a snmp trap data.
// A sample to send a trap data.
// Ref.
// http://jis.hatenablog.com/entry/2013/09/05/134001
// https://www.qoosky.net/techs/f8c35bb5d7
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class SnmpTrapClient {
@akirad
akirad / testByte.java
Created April 23, 2016 10:44
A memo to use byte in java code.
public class testByte {
public static void main(String[] args) {
byte byteData = (byte) 0xC7; // 11000111
// If there is no "(byte)", 0xC7 is looked as int.
System.out.println(byteData); // -57
int intData = 0xC7; // 00000000 00000000 00000000 11000111
System.out.println(intData); // 199
@akirad
akirad / addMailQuote.pl
Last active March 27, 2016 02:39
This script just adds "> " to the text message from clipboard and set the result to clipboard.
use strict;
use warnings;
use Win32::Clipboard;
my $clip = Win32::Clipboard();
my $text = $clip->GetText();
$text =~ s/^/> /mg;
$clip->Empty();
$clip->Set($text);
// [課題]
// 5 = -0.00003*X^4 + 0.0034*X^3 - 0.1257*X^2 + 1.6351*X + 0.000000000003 のXを求める。
// いろいろ方法はありそうだが、メジャーな数値計算法である、ニュートン法で試してみた。
// 具体的には、f(X) = -0.00003*X^4 + 0.0034*X^3 - 0.1257*X^2 + 1.6351*X + 0.000000000003 - 5 として、
// f(X) = 0 となる解Xを、ニュートン法、つまり、X[n+1] = X[n] - f(X)/f'(X) をもとに、繰り返し計算を行った。
public class Newton {
public static void main(String[] args) {
double x = 1; // 出発値
double new_x;
double EPS = 1.0e-5; // 許容誤差
@akirad
akirad / testBrace.pl
Last active January 1, 2016 23:19
perlで配列を生成する際には、( )や[ ]が利用できるが、その違いに関する覚書き。[ ]は、(無名)配列を生成し、かつ、そのリファレンス(アドレス)となる。複数の配列を関数に渡す時に、受け取った側で各配列を別個に扱うため、渡す側では配列そのものではなく、各配列のリファレンスを渡すということがあるが、そんな時に、この[ ]は役に立つかも。
use strict;
use warnings;
# {}は、(無名)ハッシュを生成し、かつ、そのリファレンス(アドレス)となる。
my $ref_hash = {"a" => "A", "b" => "B", "c" => "C"};
print($ref_hash->{"a"} . "\n"); # "A"
# つまり、以下と同様。上のように書いた方がカッコいいか。
my %hash = ("a" => "A", "b" => "B", "c" => "C");
print((\%hash)->{"a"} . "\n"); # "A"
@akirad
akirad / date.html
Last active December 24, 2015 00:09
An easy sample to show current date and years of Heisei(平成).
<html>
<head>
<title>現在時刻</title>
<script language="JavaScript">
function getCurrentTime() {
var dayArray = new Array("日","月","火","水","木","金","土");
var dateObj = new Date();
var year = dateObj.getYear() + 1900;
var heisei = year - 1988;
@akirad
akirad / Base.java
Created September 2, 2013 05:28
These code are easy sample(test) for static field in Java.
package staticFieldTest;
public abstract class Base {
public static int staticCounter = 0;
public int NonStaticCounter = 0;
public void countUp(){
staticCounter++;
NonStaticCounter++;
@akirad
akirad / getBytesSample.java
Last active December 22, 2015 02:19
A sample of using getBytes(). This shows some behaviors of getBytes() with Multi byte characters.
import java.io.UnsupportedEncodingException;
public class getBytesSample {
public static void main(String[] args) {
// Tested on Windows7.
String str = "あいう";
try {
byte[] bytesSJIS = str.getBytes("Windows-31J");
byte[] bytesUTF8 = str.getBytes("UTF-8");
@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(){
@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(