IT練習ノート

IT関連で調べたこと(実際は嵌ったこと)を書いています。

jsiiの仕組みの確認

github.com

Node.Js上でサーバが立ち上がり、クライアントのJavaと、JSONを用いたプロセス間通信をする。

Client : Java

Server : javascript
> node jsii-runtime.js


JsiiRuntimet.java <-- STDIN/STDOUT protocol --> jsii-runtime.js --> jsii-kernel.js
                       ------ JSON ------

jsiiのjavaライブラリを使う側は、JssObjectを継承したクラスを作成する。

* Class Dependency

JsiiObject --> JsiiEngine --> JsiiRuntime <--> JsiiClient
                                 |
                              ProcessBuilder (Java API)

* Java object method call

JsiiObject#jsiiCall -...-> JsiiClient#callMethod -> JsiiRuntime#reqestResponse

* Library Dependency

Jsii -> Jackson

設定ファイルを読み込むstack ghciの起動

いつもstack ghciで起動した後に手で``:set prompt " > "をしていました。これを起動時に自動的に実行したかったのですが、やり方がわかりませんでした。

PS C:\Users\User\haskell\> stack ghci
Using main module: 1. Package `RS' component exe:RS-exe with main-is file: C:\Users\User\haskell\Main.hs
...
[2 of 2] Compiling Main             ( C:\Users\User\haskell\app\Main.hs, interpreted )
Ok, two modules loaded.
Loaded GHCi configuration from C:\Users\User\AppData\Local\Temp\haskell-stack-ghci\548116bc\ghci-script
*Main Lib>
*Main Lib> :set prompt " > "
 >

確かに

Loaded GHCi configuration from C:\Users\User\AppData\Local\Temp\haskell-stack-ghci\548116bc\ghci-script

のログが出ていて、ここに起動時に実行されるスクリプトがあります。

中身は

:add Lib C:\Users\User\haskell\app\Main.hs
:module + Lib

となっています。 ここに書けば実行されるはずですが、stackが自動的に作成するTemp内にあるので、ここには書きたくありません。

マニュアルには、起動時に実行するスクリプトの配置場所が3か所書いてあります。

4. Using GHCi — Glasgow Haskell Compiler 8.8.1 User's Guide

なので、ここにスクリプトを配置すればよいのですが、stack ghciで起動したときの.appdata$HOMEの場所がわかりませんでした。 あれこれ悩みましたが、答えは単純で、System.Directoryにある関数を使えば、これらの場所がわかります。

*Main Lib> import System.Directory
*Main Lib System.Directory> getCurrentDirectory
"C:\\Users\\User\\haskell\\"
*Main Lib System.Directory> getAppUserDataDirectory ""
"C:\\Users\\User\\AppData\\Roaming\\"
*Main Lib System.Directory> getHomeDirectory
"C:\\Users\\User"
*Main Lib System.Directory>

自分の環境の場合は

"C:\Users\User\haskell\"

.ghciファイルを作成しました。

:set prompt " > "
:set +t

これで、stack ghci時に自動的にスクリプトが実行されます。

型の情報も欲しいので:set +tも入れています。

PowerPointで選択したテキストの情報をスライドタイトルも含めてクリップボードに入れるマクロ

f:id:naotoogawa:20191027123302p:plain

Public Sub getSelectedTextInfo()
  Dim s As PowerPoint.Slide
  Set s = GetActiveSlide()
  If s Is Nothing Then
    Debug.Print "アクティブなスライドを取得できません。", vbCritical + vbSystemModal
  Else
    putCB ("スライドタイトル / 内容 = " & s.Shapes.Title.TextFrame.TextRange.Text & " / " & getSelectedText())
  End If
End Sub
  
' 参考 https://tonari-it.com/powerpoint-vba-selection-textrange-font/
Public Function getSelectedText()
  With ActiveWindow.Selection
    If .Type >= ppSelectionText Then
        getSelectedText = .TextRange.Text
    End If
  End With
End Function

' 参考 https://www.ka-net.org/blog/?p=2294
Public Function GetActiveSlide() As Slide
  Dim ret As Slide
  Set ret = Nothing
  On Error Resume Next
  Set ret = ActivePresentation.Slides.FindBySlideID(ActivePresentation.Windows(1).Selection.SlideRange.SlideID)
  On Error GoTo 0
  Set GetActiveSlide = ret
End Function

' クリップボードに入れる
Private Sub putCB(ByVal val As String)
  With CreateObject("Forms.TextBox.1")
    .MultiLine = True
    .Text = val
    .SelStart = 0
    .SelLength = .TextLength
    .Copy
  End With
End Sub

選択したセルの情報をクリップボードに張り付けるエクセルマクロ

選択したセルの、ブック名、シート名、セルの位置とセル自体の値をクリップボードに設定するマクロ(getActiveCellValueCB1プロシージャ)

f:id:naotoogawa:20191022144610p:plain

Sub getCurrentSheetNameCB()
  putCB getCurrentSheetName()
End Sub

Sub getActiveCellRowColCB()
  putCB getActiveCellRowCol()
End Sub

Sub getActiveCellValueCB1()
  putCB "ブック / シート / セル / 値 = " & _
    joindel(ActiveWorkbook.Name, getCurrentSheetName(), getActiveCellRowCol(), ActiveCell.Text)
End Sub

Sub getActiveCellValueCB2()
  putCB "シート / セル / 値 = " & _
    joindel(getCurrentSheetName(), getActiveCellRowCol(), ActiveCell.Text)
End Sub

Function getCurrentSheetName()
  Dim sheetName As String
  getCurrentSheetName = ActiveSheet.Name
End Function

Function getActiveCellRowCol()
  Dim r As Long
  r = Selection.Row
  Dim l As Long
  l = Selection.Column
  getActiveCellRowCol = ConvertToLetter(l) & CStr(r)
End Function

' join
Function joindel(ParamArray val() As Variant)
  joindel = Join(val, " / ")
End Function

' クリップボードに入れる
Private Sub putCB(ByVal val As String)
  With CreateObject("Forms.TextBox.1")
    .MultiLine = True
    .Text = val
    .SelStart = 0
    .SelLength = .TextLength
    .Copy
  End With
End Sub

' https://docs.microsoft.com/ja-jp/office/troubleshoot/excel/convert-excel-column-numbers
Function ConvertToLetter(iCol As Long) As String
   Dim iAlpha As Integer
   Dim iRemainder As Integer
   iAlpha = Int(iCol / 27)
   iRemainder = iCol - (iAlpha * 26)
   If iAlpha > 0 Then
      ConvertToLetter = Chr(iAlpha + 64)
   End If
   If iRemainder > 0 Then
      ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
   End If
End Function