'전체 글'에 해당되는 글 68건

  1. 2010.07.20 Python Expression For Nuke.
  2. 2010.07.14 Rails 에서 업로드 컴포넌트로 플래쉬를 사용할 경우에.
  3. 2010.07.09 ruby에서 UTF-8 문자열을 EUC-KR 로 변환하는 방법.
  4. 2010.06.28 Rails 에서 정말 간편한 Helper 함수들 목록.
  5. 2010.06.26 QT4 VS2008 Installer
  6. 2010.06.25 QT4 프로그래밍에서 한글 입출력 관련..
  7. 2010.06.10 inplace select 에 필드추가 기능 넣기
  8. 2010.06.10 Super inplace controls의 사용.
  9. 2010.06.08 PaperClip 사용방법.
  10. 2010.06.03 QT4에서 SLOT 을 선언하는 방버.
  11. 2010.05.31 CUDA Tips #1.
  12. 2010.05.27 QT4 With Visual Studio x64 1
  13. 2009.03.23 CentOS 5.2 에서 rails 설치.
  14. 2009.03.05 JQuery 기본적인 사용방법.
  15. 2009.03.05 Rails 에서 JQuery와 Prototype 을 함께 사용하는 방법 #2
  16. 2009.02.19 Rails 에서 Prototype 과 JQuery 를 동시에 사용하기.
  17. 2009.02.16 ActiveRecord 정렬하는 방법.
  18. 2009.01.29 Ajax 에서 로딩중인 이미지를 만들어 보자~
  19. 2009.01.28 꽤 쓸모가 있을 만한 Rounded Corner CSS
  20. 2009.01.28 Activescaffold 에서 rounded corner 를 사용하는 방법.

Python Expression For Nuke.


사용하기 전에 일단 init.py 파일에서 nuke.load 를 통해서 등록을 해주면 된다.
그러면 해당 파이썬 함수를 익스프레션으로 사용할 수 있다.

그리고 init.tcl 파일도 있는데 이것은 같은 디렉토리 내의 모든 tcl 파일들을 자동으로 포함한다.
그래서 tcl 파일은 걍 복사만으로도 실행이 된다.

Rails 에서 업로드 컴포넌트로 플래쉬를 사용할 경우에.

엄청 많은 삽질을 통해서...

이거 제대로 다들 알고 있지 못하는듯 하다. -_-

multiple file upload with rails. (fancyupload)

ActionController::InvalidAuthenticityToken
에러로 무지하게 고생을 했으나.

ApplicationController 에서 기본적으로 사용하는 인증 토큰 부분을 없애버려서 잘 사용하고 있다.

class ApplicationController < ActionController::Base

  helper :all # include all helpers, all the time

  #protect_from_forgery # See ActionController::RequestForgeryProtection for details

  self.allow_forgery_protection = false

  # Scrub sensitive parameters from your log

  # filter_parameter_logging :password

  

  layout "application"

end




'OLD POSTS' 카테고리의 다른 글

OGRE3D for iPhone.  (0) 2010.08.26
Python Expression For Nuke.  (0) 2010.07.20
ruby에서 UTF-8 문자열을 EUC-KR 로 변환하는 방법.  (0) 2010.07.09
Rails 에서 정말 간편한 Helper 함수들 목록.  (0) 2010.06.28
QT4 VS2008 Installer  (0) 2010.06.26

ruby에서 UTF-8 문자열을 EUC-KR 로 변환하는 방법.

require "iconv"

Iconv.new('EUC-KR', 'UTF-8').iconv(string)



Rails 에서 정말 간편한 Helper 함수들 목록.


http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M000423

Rails 의 Helper 함수들.

테이블 리스트로 출력시 cycle('odd', 'even') 이건 정말이지. 짱이삼.!

QT4 VS2008 Installer

http://code.google.com/p/qt-msvc-installer/

win32, win64 버젼 두개다 있는듯.

이미 컴파일된 상태로 설치가 된다.
이걸 쓰는게 속편하고 좋다~

용량 차이가 많이 남.
실제 컴파일하게 되면 약 4기가 정도나 된다.
이걸로 설치하면 약 800메가 정도 차지.


QT4 프로그래밍에서 한글 입출력 관련..

기본적으로 QT 프레임웍에서 QString 에 한글을 사용할 경우에는 
여기저기 제대로 나오는게 하나도 없소.

그래서 맨처음부분에..

QTextCodec::setCodecForTr(QTextCodec::codecForName("eucKR"));

이걸 해주면 되오.

'OLD POSTS' 카테고리의 다른 글

Rails 에서 정말 간편한 Helper 함수들 목록.  (0) 2010.06.28
QT4 VS2008 Installer  (0) 2010.06.26
inplace select 에 필드추가 기능 넣기  (0) 2010.06.10
Super inplace controls의 사용.  (0) 2010.06.10
PaperClip 사용방법.  (0) 2010.06.08

inplace select 에 필드추가 기능 넣기

super_inplace_controls 를 사용하는 중인데
이것이 select 값을 선택한뒤에 값을 세팅하는 액션이 실행된 후.

변경된 값으로 다시 되돌아와야하는데 그렇지 못하고 있다. 아마 버그인듯 한데.
ajax로 받아온 값을 다시 html 로 뿌려야 하는데 그렇지 않고 있는데다가
원래 값의 div 를 display:hide 시켜놓고 복구를 안한다. -_-

뭔가 매우 어설픈 플러그인인데...
일단 고고씽하기 위해서 몇가지를 수정해서 사용할려고 하는중이다.

vendor>plugin>super_inplace_controls 안에
super_inplace_controls.rb
 부분 수정
def draw_form(set_method, object, id_string, opts = {})
form_remote_tag(:url => { :action => set_method, :id => object.id },
:method => opts[:http_method] || :post,
:loading => update_page do |page|
page.show "loader_#{id_string}"
page.hide "#{id_string}_form"
end,
:complete => update_page do |page|
page.hide "loader_#{id_string}"
          page.show "#{id_string}"
          page.hide "#{id_string }_form"          
end,
:html => {:class => "in_place_editor_form", :id => "#{id_string}_form", :style => "display:none" } )
end
이 함수는 form 을 그려주는 함수인데 :complete 부분에서 page show, hide 부분을 추가했다.

이로써 결과값이 제대로 표현된다.

inplace_select에서 Add... 부분을 추가하기 위해서 rhtml 파일을 수정하고 컨트롤러 부분도 수정했다.

<%= inplace_error_div %>
<% 
choices = Locate.all.map {|e| [e.name, e.id] } 
choices.concat([["Add..", -1 ]])
%>
<%= in_place_select :field_script, :locate_name, :choices => choices %>


 def set_field_script_locate_name
    locate = params[:field_script][:locate_name]
    if locate.to_i > 0
      @field_script = FieldScript.find(params[:id])
      @field_script.locate = Locate.find(locate)
      @field_script.save
      id_string = "field_script_locate_name_#{params[:id]}"
      render :update do |page|
        page.replace_html id_string, @field_script.locate.name
        page.visual_effect :highlight, id_string, :duration => 2
      end
    else
      render :js => "new_name = prompt('Enter New Locate','New Locate');jQuery.post('/field_scripts/set_field_script_locate_new_name', {name:new_name, field_id:#{params[:id]}});"
    end  
  end
  
  def set_field_script_locate_new_name
    new_locate = Locate.create(:name => params[:name])
    @field_script = FieldScript.find(params[:field_id])
    @field_script.locate = new_locate
    @field_script.save
    id_string = "field_script_locate_name_#{params[:field_id]}"
    render :update do |page|
      page.replace_html id_string, @field_script.locate.name
      page.visual_effect :highlight, id_string, :duration => 2
    end    
  end

중간에 자바스크립트 부분은 New 값을 받아서 field 를 추가하는 액션을 실행시키기 위해서 만들어준 jQuery 함수이다.

뭐 나중에 다시보면 기억 나겠지..

'OLD POSTS' 카테고리의 다른 글

QT4 VS2008 Installer  (0) 2010.06.26
QT4 프로그래밍에서 한글 입출력 관련..  (0) 2010.06.25
Super inplace controls의 사용.  (0) 2010.06.10
PaperClip 사용방법.  (0) 2010.06.08
QT4에서 SLOT 을 선언하는 방버.  (0) 2010.06.03

Super inplace controls의 사용.

http://github.com/flvorful/super_inplace_controls

rails 2.3.8 에서는 제대로 표현이 안되는데
오전 내내 삽질해보니.. jrails가 2.3.8 에서 제대로 안먹는 문제가 있었다.

아마도 이 문제라고 판단되어서 rails 2.3.5 를 설치해서 테스트를 해보니..
덴당.
잘된다.


'OLD POSTS' 카테고리의 다른 글

QT4 프로그래밍에서 한글 입출력 관련..  (0) 2010.06.25
inplace select 에 필드추가 기능 넣기  (0) 2010.06.10
PaperClip 사용방법.  (0) 2010.06.08
QT4에서 SLOT 을 선언하는 방버.  (0) 2010.06.03
CUDA Tips #1.  (0) 2010.05.31

PaperClip 사용방법.

http://github.com/thoughtbot/paperclip
위의 주소에서 plugin을 설치한다.

http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/
위의 주소의 튜터리얼을 참고하면 된다.

본격적으로 사용하기에 앞서서 필요한 것들이 있는데.

imagemagick 이건 꼭 필수 => port 로 설치
rb-rmagick         => 이것도 port로 설치 (gem이 아니다.)
mime-types       => gem 으로 설치하라고 나오지만 이것도 port로 설치해야한다. (rb-mime-types 설치)
이걸 빼먹으면 해당 파일의 type을 알수 없어서 에러 메시지 없이 등록이 되지 않는다. 은근히 미친다 이거. -_-


'OLD POSTS' 카테고리의 다른 글

inplace select 에 필드추가 기능 넣기  (0) 2010.06.10
Super inplace controls의 사용.  (0) 2010.06.10
QT4에서 SLOT 을 선언하는 방버.  (0) 2010.06.03
CUDA Tips #1.  (0) 2010.05.31
QT4 With Visual Studio x64  (1) 2010.05.27

QT4에서 SLOT 을 선언하는 방버.

protected slots:

private slots:

public slots:

 

위 세가지 지시자를 사용한다.!

slots 로 선언하지 않은 함수는 SIGNAL 과 연결지어도 실행되지 않는다.
--> 에러메시지 혹은 warning 이라도 뜨면 좋으련만 그렇지 않아서 약간의 시간을 날려버렸다.

'OLD POSTS' 카테고리의 다른 글

Super inplace controls의 사용.  (0) 2010.06.10
PaperClip 사용방법.  (0) 2010.06.08
CUDA Tips #1.  (0) 2010.05.31
QT4 With Visual Studio x64  (1) 2010.05.27
CentOS 5.2 에서 rails 설치.  (0) 2009.03.23

CUDA Tips #1.

거창한 팁 시리즈들은 아니고

CUDA 를 사용해서 프로그래밍을 하던 중 이것저것 알아낸 부분이 있으면 정리하기 위한! 시리즈!

그 첫번째!

오늘 하루종일 삽질하던 에러..

cpp 파일에서 cu 파일의 함수를 불러오는 중에 (call by ref, call by param)

dim3 변수가 제값을 전달하지 못하는 에러가 발생했다.

10, 10, 10 을 넣었는데 16390, 0, 1231994 등의 이상한 값들이 계속 발생. dim3 를 int 로 바꿔봐도 마찬가지.

이것저것 골머리를 앓던중에 알아낸 것은!

x64 환경에서 cu 파일을 32비트로 컴파일하고 그냥 링크하는 것이었다. –_-

딱히 경고나 에러 메시지가 전혀 나오지 않아서 계속 삽질만 하던중에 혹시(?) 라고 판단 64비트 옵션을 주어서 –m64

nvcc 에서 컴파일하니깐 제대로 돌아간다…

 

* nvcc –m64 option.

'OLD POSTS' 카테고리의 다른 글

PaperClip 사용방법.  (0) 2010.06.08
QT4에서 SLOT 을 선언하는 방버.  (0) 2010.06.03
QT4 With Visual Studio x64  (1) 2010.05.27
CentOS 5.2 에서 rails 설치.  (0) 2009.03.23
JQuery 기본적인 사용방법.  (0) 2009.03.05

QT4 With Visual Studio x64

일단 QT4 를 설치 한 상태이고 visual studio addin 을 설치한다.

visual studio 2008 x64 Win64 Command Prompt 를 실행한 후에

QT4 의 디렉토리로 가서 configure 를 실행한다.

실행을 하면 자동으로 nmake 파일들이 생성이 되는데.

이어서 nmake 를 실행시켜서 QT4 를 다시 컴파일해주면 된다.

visual studio 2008 에서 New > QT4 프로젝트를 생성해서 컴파일 실행이 가능하다!~

CentOS 5.2 에서 rails 설치.

1. Install ruby

> yum install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc


2. Install gem
> wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
> tar xvf rubygems-1.3.1.gz
> cd rubygems-1.3.1
> ruby setup.rb

3. Install Rails
> gem install rails

JQuery 기본적인 사용방법.

dom 선택

css selector와 같은 형식으로 dom을 선택할 수 있다. selector를 사용하기 위해서 jQuery 혹은 $를 사용한다.

  1. jQuery("#id")  
  2. $(".class")  
  3. $("tag.class")  

return되는 것은 jQuery 객체이다.

 

event handling

가장 맘에 드는 event handling이다. 다음과 같이 선택된 DOM에 원하는 event 함수들을 달아놓으면 된다.

  1. $(document).ready( function() {  
  2.   $("#project_submit").click(function(){    
  3.     alert("submit the form");  
  4.     return true;  
  5.   });  
  6. });  

$(document).ready 는 브라우져가 모든 js 들을 다 download 받은 후 실행될 것을 보장한다. (window.onload와 같다.)

$("#project_submit").click 은 project_submit이란 id를 가진 dom에 click 이벤트가 발생하면 실행된다.

더 자세한 event에 대해서는 http://docs.jquery.com/Events 를 참조한다.

Effect

간단한 effect들 역시 손쉽게 사용할 수 있다.

  1. $("#message_box").fadeOut();  

더 자세한 효과들에 대해서는 http://docs.jquery.com/Effects 를 참조.

 

each, map, unique

배열이 있고 배열을 iteration 하고 싶은 경우 each를 사용할 수 있다.

  1. members = ["juddy""james"];  
  2. $.each(members, function() {  
  3.   project.members.push(this));  
  4.   
  5. });  

function 안의 this는 각 member를 가르킨다.

selector를 이용했다면 다음과 같이 더 간결한 표현도 가능하다.

  1. $(".project").each( function() {    
  2. });  

 

Ajax Request

Ajax request도 간단하게 사용할 수 있다.

  1. $.ajax({  
  2.   type: "POST",  
  3.   url: "/projects/recent",  
  4.   data: "duration=5&user=juddy",  
  5.   success: function(html){  
  6.    $("#recent_projects").replaceWith(html);  
  7.   }  
  8. });  

success는 요청 성공시 호출되는 event handler이다. 이렇게 각 요청에 대해서 event handler를 작성할 수도 있고, 모든 요청에 대한 global event handler를 다음과 같이 정의할 수도 있다.

  1. $("#ajax_msg").ajaxSuccess(function(evt, request, settings){  
  2.    $(this).append("<li>Successful Request!</li>");  
  3.  });  

 

json request를 callback과 함께 사용하고 싶다면 getJSON을 사용할 수도 있다. (GET요청만 사용가능)

  1. $.getJSON("/projects/recent",  
  2.   function(data){  
  3.     // handle data  
  4.   });  
  5. });  

 

더 자세한 내용은 http://docs.jquery.com/Ajax 를 참조.

Rails 에서 JQuery와 Prototype 을 함께 사용하는 방법 #2

지금 현재 JRails 플러그인을 깔아놓은 형태이긴 한데.

 

<%= javascript_include_tag :defaults %>   

 

이 부분에서 약간 혼란이 있는듯 하다.

JRails 플러그인 설명에 보면 이부분이 자동적으로 JQuery 로 바뀌는 듯하다.

 

뭐 어쨌건 지금은

 

<%= javascript_include_tag :defaults %>       
<%= javascript_include_tag 'jrails', 'jquery', 'jquery-ui', 'application' %>

<%= javascript_include_tag 'prototype', 'effects', 'dragdrop' %>
<%= active_scaffold_includes %>       

 

이 순서로 로딩해서 사용하고 있다. application.js 부분에는

 

jQuery.noConflict();

 

이걸 추가해준 상태다.

 

테스트로 drag div 에 drag 속성을 줬다.

 

<script>
    jQuery("#job_1166").draggable();
    new Draggable("job_1116");

</script>

 

프로토타입과 jquery 에서 ID 찾는 방법이 차이가 있는데

프로토타입에서는 그냥 id name 만 쓰면 되지만.

JQuery에서는 # 을 꼭 붙여줘야한다.

Rails 에서 Prototype 과 JQuery 를 동시에 사용하기.

Rails 에서 포함된 Prototype 같은 경우 좋은 라이브러리이긴 하나.

JQuery 가 플러그인 형태로 제공되는 라이브러리들이 굉장히 많다는 장점 때문에.
JQuery 가 끌리는게 사실이다.

Prototype 라이브러리를 JQuery 로 완전히 바꾼 JRails 가 있긴 하지만.
굳이 아직까지는 완전히 대체할 필요까지는 없는 듯하다.

앞으로 계속 JQuery 를 사용한다면 얘기는 달라지긴 하겠지만.
일단 Prototype 과 JQuery 를 같이 사용할 예정이다.

같이 사용하는 방법에 대해서는

Using jQuery with Other Libraries

prototype과 jquery 같이 사용하기 [JQuery 클릭, 링크 이벤트 포함]


ActiveRecord 정렬하는 방법.

ActiveRecord 를 많이 사용하다 보면

정렬해서 볼 필요가 많이 생기는데.

 

기본적으로.. sort, sort_by 메쏘드를 많이 사용하게 된다.

 

 

enum.sort => array
enum.sort {| a, b | block } => array

 

Returns an array containing the items in enum sorted, either according to their own <=> method, or by using the results of the supplied block. The block should return -1, 0, or +1 depending on the comparison between a and b. As of Ruby 1.8, the method Enumerable#sort_by implements a built-in Schwartzian Transform, useful when key computation or comparison is expensive..

   %w(rhea kea flea).sort         #=> ["flea", "kea", "rhea"]
   (1..10).sort {|a,b| b <=> a}   #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
 

enum.sort_by {| obj | block } => array

 

Sorts enum using a set of keys generated by mapping the values in enum through the given block.

   %w{ apple pear fig }.sort_by {|word| word.length}
                #=> ["fig", "pear", "apple"]

The current implementation of sort_by generates an array of tuples containing the original collection element and the mapped value. This makes sort_by fairly expensive when the keysets are simple

   require 'benchmark'
   include Benchmark

   a = (1..100000).map {rand(100000)}

   bm(10) do |b|
     b.report("Sort")    { a.sort }
     b.report("Sort by") { a.sort_by {|a| a} }
   end

produces:

   user     system      total        real
   Sort        0.180000   0.000000   0.180000 (  0.175469)
   Sort by     1.980000   0.040000   2.020000 (  2.013586)

However, consider the case where comparing the keys is a non-trivial operation. The following code sorts some files on modification time using the basic sort method.

   files = Dir["*"]
   sorted = files.sort {|a,b| File.new(a).mtime <=> File.new(b).mtime}
   sorted   #=> ["mon", "tues", "wed", "thurs"]

This sort is inefficient: it generates two new File objects during every comparison. A slightly better technique is to use the Kernel#test method to generate the modification times directly.

   files = Dir["*"]
   sorted = files.sort { |a,b|
     test(?M, a) <=> test(?M, b)
   }
   sorted   #=> ["mon", "tues", "wed", "thurs"]

This still generates many unnecessary Time objects. A more efficient technique is to cache the sort keys (modification times in this case) before the sort. Perl users often call this approach a Schwartzian Transform, after Randal Schwartz. We construct a temporary array, where each element is an array containing our sort key along with the filename. We sort this array, and then extract the filename from the result.

   sorted = Dir["*"].collect { |f|
      [test(?M, f), f]
   }.sort.collect { |f| f[1] }
   sorted   #=> ["mon", "tues", "wed", "thurs"]

This is exactly what sort_by does internally.

   sorted = Dir["*"].sort_by {|f| test(?M, f)}
   sorted   #=> ["mon", "tues", "wed", "thurs"]

Ajax 에서 로딩중인 이미지를 만들어 보자~

http://www.ajaxload.info/

 

꽤 쓸만한것들이 많다!

꽤 쓸모가 있을 만한 Rounded Corner CSS

CurvyCorners

 

 

pre {
background-color: #def;
color: #112;
padding: 10px;
font-size: 13px;
overflow: auto;
margin: 4px 0px;
overflow-x: auto;
overflow-y: hidden;
margin-top: 12px;
border: 1px solid #9ad;
-moz-border-radius: 25px 10px 25px 10px;

CCborderRadiusTL: 25px;
CCborderRadiusTR: 10px;
CCborderRadiusBL: 10px;
CCborderRadiusBR: 25px;       

}

Activescaffold 에서 rounded corner 를 사용하는 방법.

activescaffold 에서는

 

Rico 라는 Ajax 프레임 웍을 사용하는데.

 

http://openrico.org/

 

이중에서 Rounded Corner 를 사용하는 방법은..

 

<script type="text/javascript">
    Rico.Corner.round($$('#myBox').first());
</script>

 

 

이런식으로 사용한다.

prev 1 2 3 4 next