Skip to content

Instantly share code, notes, and snippets.

@kzkn
kzkn / example2_controller.js
Created October 19, 2021 04:16
stimulus controller lifecycle
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
initialize() {
this.log('initialize')
}
connect() {
this.log('connect')
}
@kzkn
kzkn / simple_form_association_collection.rb
Created March 18, 2021 15:11
simple_form の association メソッドで collection を未指定な場合に警告する rubocop
module RuboCop
module Cop
module FooBar
class SimpleFormAssociationCollection < Base
MSG = 'Specify the `collection` option'.freeze
def_node_matcher :has_association_call?, <<~PATTERN
(block
(send _ :simple_form_for ...)
(args (arg _f))
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Include Choices CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/styles/choices.min.css" />
<!-- Include Choices JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/scripts/choices.min.js"></script>
</head>
class WordFilter
def initialize(words)
@root = Node.new
words.each.with_index do |w, weight|
(0..w.size).each do |len|
s = "#{w[-len, len]}@#{w}"
@root.add_word(weight, s, 0)
end
end
end
# @param {Character[][]} board
# @param {String[]} words
# @return {String[]}
def find_words(board, words)
root = Node.new
words.each do |w|
root.add_word(w)
end
b = Board.new(board)
class WordDictionary
def initialize
@root = Node.new
end
def add_word(word)
@root.add_word(word, 0)
end
def search(word)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Include Choices CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/styles/choices.min.css" />
<!-- Include Choices JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/public/assets/scripts/choices.min.js"></script>
</head>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Include Choices CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css">
<!-- Include Choices JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
</head>
<body>
@kzkn
kzkn / init.el
Created March 14, 2019 13:59
ssass-mode を使いやすくする
(defun ssass-indent ()
"Indent the current line."
(interactive)
(indent-line-to
(cond
((and (not ssass-indent-blanks) (ssass--whitespace-p 0)) 0)
((ssass--whitespace-p -1) 0)
((ssass--no-anchor-line-p) 0)
((ssass--comma-before-p) (ssass--last-anchor-line-indent-level))
;; ここが増えた。セレクタ行は自動インデントしない
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
port: 54394
development: