Skip to content

Instantly share code, notes, and snippets.

@yuki2021
yuki2021 / add_infeed_google_adsence.html
Last active June 21, 2024 12:31
遅延読み込みでGoogleアドセンスのインフィード広告を読み込み、なおかつ配信されてこない時は削除するスクリプト
<!-- Googleアドセンスのinsのdata-ad-statusがunfilledの時はnone -->
<style>
ins[data-ad-status="unfilled"] {
display: none;
}
</style>
<!-- 広告読み込み -->
<script>
(function(){
@yuki2021
yuki2021 / scrapbox_to_hatena_blog_post.user.js
Last active March 6, 2024 12:22
TampermonkeyでScrapboxからはてなブログに投稿するスクリプト
// ==UserScript==
// @name Scrapbox to Hatena Blog Post
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Scrapboxのページデータを取得してはてなブログに投稿するスクリプト
// @author yuki2021
// @match https://scrapbox.io/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
@yuki2021
yuki2021 / test_insert_import.sh
Last active November 13, 2023 05:13
特定の文字が含まれてるファイルをディレクトリを回帰的に検索して、置換を行うシェルスクリプト
#!/bin/zsh
# testのディレクトリにlogger.dartのimport文を挿入するための使い捨てスクリプト
# 検索するコメント
search_string="// FirebaseSecureStorageをモック化"
# 挿入するインポート文
import_statement="import 'package:test_2023/constant/logger.dart';"
@yuki2021
yuki2021 / randam_url_open.js
Created September 13, 2023 00:32
自分用のランダムなニュースサイトのURLを開くブックマークレット
javascript:(function() {
var urls = [
'https://www.nikkei.com/',
'https://www3.nhk.or.jp/news/',
'https://ryukyushimpo.jp/',
'https://www.asahi.com/',
'https://www.sankei.com/',
'https://courrier.jp/',
'https://www.cnn.co.jp/',
'https://www.bbc.com/japanese',
@yuki2021
yuki2021 / apcu_cache.php
Created May 31, 2023 11:57
APCuでDB処理のキャッシュを行う方法。
<?php
/// 渡されたURLでDBを検索する。見つけたデータを返す
public function searchDB($url) {
// APCuにキャッシュがあればそれを返す
$data = apcu_fetch($url);
if ($data === false) {
$sql = 'SELECT b.abstract FROM `hatena_blog_data` AS a
LEFT JOIN `hatena_content_abstract` AS b
ON a.`id` = b.`hatena_blog_id`
where b.`abstract` IS NOT NULL AND
@yuki2021
yuki2021 / completer_try_catch_example.dart
Created May 24, 2023 07:00
Completerで例外処理
import 'dart:async';
void main() async {
Completer completer = Completer<String>();
// 非同期処理を開始します(ここでは2秒待つだけ)
Future.delayed(Duration(seconds: 2)).then((_) {
// 非同期処理が完了したらエラーを投げます
completer.completeError(Exception("Something went wrong"));
});
@yuki2021
yuki2021 / completer_example.dart
Created May 24, 2023 06:59
Completerの使い方の例
import 'dart:async';
void main() async {
Completer completer = Completer<String>();
// 非同期処理を開始します(ここでは2秒待つだけ)
Future.delayed(Duration(seconds: 2)).then((_) {
// 非同期処理が完了したらCompleterを完成させます
completer.complete("Hello, World!");
});
@yuki2021
yuki2021 / page_exists.dart
Created May 24, 2023 06:57
Scrapboxにそのページが存在するか確認する処理
// その日の日付のページが存在するかどうか
Future<bool> pageExists(String title) async {
try {
// webViewContrllerを取得
final webViewController = ref.watch(webViewControllerProvider);
final url =
'https://scrapbox.io/api/pages/$_scrapboxProject/${Uri.encodeComponent(title)}';
if (webViewController == null) return false;
@yuki2021
yuki2021 / scrapbox_share.js
Created May 2, 2023 06:46
Scrapboxのリンクをクリップボードにコピーするブックマークレット
javascript:(function(){
var textToCopy = '['+ document.title +' '+ location.href + ']';
navigator.clipboard.writeText(textToCopy).then(function() {
console.log('Copying to clipboard was successful!');
}, function(err) {
console.error('Could not copy text: ', err);
});
})();
@yuki2021
yuki2021 / scrapbox_open_diary.user.js
Created May 1, 2023 08:43
Tampermonkeyにて、Scrapboxの日記ページを開くためのUserScript
// ==UserScript==
// @name scrapbox_open_diary
// @version 1.0
// @description Scrapboxでその日の日付の日記ページを開く
// @author yuki2021
// @match https://scrapbox.io/*
// ==/UserScript==
var optDown = false;