Skip to content

Instantly share code, notes, and snippets.

seiyamaeda seiyamaeda

View GitHub Profile
@seiyamaeda
seiyamaeda / hoge_custom_validatior.js
Last active Aug 22, 2018
The validation for input type number(n>=0) by JavaScript
View hoge_custom_validatior.js
// 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/)) {
@seiyamaeda
seiyamaeda / hoge.php
Created Aug 14, 2018
Extract some code, Specific post tag, WordPress
View hoge.php
<?php $posttags = get_the_tags(); if ($posttags) { $key = array_search($posttags, 'TAG_NAME'); $posttags[$key]; ?>
<!-- something do -->
<?php } ?>
@seiyamaeda
seiyamaeda / app|lib|hoges|hoge_hoge.rb
Last active Jun 29, 2018
Get the increment of time (string), increment 30 mins
View app|lib|hoges|hoge_hoge.rb
def get_hoge_times
48.times.map.each_with_index {|i| (Time.parse('0:00') + 30.minutes * i).strftime('%H:%M')}
end
@seiyamaeda
seiyamaeda / app|assets|javascripts|hoge.js
Last active Jun 29, 2018
Get the name of controller, from JS
View app|assets|javascripts|hoge.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
}
View app|controllers|application_controller.rb
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
@seiyamaeda
seiyamaeda / CLI
Last active Apr 9, 2018
How to install MongoDB in CentOS7
View CLI
#############################################################################
# via: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ #
# via: https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/ #
# via: https://qiita.com/SOJO/items/dc5bf9b4375eab14991b #
#############################################################################
$ vi /etc/yum.repos.d/mongodb-org-3.6.repo
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
@seiyamaeda
seiyamaeda / MONGOID.md
Last active Apr 7, 2018
How to use 'Mongoid' gem
View MONGOID.md

ADE

$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

$ bundle exec rails -v
Rails 5.1.4
@seiyamaeda
seiyamaeda / CLI
Last active Apr 6, 2018
Update select box when another one is updated. / E.g. Hoge and Fuga are 'one-to-many relationship', and use a controller 'Piyo' without this association .
View CLI
$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
$ bundle exec rails -v
Rails 5.1.4
@seiyamaeda
seiyamaeda / CLI
Last active Apr 6, 2018
How to install Vue.js on Webpacker
View CLI
$ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
$ bundle exec rails -v
Rails 5.1.4
$ yarn -v
1.5.1
$ bundle install
@seiyamaeda
seiyamaeda / Gemfille
Last active Apr 3, 2018
Post a message to 'alert' channel in Slack
View Gemfille
gem 'json'
gem 'faye-websocket'
gem 'eventmachine'
gem 'slack-ruby-client'
You can’t perform that action at this time.