Skip to content

Instantly share code, notes, and snippets.

View KenjiOhtsuka's full-sized avatar
👍
Hello, World!

Kenji Otsuka KenjiOhtsuka

👍
Hello, World!
View GitHub Profile
// Require `PhoneNumberFormat`.
const PNF = require('google-libphonenumber').PhoneNumberFormat;
// Get an instance of `PhoneNumberUtil`.
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
function test(text) {
// Parse number with country code and keep raw input.
let number = phoneUtil.parseAndKeepRawInput(text, 'JP');
@KenjiOhtsuka
KenjiOhtsuka / extract.py
Created May 27, 2024 04:17
Extract all images in a PowerPoint file
import pptx
from pptx.enum.shapes import MSO_SHAPE_TYPE
import os
# extract all images in the pptx file
def extract_images(pptx_path, output_dir):
i = 0
ppt = pptx.Presentation(pptx_path)
for slide in ppt.slides:
@KenjiOhtsuka
KenjiOhtsuka / hmac_sha256.py
Created December 2, 2023 02:56
HMAC (SHA-256) implementation
# HMAC with SHA-256
def sha256(message):
# SHA-256 implementation
import hashlib
return hashlib.sha256(message).digest()
def xor(a, b):
# XOR two byte strings
return bytes([x ^ y for x, y in zip(a, b)])
@KenjiOhtsuka
KenjiOhtsuka / sha_256.py
Last active December 1, 2023 22:55
SHA-256 Calculation in Python
# メッセージをビット列に変換する関数
def message_to_bitstring(message):
bitstring = ""
for char in message:
# ASCII コードを 8 ビットのビット列に変換する
bit = bin(ord(char))[2:].zfill(8)
bitstring += bit
return bitstring
@KenjiOhtsuka
KenjiOhtsuka / sample_to_call_azure_api_management_operation_with_service_principal.py
Last active October 20, 2023 00:50
Sample to Call Azure API Management Operation with Service Principal
"""
This is a sample to call API management operation with OAuth based on Azure AD.
"""
import msal
import logging
import requests
if __name__ == "__main__":
@KenjiOhtsuka
KenjiOhtsuka / KQL_cheat_sheet_ja.md
Last active August 17, 2023 02:53
with ChatGPT

Kusto Query Language (KQL) チートシート

データ型

  1. bool: 真偽値 (true または false) を表します。
  2. int: 整数型を表します。
  3. long: 長整数型を表します。通常、intよりも大きい値を扱う際に使用されます。
  4. real: 浮動小数点数型を表します。
  5. decimal: 10進数型を表します。高精度な小数点数計算に使用されます。
@KenjiOhtsuka
KenjiOhtsuka / 01_WhatWG_vs_W3C.md
Last active August 14, 2023 06:21
WhatWG, W3C についてのメモ書き。 ChatGPTにお世話になりました。

WhatWG と W3C の比較

WhatWG(Web Hypertext Application Technology Working Group)は、ウェブ技術の進化と標準化に関するグループであり、主にHTMLと関連するテクノロジーの開発と標準化に取り組む組織です。WhatWGは、特にHTML5仕様の開発を主導し、ウェブブラウジング体験を向上させるための新機能や改良を提案・実装してきました。

一方、W3C(World Wide Web Consortium)は、国際的な標準化団体であり、ウェブに関連する技術やプロトコルの標準を策定することを目指しています。W3CはHTMLやCSSなどのウェブ技術の標準を定めており、インターネット上の情報をよりアクセス可能で持続可能なものにするための取り組みを行っています。

WhatWGとW3Cの違いは以下のような点にあります。

特徴 WhatWG W3C
@KenjiOhtsuka
KenjiOhtsuka / PEM_keys.md
Created August 14, 2023 05:39
PEM key variation

秘密鍵の形式ごとに、使用するクラスが違う(C#)

“BEGIN RSA PRIVATE KEY” => RSA.ImportRSAPrivateKey
“BEGIN PRIVATE KEY” => RSA.ImportPkcs8PrivateKey
“BEGIN ENCRYPTED PRIVATE KEY” => RSA.ImportEncryptedPkcs8PrivateKey
“BEGIN RSA PUBLIC KEY” => RSA.ImportRSAPublicKey
“BEGIN PUBLIC KEY” => RSA.ImportSubjectPublicKeyInfo
@KenjiOhtsuka
KenjiOhtsuka / weird_css.html
Last active August 1, 2023 21:33
Weird CSS
<!--
When the computer browser shows 2nd and 3rd paragraphs in the same format,
but the mobile browser shows 2nd and 3rd ones differently.
-->
<!DOCTYPE html>
<html>
<head></head>
<body>
<p style="line-height: 1em; margin: 1em; background: rgba(0, 0, 0, 0.1);">
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@KenjiOhtsuka
KenjiOhtsuka / select.sql
Last active July 31, 2023 07:03
Generate SELECT SQL with listing all columns in the table (SQL Server)
-- for one table
SELECT 'SELECT ' + STUFF((
SELECT ', ' + name + CHAR(10)
FROM sys.columns
WHERE object_id = OBJECT_ID('table_name')
FOR XML PATH('')
), 1, 2, '') + ' FROM table_name;';
-- if you want to generate such SQL for multiple tables:
SELECT (SELECT 'SELECT ' + STUFF((SELECT ', ' + name + CHAR(10)