Skip to content

Instantly share code, notes, and snippets.

@ken-itakura
ken-itakura / CustomYouTubePlayerView.swift
Created November 18, 2024 03:46
Play and control youtube video by SwiftUI controls
//
// YouTubePlayerView.swift
//
// Created by Ken Itakura on 2024/11/16.
//
import SwiftUI
import WebKit
struct YouTubePlayerView: UIViewRepresentable {
@ken-itakura
ken-itakura / SampleSwiftJSInteraction.html
Last active November 18, 2024 05:59
SwiftUI: inject javascript into a page in WKWebView, call javascript function from swift, call swift function from javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example</title>
</head>
<body>
<h1>WKWebView Example</h1>
<p>HTML content loaded!</p>
@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){