Skip to content

Instantly share code, notes, and snippets.

View ChangJoo-Park's full-sized avatar
:octocat:
🌱

ChangJoo Park(박창주) ChangJoo-Park

:octocat:
🌱
View GitHub Profile
@ChangJoo-Park
ChangJoo-Park / seoulweather_wundergorund.html
Created November 23, 2012 05:11
서울시 날씨 정보 예제
<!DOCTYPE html>
<html>
<head>
<title>서울시 날씨정보-wunderground API이용</title>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
@ChangJoo-Park
ChangJoo-Park / analyzer.rb
Last active December 10, 2015 03:28
oliver.txt파일을 읽어 파일의 내용을 분석한다. 전체 길이, 글자수(공백 유무), 단어, 문장, 문단의 수를 분석
# encoding: utf-8
lines=File.readlines("oliver.txt")
line_count=lines.size
text=lines.join
total_character=text.length
total_character_no_whitespace=text.gsub(/\s+/,'').length
word_count=text.split.length
paragraph_count=text.split(/\n\n/).length
sentence_count=text.split(/\.|\!|\?/).length
puts "전체 길이 : #{line_count}"
@ChangJoo-Park
ChangJoo-Park / stop_wods.rb
Last active December 10, 2015 03:28
불용어를 제외하고 보여줌
# encoding: utf-8
# Stop_words 2012-12-26
stop_words = %w{the a by on for of are with just but and to the my I has some in}
text=%q{Korea is officially the only divided nation in the world.}
words = text.scan(/\w+/)
key_words = words.select { |word| !stop_words.include?(word)}
puts "문장 중 키워드의 비율은 : #{((key_words.length.to_f/words.length.to_f)*100).to_i}%"
puts key_words.join(' ')
@ChangJoo-Park
ChangJoo-Park / current_user.rb
Created January 14, 2013 17:58
||= 를 사용하면 동일한 내용이 있는 경우 다시 쿼리를 하지 않음
def current_user
@current_user ||= User.find(session[:user_id])
end
@ChangJoo-Park
ChangJoo-Park / TaskController.rb
Created January 14, 2013 18:12
find를 find_by_all 로 바꾸면 더 간단하다
class TaskController < ApplicationController
def incomplete
@tasks = Task.find(:all, :conditions => ['complete = ?', false])
end
def last_incomplete
@task = Task.find(:first, :conditions => ['complete =?', false], :order => 'created_at DESC')
end
end
@ChangJoo-Park
ChangJoo-Park / helloworld.rb
Created April 10, 2013 14:26
Ruby Hello World!
=begin 문자열 출력해보기
** 문서는 루비 2.0.0-p0 버전의 Ruby core API 기반의 메소드를 사용합니다.**
** 작성자 정보
** 박창주
** pcjpcj2@gmail.com
** http://parkcj.wordpress.com
** 2013-04-07
single quotation vs double quotation
'' "" 차이를 알아보자
우선 puts 문자열을 출력하는 함수이다.
@ChangJoo-Park
ChangJoo-Park / use_number.rb
Created April 10, 2013 14:45
루비에서 문자열 안에서 코드를 출력하여 봅니다.
=begin
** 문서는 루비 2.0.0-p0 버전의 Ruby core API 기반의 메소드를 사용합니다.**
** 작성자 정보
** 박창주
** pcjpcj2@gmail.com
** http://parkcj.wordpress.com
** 2013-04-07
예를 들어 특정 횟수만큼 문장을 반복할 일이 생긴다면
어떻게 해야할까?
-> 1. 1번의 Hello World! 출력해보자
@ChangJoo-Park
ChangJoo-Park / for_end.rb
Created April 10, 2013 14:45
for ~in 메소드를 이용하여 오감도 제 1호를 출력합니다.
=begin
** 문서는 루비 2.0.0-p0 버전의 Ruby core API 기반의 메소드를 사용합니다.**
** 작성자 정보
** 박창주
** pcjpcj2@gmail.com
** http://parkcj.wordpress.com
** 2013-04-07
이상 시인의 오감도 1호를 작성하여 보자
시의 전문 :
오감도(烏瞰圖) 제1호
@ChangJoo-Park
ChangJoo-Park / more_string.rb
Created April 17, 2013 13:35
String Class의 사용법을 알아봅니다. http://ruby-doc.org/core-1.9.3/String.html
# encoding: utf-8
=begin
** 문서는 루비 1.9.3-p392 버전의 Ruby core API 기반의 메소드를 사용합니다.**
** 작성자 정보
** 박창주
** pcjpcj2@gmail.com
** http://parkcj.wordpress.com
** 2013-04-07
조금 문자열에 대해서 알아보자.
@ChangJoo-Park
ChangJoo-Park / input_output_num.rb
Last active December 16, 2015 08:18
숫자를 입력받아 for 반복문을 사용합니다.
# encoding: utf-8
=begin
** 문서는 루비 2.0.0-p0 버전의 Ruby core API 기반의 메소드를 사용합니다.**
** 작성자 정보
** 박창주
** pcjpcj2@gmail.com
** http://parkcj.wordpress.com
** 2013-04-07
이상의 오감도 1 계속