Skip to content

Instantly share code, notes, and snippets.

@hara-y-u
hara-y-u / week_index_in_month.rb
Created January 10, 2025 05:15
Calculate week index in month / Rubyで特定日が何番目の週か計算
require "date"
# Days from day one to first saturday are result in index 1
def week_index_in_month(date)
first_day_of_month = Date.new(date.year, date.month, 1)
((date.day + first_day_of_month.wday) / 7.0).ceil
end
# Days from day one to seven are result in index 1
def week_index_in_month(date)
@hara-y-u
hara-y-u / soc_with_custom_callbacks.rb
Last active January 9, 2025 14:24
Separation of Concerns with Rails ActiveRecord custom callbacks
module Commentable
extend ActiveSupport::Concern
included do
has_many :comments
define_model_callbacks :comment_update, only: :after
end
end
class Post
@hara-y-u
hara-y-u / sequential_id.rb
Last active June 8, 2024 07:53
Scoped Sequential ID Concern for Rails Models
# Usage:
# This module adds single scoped sequential id on AR model.
# In your model, include this module like:
# include SequentialId[:number, scope: :user_id]
module SequentialId
def self.[](column_name, scope:)
options = Struct.new(:column_name, :scope)
Module.new do
extend ActiveSupport::Concern
include SequentialId
@hara-y-u
hara-y-u / 0_reuse_code.js
Created November 20, 2015 15:31
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hara-y-u
hara-y-u / shinchoku.coffee
Last active August 29, 2015 13:56
進捗どうですか? on Hubot
# put in scripts/shinchoku.coffee
# add "tumblr": "~0.4.0" on package.json -> "dependencies"
tumblr = require 'tumblr'
util = require 'util'
auth =
# Set these on environment variables
consumer_key: process.env['TUMBLR_CONSUMER_KEY']
consumer_secret: process.env['TUBMLR_CONSUMER_SECRET']
token: process.env['TUMBLR_TOKEN']
@hara-y-u
hara-y-u / find-outdated-docs.sh
Last active January 2, 2016 17:19
find out dated files for enja-oss/stylus
#!/bin/bash
ORIG_DIR='./stylus_orig'
CLONE_TO='git clone https://github.com/LearnBoost/stylus.git'
LIST_DOCS='git ls-tree --name-only HEAD docs/'
LAST_TIME='git log -1 --pretty=format:%ct'
LAST_TIME_F='git log -1 --pretty=format:%cr'
DEV=false
${CLONE_TO} ${ORIG_DIR} > /dev/null 2>&1
@hara-y-u
hara-y-u / bifs.diff
Last active January 2, 2016 16:29
enja-oss/stylus out dated files(2013-1-9)
diff --git a/docs/bifs.md b/docs/bifs.md
index 57a6c5c..9f420ad 100644
--- a/docs/bifs.md
+++ b/docs/bifs.md
@@ -19,7 +19,7 @@ Return the green component of the given `color`.
Return the blue component of the given `color`.
- red(#00c)
+ blue(#00c)
@hara-y-u
hara-y-u / Gemfile
Last active December 31, 2015 20:39
test for rails-sass-source-maps
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
@hara-y-u
hara-y-u / Vagrantfile
Last active December 27, 2015 11:09
Conf file for hosting yukihr.github.io/fjord_intern on Debian wheezy on VirtualBox with nginx.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "wheezy"
カレーのレシピ
誰でもできる、美味しいカレーの作り方です。旦那も息子もこのカレーが大好物。
ポイントは玉ねぎと人参はミキサーで細かくしてしまうところ。逆にコクのある美味しいカレーになります。
レシピの作者
山田サチ子さん
材料 ( 8皿分 )