Monday, April 27, 2015

Regular Expressions for Japanese

Regex for matching Japanese Post Codes (郵便番号)
/^¥d{3}¥-¥d{4}$/
/^¥d{3}-¥d{4}$|^¥d{3}-¥d{2}$|^¥d{3}$/

Regex for matching Japanese mobile phone numbers (携帯電話番号)
/^¥d{3}-¥d{4}-¥d{4}$|^¥d{11}$/
/^0¥d0-¥d{4}-¥d{4}$/

Regex for matching Japanese fixed line phone numbers (固定回線電話番号)
/^[0-9-]{6,9}$|^[0-9-]{12}$/
/^¥d{1,4}-¥d{4}$|^¥d{2,5}-¥d{1,4}-¥d{4}$/

Morse Code in Python

var dict = {
  '.-': 'A',
  '-...': 'B',
  '-.-.': 'C',
  '-..': 'D',
  '.': 'E',
  '..-.': 'F',
  '--.': 'G',
  '....': 'H',
  '..': 'I',
  '.---': 'J',
  '-.-': 'K',
  '.-..': 'L',
  '--': 'M',
  '-.': 'N',
  '---': 'O',
  '.--.': 'P',
  '--.-': 'Q',
  '.-.': 'R',
  '...': 'S',
  '-': 'T',
  '..-': 'U',
  '...-': 'V',
  '.--': 'W',
  '-..-': 'X',
  '-.--': 'Y',
  '--..': 'Z',
  '.----': '1',
  '..---': '2',
  '...--': '3',
  '....-': '4',
  '.....': '5',
  '-....': '6',
  '--...': '7',
  '---..': '8',
  '----.': '9',
  '-----': '0'
};

Friday, April 24, 2015

Finding duplicate ids in html nodes

var idList = {};
var nodes = document.getElementsByClassName('');
for (var i in nodes) {
  if (!isNaN(i) && nodes[i].id) {
    idList[nodes[i].id] = idList[nodes[i].id]? idList[nodes[i].id]+1:1;
  }
}
for (var id in idList) {
  if (idList[id] > 1) console.log("Duplicate id: #" + id);
}

Going one step further with Kotlin & gRPC

Recently, I tried using Quarkus with Kotlin for grpc. I have worked with grpc for communication between microservices in Java & Golang. ...