Skip to content

Instantly share code, notes, and snippets.

View PJZ9n's full-sized avatar
🏠
Working from home

PJZ9n PJZ9n

🏠
Working from home
View GitHub Profile
@PJZ9n
PJZ9n / convert_hash.rb
Last active October 4, 2022 20:03
ドット区切り文字列がキーのハッシュを連想ハッシュに変換する
hash_input = {"a.b" => "value", "a.c" => "hoge", "b.1" => "a", "a.b.c" => "aa"}
hash_output = {}
ENABLE_OVERRIDE = true
hash_input.each do |key, value|
key_splits = key.split(".")
current_hash = hash_output
key_splits_tmp = key_splits.dup
key_splits_tmp.delete_at(key_splits.size - 1) # remove last value
@PJZ9n
PJZ9n / suspend.rb
Created March 29, 2021 00:35
サーバーID一覧データから当てはまらないものはサスペンドする
require "csv"
sql = 'UPDATE servers SET status="suspended" WHERE status IS NULL'
CSV.foreach("test.csv") do |row|
sql += ' AND NOT uuidShort="' + row[0] + '"'
end
puts sql
@PJZ9n
PJZ9n / get_words_from_csv.rb
Created February 5, 2021 22:34
CSVから禁止ワードのリストを生成する http://monoroch.net/kinshi/kinshi.csv
require "csv"
words = []
CSV.foreach("test.csv") do |row|
words << row[0] unless row[0].nil?
words << row[1] unless row[1].nil?
words << row[2] unless row[2].nil?
end
@PJZ9n
PJZ9n / db.rb
Last active January 15, 2021 10:53
RubyでSQLite3を使ってみる
require 'sqlite3'
DB_FILE_NAME = "test.db"
$db = SQLite3::Database.new(DB_FILE_NAME)
# 初期化(テーブル作成)
def init
sql = <<~'SQL'
CREATE TABLE IF NOT EXISTS users(
@PJZ9n
PJZ9n / TargetBlock.php
Created December 4, 2020 21:21
見ているブロックを取得する
<?php
/**
* @name TargetBlock
* @version 1.0.0
* @main pjz9n\test\targetblock\Main
* @api 3.0.0
*/
declare(strict_types=1);
<div class="container-fluid py-4">
<div class="row">
<div class="col-sm-7 col-lg-9 order-sm-2">
<div class="card bg-dark border-dark rounded-lg">
<div class="card-header bg-info">
<h3 class="card-title">Foobar</h3>
</div>
<div class="card-body">
<div class="container py-2">
<div class="card bg-dark border-dark">
<header>
<nav>
<% if user_signed_in? %>
<%= current_user.confirmation_token %>
<strong><%= link_to current_user.email %></strong>
<%= link_to 'プロフィール変更', edit_user_registration_path %>
<%= link_to 'ログアウト', destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to 'サインアップ', new_user_registration_path %>
<%= link_to 'ログイン', new_user_session_path %>
<div class="text-center">
<div class="container">
<%= bootstrap_form_with url: '/test1' do |f| %>
<%= f.email_field :email %>
<%= f.password_field :password %>
<%= f.check_box :remember_me %>
<br>
<%= invisible_recaptcha_tags text: '<i class="fas fa-paper-plane"></i> 送信', class: 'btn btn-success' %>
<% end %>
</div>
@PJZ9n
PJZ9n / test.php
Created September 26, 2020 16:03
pmformsでオートコンプリート実装例(非公式ブランチ)
<?php
use dktapps\pmforms\CustomForm;
use dktapps\pmforms\CustomFormResponse;
use dktapps\pmforms\element\Input;
use pocketmine\Player;
$form = new CustomForm(
"example",
[
@PJZ9n
PJZ9n / ExampleForm.php
Last active September 21, 2020 19:47
pmformsを使ったクラスベースのModalFormとそれの実装
<?php
declare(strict_types=1);
namespace pjz9n\classbasedpmforms;
use pocketmine\Player;
class ExampleForm extends ModalForm
{