Skip to content

Instantly share code, notes, and snippets.

View mironal's full-sized avatar
🍷

mironal mironal

🍷
View GitHub Profile
@mironal
mironal / CountChar.swift
Created April 15, 2024 06:35
Count the number of characters typed in the Mastodon post screen.
import Foundation
import RegexBuilder
private let urlRegex = Regex {
Capture(.url(scheme: .required))
}
private let mentionRegex = Regex {
Capture {
ChoiceOf {
@mironal
mironal / README.md
Created February 2, 2024 08:03
Apple Privacy Manifest: Describing use of required reason API

Run this script in Describing use of required reason API.

let element = document.querySelector(".content > h3")
const results = []
do {
    if (element.nodeName === "H3") {
        const title = element.textContent
        results.push({ APIType: title })
@mironal
mironal / KeychainStorageEngine.swift
Created February 15, 2023 00:46
KeychainStorageEngine.swift implementation for Bodega with KeychainAccess
import Bodega // https://github.com/mergesort/Bodega
import Foundation
import KeychainAccess // https://github.com/kishikawakatsumi/KeychainAccess
public actor KeychainStorageEngine: StorageEngine {
private let keychain: Keychain
init(keychain: Keychain) {
self.keychain = keychain
}
@mironal
mironal / 0_HowToUse.swift
Last active July 5, 2022 09:14
TwitterAPIKit+RxSwift.generated.swift (The RxSwift extension for TwitterAPIKit)
struct TwitterResponse<Data: Decodable>: Decodable {
let data: Data
}
struct Status: Decodable {
let id: String
let text: String
}
let client = TwitterAPIClient(/* auth */)
@mironal
mironal / SearchStream.swift
Created February 27, 2022 02:15
Sample code for Search Stream API using TwitterAPIKit.
func testExample() throws {
let client = TwitterAPIKit(
.bearer(
"<your token>"
))
let exp = expectation(description: "")
/*
@mironal
mironal / Stream.swift
Created February 26, 2022 14:14
Sample code for Stream API using TwitterAPIKit.
func testExample() throws {
let client = TwitterAPIKit(
.bearer(
"token"
))
let exp = expectation(description: "")
let task = client.v2.sampleStream(.init())
@mironal
mironal / Data+split.swift
Last active February 26, 2022 02:43
Split Data by other Data
import Foundation
let datas = "abc\r\n\r\n123\r\nあいう😂\r\nAB\r\n".data(using: .utf8)!
let delim = "\r\n".data(using: .utf8)!
extension Data {
func split(separator: Data, omittingEmptySubsequences: Bool = true) -> [Data] {
var current = startIndex
var chunks = [Data]()
@mironal
mironal / DeleteSubtitle.swift
Last active February 24, 2022 15:19
Sample code for uploading video and subtitles using TwitterAPIKit.
// Delete subtitle
let exp = expectation(description: "")
client.v1.media.deleteSubtitle(.init(mediaID: "<media id>", mediaCategory: "TweetVideo", subtitleLanguageCodes: ["en"])).responseData { response in
print(response.prettyString)
exp.fulfill()
}
wait(for: [exp], timeout: 100)
@mironal
mironal / download.js
Created February 21, 2022 13:02
くらし TEPCO の指定した日付の範囲の30分毎データの csv をダウンロードするやつ
/*
1. startDay, endDay を編集する
2. ログインする: https://www.kurashi.tepco.co.jp/pf/ja/pc/mypage/learn/comparison.page
3. 2 のページで Chrome DevTools を開いてコードをコピペして実行する
概念: ダウンロード用の a タグを作ってマウスクリックを発火させてダウンロードしている.
*/
// includes start, end day
function getDays(start, end) {
@mironal
mironal / useTwitter.tsx
Created January 5, 2022 03:23
Twitter の Widget (widgets.js) を React でかんたんに使うためのやつ(React 以外の依存なし)
import { useEffect, useState } from "react"
/*
index.html などに以下の script をコピペ。
see) https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/set-up-twitter-for-websites
```
<script>window.twttr = (function(d, s, id) {