Skip to content

Instantly share code, notes, and snippets.

View negabaro's full-sized avatar

kim negabaro

View GitHub Profile
cnt =0
inputs = []
while str = STDIN.gets
inputs << str.to_i
end
inputs.each do |i|
inputs2 = inputs.dup
inputs2.delete(i)
env_check() {
if [ -n "$SLAVE_DB_NAME" ] && \
[ -n "$SLAVE_DB_USER" ] && \
[ -n "$SLAVE_DB_PASSWORD" ] && \
[ -n "$SLAVE_DB_HOST" ] && \
[ -n "$DB_NAME" ] && \
[ -n "$DB_USER" ] && \
[ -n "$DB_PASSWORD" ] && \
[ -n "$DB_HOST" ] && \
[ -n "$RAILS_ENV" ];
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@negabaro
negabaro / rails-controller.txt
Last active September 19, 2017 14:02
CRUD simple noticeboard with rails5.1
app/controller/articles_controller.rb
class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]
def show
end
def edit
@negabaro
negabaro / check_rspec_enable.sh
Created October 6, 2017 11:20
不要なRSPEC省略
#echo "export RSPEC_ENABLE=0" >> ~/.bashrc
should_run_rspec(){
echo "You Should Run RSPEC Test"
sed -i 's/export RSPEC_ENABLE=0/export RSPEC_ENABLE=1/g' ~/.bashrc
}
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD)"
check_file() {
for var in $changed_files
#app/models/user.rb
def self.find_for_twitter_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
unless user
user = User.create(user_nickname: auth.info.nickname,
provider: auth.provider,
uid: auth.uid,
email: User.create_unique_email,
password: Devise.friendly_token[0,20]
)
@negabaro
negabaro / aasm-articles_controller.rb
Created October 17, 2017 20:52
Rails AASM controller example
def create
@article = current_user.articles.build(article_params)
if @article.valid?
@article.save!
case params[:ope][:cmd]
when 'publish'
@article.publish!
puts "hi this is publish zone"
flash[:success] = '記事を公開しました。'
@negabaro
negabaro / model-article.rb
Created October 17, 2017 20:54
Rails AASM model example
include AASM
aasm do
state :draft, :initial => true
state :published
#event :publish, before: ->{ self.published_at = Time.now } do
event :publish do
transitions :from => :draft, :to => :published
@negabaro
negabaro / view-form.html.haml
Created October 17, 2017 20:55
Rails AASM view example
= bootstrap_form_for(@article, layout: :horizontal) do |f|
= f.text_field :title, autofocus: true
= f.text_area :body_source, rows: 20
.form-group
.col-sm-offset-2.col-sm-10
= f.button '下書きを保存', name: 'ope[cmd]', value: 'save', class: 'btn btn-lg btn-default'
- if @article.draft?
= f.button '公開する', name: 'ope[cmd]', value: 'publish', class: 'btn btn-lg btn-default'
@negabaro
negabaro / css
Last active December 10, 2017 15:08
weekCalendar
.wrap {
width: 500px;
margin: 0 auto;
}
.btn-holder {
text-align: center;
margin: 10px 0 10px 0;
}
#calendar table {
border-collapse: collapse;