Skip to content

Instantly share code, notes, and snippets.

@ken-itakura
ken-itakura / IsAllHiragana, IsAllKatakana
Created October 1, 2016 20:13
Excel function that checks whether a cell contains Hiragana only or Katakana only
Public Function IsAllHiragana(cell)
Set REG = CreateObject("VBScript.RegExp")
REG.Pattern = "^[ぁ-んー]+$" ' there are a couple of more hiragana in unicode, which are ignored
Set REGMatch = REG.Execute(cell)
If REGMatch.Count > 0 Then
IsAllHiragana = True
Else
IsAllHiragana = False
End If
End Function
@ken-itakura
ken-itakura / Csv2Map.scala
Created October 4, 2016 07:14
Read CSV and create Map
import scala.io.Source
// Read CSV create and create Map
object DictSource2SeedDict extends App {
val csvFile = Source.fromFile("file_path", "utf8")
val listDict = Map(csvFile.getLines.toList.map{l =>
val lc = l.split("\t")
(lc(0)->lc(1)) // assume first field is key and second field is value
@ken-itakura
ken-itakura / MD5.vb
Created November 8, 2016 12:58
Excel, Access VBA Function to create MD5 for text
Public Function MD5Hex(textString As String) As String   
Dim enc   
Dim textBytes() As Byte   
Dim bytes   
Dim outstr As String       
Set enc = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")   
textBytes = textString   
bytes = enc.ComputeHash_2((textBytes))   
@ken-itakura
ken-itakura / strutils.py
Created May 25, 2017 07:29
python unicode str conversion functions
# -*- coding: utf-8 -*-
"""
Created on 2017/5/25
@author: itakura
"Unicode <-> str 変換関連"
"""
class strutils:
@ken-itakura
ken-itakura / watch_cloudwatch.py
Created March 6, 2018 21:23
monitor cloud watch log continuously
import boto3
from boto3.session import Session
import time
from datetime import datetime
import calendar
def get_log_events(log_group):
"""Generate all the log events from a CloudWatch group.
thanks to https://alexwlchan.net/2017/11/fetching-cloudwatch-logs/
:param log_group: Name of the CloudWatch log group.
@ken-itakura
ken-itakura / photo_capture.py
Last active March 19, 2019 08:32
Capture image by web cam and get data (python3.6, OpenCV, JupyterLab)
import cv2
import matplotlib.pyplot as plt
import ipywidgets as widgets
# from IPython.core.debugger import set_trace
# To run in JuptyerLab, you need to run following in console to enable interactive
# jupyter labextension install @jupyter-widgets/jupyterlab-manager
class PhotoCapture():
"""
Catpture image by camera
@ken-itakura
ken-itakura / export_import_firestore_docs.ts
Created June 14, 2020 10:06
export and import firestore document tree (typescript). env var GOOGLE_APPLICATION_CREDENTIALS must be defined before run
import {Firestore} from "@google-cloud/firestore";
import fs from "fs";
const firestore = new Firestore();
const keyOriginalPath = "__originalPath__";
const keyDocumentContent = "__documentContent__";
const keyCollectionPath = "__collectionPath__";
const keyCollections = "__collections__";
const keyDocument= "__document__";
if(process.argv.length !== 5){
@ken-itakura
ken-itakura / SampleAsyncTest.kt
Created April 2, 2021 04:02
async function test with Kotlin, junit and Truth
import com.google.common.truth.Truth.assertThat // https://truth.dev/
import junit.framework.TestCase
import kotlinx.coroutines.*
import org.junit.Test
class SampleAsyncTest : TestCase() {
suspend fun sampleFunctionToTest(): String {
delay(1000)
return "failure"
@ken-itakura
ken-itakura / cache_result.py
Last active July 16, 2022 08:51
Avoid redoing long computation in a jupyter cell by pickling the result
import pickle
import os
# Helper functions
def pickle_them(pickle_file, *objs):
print(f"saving to {pickle_file}")
with open(pickle_file, 'wb') as f:
for obj in objs:
pickle.dump(obj, f)
@ken-itakura
ken-itakura / plt_subplots_helper.py
Last active July 16, 2022 09:07
matplotlib subplots helper
#
# helper function to matplotlib subplots make pretty and easy to handle.
#
from matplotlib import pyplot as plt
plt.style.use('default') # To avoid chart invisible, due to browser theme etc.
# Create raws x cols square subplots, fits to given width
# returned axes is 1D array, so that easily handle with simple loop