Skip to content

Instantly share code, notes, and snippets.

View axtutuu's full-sized avatar
🦄
On vacation

Kawasaki Atsushi axtutuu

🦄
On vacation
View GitHub Profile
@axtutuu
axtutuu / 0_reuse_code.js
Created April 21, 2016 01:27
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
@axtutuu
axtutuu / model.rb
Last active October 3, 2016 02:52
ActiveRecordで取得したデータをカスタマイズしてJSONで返却
class Model < ActiveRecord::Base
has_many :users
def as_json(options={})
super.as_json(options).merge({users: self.users})
end
end
@axtutuu
axtutuu / errors_controller.rb
Last active October 4, 2016 12:06
Ruby on Railsのエラーハンドリング
class ErrorsController < ActionController::Base
NOT_FOUND = 404
STANDARD_ERROR = 500
rescue_from StandardError, with: :error_500
rescue_from AbstractController::ActionNotFound, with: :render_404
rescue_from ActionController::RoutingError, with: :render_404
layout false
@axtutuu
axtutuu / Gemfile.rb
Created October 5, 2016 01:41
New Relic Set Up on Ruby on Rails
gem 'newrelic_rpm'
@axtutuu
axtutuu / hoge_model.rb
Last active October 5, 2016 06:42
マッチした attributes を配列で取り出す
class HogeModel
# fugaにマッチしたカラムの返却
def fuga_columns
self.attributes.keys.select { |a| a.match(/fuga/) }
end
end
@axtutuu
axtutuu / aec_cipher.rb
Created October 7, 2016 03:08
Ruby DES-ECB & PKCS5Padding で暗号化
# 暗号モード: ECB
# パディング方式: PKCS5Padding
# OpenSSL::Cipher.ciphers で利用可能な暗号方式名を取得可能
# https://docs.ruby-lang.org/ja/latest/class/OpenSSL=3a=3aCipher.html
module AesCipher extend self
KEY = "Your key"
CIPHER = "DES-ECB"
def encrypt(text)
@axtutuu
axtutuu / filter_parameter_logging.rb
Created October 21, 2016 09:48
Railsのlog フィルダリング方法
# config/initializers/filter_parameter_logging.rb
Rails.application.config.filter_parameters += [:password]
@axtutuu
axtutuu / cron.sh
Created November 21, 2016 13:31
crontabメモ
# 書き方
分 時 日 月 曜日 コマンド
# 曜日
# 0, 7 => 日曜日
# 1 ~ 6 => 月曜日 ~ 金曜日
# cron一覧を確認 crontab -l
# cronの削除 crontab -r ※警告なしに全て消えるので注意
@axtutuu
axtutuu / .vimrc
Created November 21, 2016 14:30
vimrc
"------------------------------------------------
" プラグインのインストール
"------------------------------------------------
filetype plugin indent off
if has('vim_starting')
set runtimepath+=~/.vim/bundle/neobundle.vim
call neobundle#begin(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
@axtutuu
axtutuu / Gemfile
Last active November 24, 2016 07:09
tweet取得
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem "oauth"
gem "dotenv"
gem "pry"
# for active_support/core_ext
gem "rails"