Skip to content

Instantly share code, notes, and snippets.

# coding: utf-8
def  (  )
(1..  ).each do |   |
if     % 15 == 0
print '     '
elsif     % 3 == 0
print '   '
elsif     % 5 == 0
print '  '
else
@aquarla
aquarla / hashtags.js
Created May 2, 2022 09:20
テキストからハッシュタグを抽出
const text = "#テ・スト 今日はカレーです #あbc #aaa  #gochisou_photo abcde";
const WORD = '\\p{L}\\p{M}\\p{N}\\p{Connector_Punctuation}';
const ALPHA = '\\p{L}\\p{M}';
const SEPARATORS = '\\u00b7\\u2007';
const regexp = new RegExp(`(?:^|[^\/\)\w])(#(([${WORD}_][${WORD}${SEPARATORS}]*[${ALPHA}${SEPARATORS}][${WORD}${SEPARATORS}]*[${WORD}_])|([${WORD}_]*[${ALPHA}][${WORD}_]*)))`, 'gu');
const tags = Array.from(text.matchAll(regexp)).map((item) => item[1]);
@aquarla
aquarla / pseudo-snowflake.js
Created April 25, 2022 08:14
なんちゃってSnowflake
export default function pseudoSnowflake() {
const now = new Date();
const time = now.getTime();
return (BigInt(time) << BigInt(16) + BigInt(Math.floor(Math.random(2**16)))).toString();
}
/*
* PrismaではDatetime型を取り出すときのタイムゾーンが指定できない(固定でUTC)になってしまう
* ため、強制的に9時間マイナスしてJSTに補正する
*/
export default function convertTimezone(obj) {
return {
...obj,
createdAt: new Date(Date.parse(obj.createdAt) - 1000 * 60 * 60 * 9),
updatedAt: new Date(Date.parse(obj.updatedAt) - 1000 * 60 * 60 * 9),
}
@aquarla
aquarla / kuku.rb
Created March 12, 2021 06:26
九九の進捗がいまいちなこどものために無限に問題を作成するヤツ
# coding: utf-8
100.times do |n|
str = ""
20.times do |i|
5.times do |j|
str += (rand(9)+1).to_s + "×" + (rand(9)+1).to_s + "=   "
end
str += "\n"
end
@aquarla
aquarla / mastodon_rss_bot.rb
Last active December 17, 2020 07:59
AWS Lambda用のマストドンRSS投稿BOTプログラム
require 'net/https'
require 'rss'
def lambda_handler(event:, context:)
iwatedon_api_url = 'https://enter-your-mastodon-domain/api/v1/statuses'
access_token = 'enter-your-access-token'
urls = [
'rss url 1',
'rss url 2',
'rss url 3',

Keybase proof

I hereby claim:

  • I am aquarla on github.
  • I am aquarla (https://keybase.io/aquarla) on keybase.
  • I have a public key whose fingerprint is C42C F2CB 24A5 4FC2 CBA8 72F3 CC80 85B9 4364 8C26

To claim this, I am signing this object:

@aquarla
aquarla / mastodon_screenshot.rb
Created August 1, 2018 08:18
Selenium WebDriver + Headless (Firefox|Chrome) でマストドンの個別ページのスクリーンショットを取るヤツ(要ImageMagick)
require 'selenium-webdriver'
mode = "firefox"
if mode == "firefox"
options = Selenium::WebDriver::Firefox::Options.new
options.add_argument('-headless')
profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] = "ja,en-us,en"
@aquarla
aquarla / hide_drawer.js
Created May 17, 2018 04:34
左端にカーソルを持っていったときだけ、Mastodonの投稿エリアが表示されるユーザーCSS
@-moz-document url-prefix("https://iwatedon.net/") {
div.drawer {
width: 10px;
}
div.drawer:hover {
width: 300px;
}
}
@aquarla
aquarla / split_into.rb
Created September 22, 2014 09:03
要素数が出来るだけ均等になるように、配列をn個に分割する
# -*- coding: utf-8 -*-
class Array
# 配列を要素数が出来るだけ均等になるようにn個に分割
def split_into(n)
sizes = (0...n).collect { |i|
(size % n >= (i+1)) ? (size / n + 1) : (size / n)
}
(0...n).collect { |i| slice(sizes[0,i].inject(0, :+), sizes[i]) }