Skip to content

Instantly share code, notes, and snippets.

View Arakaki-Yuji's full-sized avatar
🏠
Working from home

Arakaki Yuji Arakaki-Yuji

🏠
Working from home
View GitHub Profile
@Arakaki-Yuji
Arakaki-Yuji / thisweek.rb
Created September 17, 2019 01:29
今週月曜日の日付 ~ 今週日曜日の日付を出力する
# coding: utf-8
#!/bin/sh
exec ruby -x "$0" "$@"
#!ruby
require 'date';
today = Date.today;
if(today.cwday == 1) then
this_week_monday = today;
else
// 簡単なプログラミング問題でトランプソートというのを考えた。(というかもうありそう)
// トランプ1枚のデータ構造はtypeとnumberをキーに持つobject
SampleTrunmpCard = { "type" => "heart", number => 1 };
// typeは"heart"、"diamond", "club", "spade"の4種類
// numberは1~13まである。
// トランプの数は合計52枚
// ランダムに並べられているトランプをheartの1~>13,diamondの1~>13,clubの1~>13,spadeの1~>13の順になるように並び替える。
;; 日記を簡単に書けるように設定する
;;;; 日記を保存しておくディレクトリを設定
(setq diary-note-path "~/Dropbox/TextSync/Diary/")
;;;; 今日の日記ファイルのパスを返す
(defun diary-today-note ()
(concat diary-note-path (format-time-string "%Y/%m/%d") ".md"))
;;;; 今日の日記ファイルを開く or なければ作成する
(defun diary-open-today-note ()
(interactive)
@Arakaki-Yuji
Arakaki-Yuji / gist:766cc54ed18ba859881a
Last active July 11, 2020 10:18
RailsのActiveRecordで親要素から孫要素を参照する場合
#
# includesでentriesとそれに紐づくcommentsをロードしておく。
# そうすることで以後の処理でentriesとそれに紐づくcommentsを取得するさいに
# 毎回SQLを発行することを防ぐ。
#
# includesのかわりにjoinsを使うと事前ロードはされないため、
# 以後の処理でSQLが吐かれてしまうので注意する。
#
blog = Blog.includes(:entries => :comments).find_by_id(1)
@Arakaki-Yuji
Arakaki-Yuji / file0.rb
Last active August 29, 2015 14:15
ActiveRecord::RecordNotFoundのエラーメッセージを翻訳する ref: http://qiita.com/arakaji/items/7a7c262f35b17195d3d7
class UserController < ApplicationController
def show
begin
@user = User.find(9999)
rescue ActiveRecord::RecordNotFound => e
# 翻訳処理を書く。
end
end
end
@Arakaki-Yuji
Arakaki-Yuji / application.rb
Created December 25, 2014 15:52
APIファーストでバックエンドとフロントエンドを別々に開発する時にハマるクロスドメインアクセス ref: http://qiita.com/arakaji/items/f7d32e1c94d67b3e2606
module YourApp
class Application < Rails::Application
# ...
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins 'your_app_domain'
resource '*', :headers => :any, :methods => [:get, :post, :put, :delete, :options]
end
@Arakaki-Yuji
Arakaki-Yuji / uniq_rand_ary.rb
Created October 8, 2012 07:53
making array that filled the numbers, these are random and uniq.
def uniq_rand_ary(size)
ary1 = []
ary2 = []
size.times do |i|
ary1 << i
end
count = ary1.size
count.times do |c|