This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 簡単なプログラミング問題でトランプソートというのを考えた。(というかもうありそう) | |
// トランプ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の順になるように並び替える。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 日記を簡単に書けるように設定する | |
;;;; 日記を保存しておくディレクトリを設定 | |
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# includesでentriesとそれに紐づくcommentsをロードしておく。 | |
# そうすることで以後の処理でentriesとそれに紐づくcommentsを取得するさいに | |
# 毎回SQLを発行することを防ぐ。 | |
# | |
# includesのかわりにjoinsを使うと事前ロードはされないため、 | |
# 以後の処理でSQLが吐かれてしまうので注意する。 | |
# | |
blog = Blog.includes(:entries => :comments).find_by_id(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserController < ApplicationController | |
def show | |
begin | |
@user = User.find(9999) | |
rescue ActiveRecord::RecordNotFound => e | |
# 翻訳処理を書く。 | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uniq_rand_ary(size) | |
ary1 = [] | |
ary2 = [] | |
size.times do |i| | |
ary1 << i | |
end | |
count = ary1.size | |
count.times do |c| |