Skip to content

Instantly share code, notes, and snippets.

View luciuschoi's full-sized avatar

Lucius Choi luciuschoi

View GitHub Profile
@luciuschoi
luciuschoi / self_number.rb
Created October 29, 2014 07:00
ruby playground
self_number=[]
arr_number = []
5000.times do | i |
real_number = i + 1
temp_str = real_number.to_s
str_len = temp_str.length
sum = 0
str_len.times do | j |
sum += temp_str[j].to_i
end
@luciuschoi
luciuschoi / devise_invitable.ko.yml
Last active August 29, 2015 14:27
devise_invitable locale for Korean
ko:
devise:
failure:
invited: "귀하께로 초대장이 발부되었습니다. 초대를 수락하면 계정을 생성할 수 있습니다. "
invitations:
send_instructions: "초대 이메일이 %{email}에게로 발송되었습니다."
invitation_token_invalid: "제공된 초대장 토큰이 유효하지 않습니다!"
updated: "비밀번호가 성공적으로 설정되었으며, 현재 로그인 상태입니다."
updated_not_active: "비밀번호가 성공적으로 설정되었습니다."
no_invitations_remaining: "남은 초대장이 없습니다."
@luciuschoi
luciuschoi / simple_form.ko.yml
Created August 17, 2015 09:44
simple_form locale for Korean
ko:
simple_form:
"yes": '예'
"no": '아니오'
required:
text: '필수항목'
mark: '*'
# You can uncomment the line below if you need to overwrite the whole required html.
# When using html, text and mark won't be used.
# html: '<abbr title="required">*</abbr>'
#!/bin/sh
# A Ubuntu 14.04 install aimed for Ruby on Rails development
# This box start with a basic Ubuntu 14.04 (trusty) based on phusion/ubuntu-14.04-amd64
# And it adds the following packages aimed for rails development
# - rbenv and ruby-build
# - ruby 2.1.2 with bundler
# - Git 1.9.1
class User < ActiveRecord::Base
has_many :posts
has_many :shares
has_many :shared_posts, class_name: 'Post', through: :shares, source: :post
end
class Share < ActiveRecord::Base
belongs_to :user
belongs_to :post
end
# 먼저 원격 우분투 서버로 접속한 후 mysql을 설치한다.
# 그리고, 아래와 같이 root계정으로 mysql에 접속한다.
```
$ mysql -u root -p
```
아래의 명령을 실행하여 데이터베이스 및 배포용 유저를 생성하고 모든 권한 부여 한다.
== Coffe File
ready = ->
sendFile = (file) ->
data = new FormData
data.append 'content_image[image]', file
$.ajax
data: data
type: 'POST'
url: '/api/uploads'

Soft Delete of Table Record

###1. Migration Class for Adding Some Delete Flags

$ rails g migration add_deleted_to_purchase_requests deleted:boolean deleted_at:datetime deleted_by:references

###2. Modification of Migration Class for Adding Foreign Key

# 감사합니다...!
# 1. Club.all.select{|k| k.memberships.count < k.max_number}
# 2. club.unconfirmed_applications.map(&:user)
# 1에 해당하는 클럽들에 대해 2번을 적용한 유저정보(특히 user.phone_number)를 추출하려면 어떻게 해야 할까요?
class Club < ApplicationRecord
scope :recruiting, -> { select{ | club | club.memberships.count < club.max_number } }
@luciuschoi
luciuschoi / schema.rb
Last active September 28, 2016 21:08
Normalization of Club Model...
# clubs 테이블을 이와 같이 중복되는 부분을 sesons 테이블로 빼내고 club_seasons 라는 join 테이블 만들면 어떨까요?
create_table "clubs", force: :cascade do |t|
t.string "name"
t.text "description"
t.string "type"
t.string "image"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "report_length_limit", default: 400