Skip to content

Instantly share code, notes, and snippets.

View usutani's full-sized avatar

Yasuhiro Usutani usutani

  • Kobe, Hyogo, Japan
View GitHub Profile
@usutani
usutani / Factorial.playground
Last active August 29, 2015 14:10
Factorial.playground
func factorial(n : Int) -> Int {
if (n > 0) {
return n * factorial(n - 1)
} else {
return 1
}
}
factorial(20)
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Mail server for receiving",
"Parameters" : {
"MailServerDomain" : {
"Type" : "String",
"Default" : "mail.example.com",
"Description" : "mail server domain"
},
@usutani
usutani / terminate.cs
Created January 6, 2019 06:47 — forked from jvshahid/terminate.cs
C# terminating a child process (as opposed to killing, i.e. sigkill vs. sigint on linux)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TestCtrlEvent
@usutani
usutani / note_serve_rails_prod_alone.md
Created May 21, 2020 04:32
覚書: Rails単体production環境での動作確認

環境

macOS 10.15.4 Ruby 2.7.1 Rails 6.0.3.1 Yarn 1.22.4 Node 13.12.0

確認用アプリの作成

rails new app_name cd app_name

@usutani
usutani / application.js
Last active January 17, 2021 04:43
Tailwind CSSの習作: Rails scaffold.scssの移植
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("./application.scss")
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tailwind CSS Modal</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<div class="flex flex-col">
<div class="bg-blue-500 m-3 py-20 px-4">text</div>
@usutani
usutani / ch6_bicyle.rb
Created June 13, 2020 01:46
オブジェクト指向設計実践ガイド 6章 キーワード引数版
# frozen_string_literal: true
class Bicycle
attr_reader :size, :chain, :tire_size
def initialize(**kwargs)
@size = kwargs[:size]
@chain = kwargs[:chain] || default_chain
@tire_size = kwargs[:tire_size] || default_tire_size
post_initialize(**kwargs)
@usutani
usutani / ch9_trip.rb
Last active June 14, 2020 06:48
オブジェクト指向設計実践ガイド 9章 ダックタイプをテストする
# frozen_string_literal: true
class Trip
def prepare(preparers)
# ...
preparers.each do |preparer|
preparer.prepare_trip(foo: self)
end
@usutani
usutani / try_routing.rb
Last active December 22, 2020 08:10
Rails: 覚書: DHH流のルーティング
# メッセージコントローラに下書き用のコントローラを追加する。
# サブリソースのフィルタリング index # 下書き一覧を表示する
# サブリソースのアクション create # 下書きにする、destroy # 清書にする
# confing/routes.rb
Rails.application.routes.draw do
namespace :messages do
resources :drafts, only: :index
end
resources :messages do
resource :draft, only: %i[create destroy], module: 'messages'
@usutani
usutani / application_helper.rb
Last active December 26, 2020 07:52
Rails: Hotwire: button_to(delete)の見た目をlink_toに変更する
module ApplicationHelper
def form_data_window_confirm(message)
{
'data-controller' => 'window_confirm',
'data-window_confirm-message-value' => message,
'data-action' => 'window_confirm#show'
}
end
end