Skip to content

Instantly share code, notes, and snippets.

View maecha's full-sized avatar
🏠
Working from home

Maechan maecha

🏠
Working from home
View GitHub Profile
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
if Rails.env.production? || Rails.env.staging?
# 他のエラーハンドリングでキャッチできなかった場合に
# 500 Internal Server Error(システムエラー)を発生させる
rescue_from Exception, with: :handle_500
@maecha
maecha / app|assets|javascripts|hoge.js
Last active June 29, 2018 01:51
Get the name of controller, from JS
getControllerName() {
// Ex) DOMAIN.com/NAME_SPACE/CONTROLLER_NAME/ACTION
var pathname = window.location.pathname; // /NAME_SPACE/CONTROLLER_NAME/ACTION
let splitedPathnames = pathname.replace(/\//, ''); // [ 'NAME_SPACE', 'CONTROLLER_NAME', 'ACTION' ]
return splitedPathnames.split('/')[1]; // CONTROLLER_NAME
}
@maecha
maecha / app|lib|hoges|hoge_hoge.rb
Last active June 29, 2018 08:21
Get the increment of time (string), increment 30 mins
def get_hoge_times
48.times.map.each_with_index {|i| (Time.parse('0:00') + 30.minutes * i).strftime('%H:%M')}
end
@maecha
maecha / hoge_custom_validatior.js
Last active August 22, 2018 04:14
The validation for input type number(n>=0) by JavaScript
// KUSO-CODE
export class HogeCustomValidatior {
positiveIntegerValidatator() {
let elm1 = document.getElementById('number_hoge1');
let elm2 = document.getElementById('number_hoge2');
let elms = [elm1, elm2];
elms.forEach(function (elm) {
elm.addEventListener('change', function(event){
if (event.target.value.match(/\D/)) {
@maecha
maecha / hoge.php
Created August 14, 2018 04:02
Extract some code, Specific post tag, WordPress
<?php $posttags = get_the_tags(); if ($posttags) { $key = array_search($posttags, 'TAG_NAME'); $posttags[$key]; ?>
<!-- something do -->
<?php } ?>