Skip to content

Instantly share code, notes, and snippets.

View hirohitokato's full-sized avatar

Hirohito Kato hirohitokato

View GitHub Profile
@hirohitokato
hirohitokato / zenncrawler.ts
Last active August 15, 2024 03:22
DenoでZennをクロールして、記事の一覧をMarkdown形式に変換して出力するスクリプト
#!/usr/bin/env -S deno run --allow-net --allow-write
/**
* Zennのトップページまたは指定したタグのページを読み込み、Markdown形式でまとめて出力するスクリプト
* - オプションなしで実行すると"https://zenn.dev/articles/explore?tech_order=weekly"にアクセスし、
* "yyyyMMddhhmm-trend.md" のファイル名でMarkdownファイルを生成する。
* - `--tags タグ名`(タグはrustやtypescriptなど)で実行すると"https://zenn.dev/topics/タグ名"にアクセスし、
* "yyyyMMddhhmm-{タグ名}.md" のファイル名でMarkdownファイルを生成する。
* - `--stdout`オプションを付けて実行すると、ファイル出力せずに標準出力へMarkdownテキストを出力する
*
* 使用方法:
//
// CustomSlider.swift
//
// @Refer: https://betterprogramming.pub/reusable-components-in-swiftui-custom-sliders-8c115914b856
// @Usage:
//
// CustomSlider(value: $state.exposureValue, range: (0, 1)) { modifiers in
// ZStack {
// LinearGradient(gradient: .init(colors: [Color.pink, Color.orange ]), startPoint: .leading, endPoint: .trailing)
// ZStack {
@hirohitokato
hirohitokato / UIImageView+pixelColor.swift
Created October 25, 2022 09:24
UIImageViewで表示している画像の、特定位置のピクセル色を求めるextension
import UIKit
extension UIImageView {
/// UIImageView上での座標が指す色をUIColorで返す。画像が未設定の場合はnilを返す
///
/// 以下のように使う.
///
/// @objc func tappedImage(_ sender: UITapGestureRecognizer) {
/// let point = sender.location(in: self)
/// let color = self.pixelColor(at: point) // <- here
@hirohitokato
hirohitokato / UIImageView+pixelColor.swift
Last active August 14, 2022 05:36
Get pixel color at location from UIImage in UIImageView.
extension UIImageView {
/// UIImageView上での座標が指す色をUIColorで返す。画像が未設定の場合はnilを返す
///
/// 以下のように使う.
///
/// @objc func tappedImage(_ sender: UITapGestureRecognizer) {
/// let point = sender.location(in: self)
/// let color = self.pixelColor(at: point) // <- here
/// :
/// }
def to_euler_angles(R):
"""Calculate rotation matrix to euler angles.
The result is the same as MATLAB except the order
of the euler angles ( x and z are swapped ).
Args:
R (np.ndarray): rotation matrix.
"""
@hirohitokato
hirohitokato / SomeViewController.swift
Created April 28, 2020 02:02
iPadでも画面の向きによってAutoLayoutを適用したいときのコード
/*
iPadは縦横どちらの向きでもUIUserInterfaceSizeClassが.regularなので、AutoLayoutのOrientationによる表示変更ができない。
以下のコードを必要なViewControllerに書いておくと`.regular × .compact`と判断するようになりiPhoneと同じルールでレイアウトできる。
*/
// MARK: - Trick for iPad device orientation
override public var traitCollection: UITraitCollection {
let device = UIDevice.current
let result: UITraitCollection
@hirohitokato
hirohitokato / CopyURL.js
Created January 1, 2018 13:49
A bookmarklet to get a markdown style URL string you are seeing, whose title is the page title or a string you select. The result is copied to clipboard.
javascript:caption=window.getSelection()+'';if(caption==""){caption=document.title;}i=document.createElement('input');i.setAttribute('id','copyinput');document.body.appendChild(i);i.value='%5B'+caption+'%5D('+location.href+')';i.select();document.execCommand('copy');document.body.removeChild(i);void(0);
// execute the bookmarklet without selection: [page's title](page URL)
// execute it with selection: [selected string](page URL)
@hirohitokato
hirohitokato / DownloadContainer.scpt
Last active December 14, 2017 15:55
Xcodeが開いている状態で実行すると、目的のAppのコンテナダウンロードを実行し保存先ダイアログまで表示するAppleScript
set DEVICE_NAME to "ここにアプリが入ったデバイス名(My iPhoneとか)"
set APP_NAME to "ここにアプリ名"
tell application "System Events"
tell process "Xcode"
--- set frontmost to true
click menu item "Devices" of menu "Window" of menu bar 1
tell window "Devices"
--- button 1-3はクローズ・最大化・最小化
--- table 1 of scroll area 1 of splitter group 1は左ペイン内のがデバイスやシミュレータなど
@hirohitokato
hirohitokato / ArrayExtension.swift
Last active March 12, 2024 12:02
Get downsampled array from original data, using vDSP. For only Float array.
extension Array where Element == Float {
// @see: HOW TO CREATE A SOUNDCLOUD LIKE WAVEFORM IN SWIFT 3
// (https://miguelsaldana.me/2017/03/13/how-to-create-a-soundcloud-like-waveform-in-swift-3/)
func downSampled(binSize: Int, multiplier: Float = 1.0) -> [Float] {
let count = self.count
var processingBuffer = [Float](repeating: 0.0,
count: Int(count))
let sampleCount = vDSP_Length(count)
@hirohitokato
hirohitokato / DLFonts.swift
Created June 23, 2017 07:47
ダウンロードフォントの管理クラス
//
// DLFonts.swift
//
// Created by Hirohito Kato on 2017/04/21.
// Copyright © 2017 Hirohito Kato. All rights reserved.
//
//
// FontDownloader.swift
// FontDownloader