Skip to content

Instantly share code, notes, and snippets.

@ken-itakura
ken-itakura / Arrow.swift
Last active February 29, 2024 07:47
Drawing an arrow for SwiftUI
//
// Arrow.swift
//
// Created by Ken Itakura on 2024/02/29.
//
import SwiftUI
struct Arrow: View {
var start: CGPoint
@ken-itakura
ken-itakura / RunAllRules.vba
Last active March 1, 2024 01:56
Outlook VBA macro to execute all outlook sorting rules in multiple accounts.
Sub RunAllRules()
On Error Resume Next
Dim accounts As Outlook.accounts
Set accounts = Application.Session.accounts
Dim account As Outlook.account
rulesDone = ""
rulesError = ""
For Each account In accounts
rulesDone = rulesDone & account.DisplayName & "("
@ken-itakura
ken-itakura / MMMDDYYY_to_DATE.vba
Created June 2, 2023 02:18
Excel function to convert date string (mmm/d/yyyy like AUG/31/2021) to Date format
Function MMMDDYYY_to_DATE(datestr As String) As Date
Parts = Split(datestr, "/")
datestr = Parts(2) & "/" & Parts(0) & "/" & Parts(1)
MMMDDYYY_to_DATE = DateValue(datestr)
End Function
@ken-itakura
ken-itakura / ShrinkCircleAnimation.kt
Created February 3, 2023 07:28
Android simple shrinking circle animation
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.view.View
import android.view.animation.Animation
/* How to use
Call as follows in an Activity
val circleView = CircleView(this)
@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
@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 / 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 / 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 / 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 / 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.