반응형
반응형

jquery와 angulars 같이 사용하기.

requireJS로 시작했다가 무거운거 같아서 그냥 같이 쓰는걸로 해봤다.

문법적인 문제는 발견되지 않았다. 너무 간단한 테스트라서 그럴지도.

 

AS-IS

 : index.html에 require.js와 main.js, angular.js, controllers.js 등을 녹여넣었다.

* index.html

<!doctype html>
<html lang="en" ng-app>
    <head>
        <title>jQuery+RequireJS Sample Page</title>
        <!-- This is a special version of jQuery with RequireJS built-in -->
        <script data-main="scripts/main" src="scripts/require-jquery.js"></script>
               </script>
    </head>
    <body ng-controller="PhoneListCtrl" >
        <h1>jQuery+RequireJS Sample Page</h1>
        <p>Look at source or inspect the DOM to see how it works.</p>
       
       
       
        <div id="mydiv">aaa</div>
        <p>Total number of phones: {{phones.length}} </p>
        <p>Angulars Templates - http://docs.angularjs.org/tutorial/step_02</p>

 <p>Nothing here {{'yet' + '!'}}</p>
 
 <p>1 + 2 = {{ 1 + 2 }}</p>
 
 <p class="hello">{{hello}}______</p>
    </body>
</html> 

* main.js - require.js에서 사용함. 

 require(["jquery"], function($) {
  $("#mydiv").html("Hello this is RequireJS talking");
});


require(["jquery", "jquery.alpha", "jquery.beta"], function($) {
    //the jquery.alpha.js and jquery.beta.js plugins have been loaded.
    $(function() {
        $('body').alpha().beta();
    });
});

// angular.JS, controllers.js 를 LOAD.
require(["angular"], function($) {

});
require(["controllers"], function($) {

});

* controllers.js - angular.js에서 사용 

 function PhoneListCtrl($scope) {
  $scope.phones = [
    {"name": "Nexus S",
     "snippet": "Fast just got faster with Nexus S.",
     "age": 0},
    {"name": "Motorola XOOM™ with Wi-Fi",
     "snippet": "The Next, Next Generation tablet.",
     "age": 1},
    {"name": "MOTOROLA XOOM™",
     "snippet": "The Next, Next Generation tablet.",
     "age": 2}
  ];
 
  $scope.orderProp = "age";  
  $scope.hello = "Hello, world!"; 
}

 

TO-BE

* index.html 에 다 순차적으로 호출하였다.(require.js 사용안함) 

 <!doctype html>
<html lang="en" ng-app>
    <head>
        <title>jQuery+RequireJS Sample Page</title>
        <!-- This is a special version of jQuery with RequireJS built-in -->
        <script src="scripts/angular.js" ></script>
      <script src="scripts/controllers.js"></script>
      <script src="scripts/jquery-1.5.2.min.js"></script>
      <script src="scripts/jquery.alpha.js" ></script>
      <script src="scripts/jquery.beta.js" ></script>
        <script>        
         $(document).ready(function(){
             $("#mydiv").html("Hello this is RequireJS talking");
             $('body').alpha().beta();
         });
   
        </script>
    </head>
    <body ng-controller="PhoneListCtrl" >
        <h1>jQuery+RequireJS Sample Page</h1>
        <p>Look at source or inspect the DOM to see how it works.</p>
       
       
       
        <div id="mydiv">aaa</div>
        <p>Total number of phones: {{phones.length}} </p>
        <p>Angulars Templates - http://docs.angularjs.org/tutorial/step_02</p>

 <p>Nothing here {{'yet' + '!'}}</p>
 
 <p>1 + 2 = {{ 1 + 2 }}</p>
 
 <p class="hello">{{hello}}______</p>
    </body>
</html>

 

 

 

 

 

 

반응형
반응형

 

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.

 

http://requirejs.org/

 

 

프로젝트에 require.js와 main.js 파일이 필요하다.

아래에서 main.js를 호출하는 구문이다.

<script src="require.js" data-main="main"></script>

main.js( data-main="main" )에 로드할 JSLibrary와 해당 JSLabrary의 구문을 입력하면 된다.

아래에는 "jquery.js" 가 있어야 실행이 된다.

require(["jquery"], function($) {
  $(‘#mydiv”).html(‘Hello this is RequireJS talking”);
});

 

** Optimize your JavaScript with RequireJS

http://www.webdesignerdepot.com/2013/02/optimize-your-javascript-with-requirejs/

 

 

IE 6+ .......... compatible ✔
Firefox 2+ ..... compatible ✔
Safari 3.2+ .... compatible ✔
Chrome 3+ ...... compatible ✔
Opera 10+ ...... compatible ✔

Get started then check out the API.

 

require.js 2.1.4MinifiedWith Comments

All you need to start using require.js in the browser.

Sample RequireJS 2.1.4 + jQuery 1.9.1 projectDownload

A zip file containing a sample project that uses jQuery and RequireJS.

r.js: Optimizer and Node and Rhino adapterDownload

The r.js file allows you to run the optimizer as well as run modules in Node or Rhino.

If you are running in Node, and want to use npm to install this file via npm, see the Use with Node page for more information.

For information on its use, as well as how to get the JAR files to run it under Rhino, see the r.js README.

Plugins§ 2

These are useful loader plugins that have the same license terms as require.js itself. Download the plugin file and place it as a sibling to your "data-main" main.js script.

textDownload

Load text files and treat them as dependencies. Great for loading templates. The text strings can be inlined in an optimized build when the optimizer is used.

domReadyDownload

Wait for the DOM is ready. Useful for pausing execution of top level application logic until the DOM is ready for querying/modification.

cs (CoffeeScript)Download

Load files written in CoffeeScript. With this plugin, it is easy to code in CoffeeScript in the browser, it can participate in the optimizer optimizations, and it works in Node and Rhino via the RequireJS adapter. This is the best way to do cross-environment, modular CoffeeScript. The project home has more information on how to install and use it.

i18nDownload

Load string bundles used in internationalization (i18n) that are made up of separate country/language/locale-specific bundles.

반응형
반응형

기본 예제 - "예제중심의 파이썬" 1장

 

source

 

# -*- coding: utf-8 -*-

teamstandings = [('SK', 38,25,0),
                 ('SS',39,27,2),
                 ('KIA',38,29,0),
                 ('LG',36,30,0),
                 ('HH',29,39,1)
                 ]

for ts in teamstandings:
    team, win, lost, draw = ts
    games = win + lost + draw
    winrate = float(win) / (win + lost)
    format = '%s 팀은 총  %d 경기 중  %d 승으로 승률은   %.3f 입니다. '
    print(format % (team, games, win, winrate))
    #print( team, games, win, winrate )

# 4.1 숫자 계산
print("=" * 20 + '  4.1. 숫자계산    ' + "=" * 20)

print("1 + 2 = " , (1+2))
print("50 - 4 =" , 50-4)
print("5000 / 3 = ", 5000/3)
print("5000.0 / 3.0 = ", 5000.0/3.0)

print()
print('-' * 10 , 'calendar', '-' * 10)
import calendar
calendar.prmonth(2018, 2)

print()
print('-' * 10 , '문자열', '-' * 10)

print(' show * 3 = ', 'show' * 3)
print(' 11,200,000.replace(\',\', \'\' ) = ', '11,200,000'.replace(',', ''))
# 앞쪽 여섯글자
print('0~6 :  \'follower\'[0:6] = ', 'follower'[0:6])
# 앞의 0은 생략 가능
print('0~6 :  \'follower\'[:6] = ', 'follower'[:6])
# 4번부터 끝까지
print('4~end :  \'followerwhite\'[4:] = ', 'followerwhite'[4:])
#뒤에서 네번째부터 끝까지
print('-4 :  \'followerwhite\'[-4:] = ', 'followerwhite'[-4:])
# 단어의 첫 글자는 대문자, 나머지는 소문자
print(' \'espresso\'.title() = ', 'espresso'.title())
# 문자열의 길이(공백, 기호도 포함된다.)
print(' len(\'what are you?\') = ', len('what are you?'))
# 문장에서 특정문자열이 몇 번 나오는지 count
ans = "We're  here because you are looking for the best of the best of the best, sir!"
print(ans)
print( " ans.count(\'best\') = ",ans.count('best') )

 

print()
print('-' * 10 , ' 날짜 계산 ', '-' * 10)
from datetime import date

t   = date.today()
print( ' today : ' , t )
c   = date(2013, 9, 19)
gap = abs(c - t).days
subscrib = " %s - %s = - %s days. remain."
print( subscrib % (c, t, gap) )

print()
print('-' * 10 , ' 로또 번호 뽑기', '-' * 10)

lotto = list(range(1,46))
print(lotto)
import random
# lotto를 무작위로 섞는다.
random.shuffle(lotto)
print(lotto)
# 하나의 숫자를 꺼낸다.
print(' 1.  ', lotto.pop())
print(lotto)
# 하나의 숫자를 꺼낸다.
print(' 2.  ', lotto.pop())

for i in range(5):
    print(' ',i + 1,'. ', lotto.pop())
print(lotto)


family = ['father','mother','I','sister']
i = 0
print('family = ' , family )
for x in family:
    i += 1
    print(i ,'  - ', x)

print(range(4,8))   
for i in range(4,8): print('  - ', i)   

 

print('카이사르 암호문 만들기' , '-' * 20);
# from string import maketrans
# tt = maketrans('abcdefghijklmnopqrstuvwxyz', 'DEFGHIJKLMNOPQRSTUVWXYZABC')


print('  While 문   ' , '-' * 20);
num = 1
while num <= 10:
    print( num )
    num += 1

print('  IF 문   ' , '-' * 20);
a = 1234 * 4
b = 13456/4
if a < b:
    print( a )
else:
    print( b )
   
c = 15 * 5
d = 15 + 15 + 15 + 15 + 15

if c > d :
    print(' c > d ')
elif c == d:
    print(' c == d ')
else:
    print(' C < d ')
   
print('  구구단   ' , '-' * 20);
left = 8
rightlist = range(1,10)
for right in rightlist:
    print(' %d * %d = %d' % (left, right, left * right))

# * 로 마름모 만들기
a = 1
b = 10
c = 0
d = 10
for i in range(10):
    if a == 1:
        print(' ' * b + ('*' * a))
    else:
        print(' ' * b + ('*' * a) + ('*' * c) )
    a += 1
    c += 1
    b -= 1
print('*'*a + '*'*c)
for i in range(10):
    c -= 1
    a -= 1
    print(' ' * b, '*' * a + ('*' * c) )
    b += 1


 

 

 

result 

 SK 팀은 총  63 경기 중  38 승으로 승률은   0.603 입니다.
SS 팀은 총  68 경기 중  39 승으로 승률은   0.591 입니다.
KIA 팀은 총  67 경기 중  38 승으로 승률은   0.567 입니다.
LG 팀은 총  66 경기 중  36 승으로 승률은   0.545 입니다.
HH 팀은 총  69 경기 중  29 승으로 승률은   0.426 입니다.
====================  4.1. 숫자계산    ====================
1 + 2 =  3
50 - 4 = 46
5000 / 3 =  1666.6666666666667
5000.0 / 3.0 =  1666.6666666666667

---------- calendar ----------
   February 2018
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28
 
---------- 문자열 ----------
 show * 3 =  showshowshow
 11,200,000.replace(',', '' ) =  11200000
0~6 :  'follower'[0:6] =  follow
0~6 :  'follower'[:6] =  follow
4~end :  'followerwhite'[4:] =  owerwhite
-4 :  'followerwhite'[-4:] =  hite
 'espresso'.title() =  Espresso
 len('what are you?') =  13
We're  here because you are looking for the best of the best of the best, sir!
 ans.count('best') =  3

----------  날짜 계산  ----------
 today :  2013-02-08
 2013-09-19 - 2013-02-08 = - 223 days. remain.

----------  로또 번호 뽑기 ----------
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45]
[21, 40, 1, 8, 15, 9, 11, 23, 31, 20, 10, 28, 13, 41, 19, 6, 12, 39, 43, 18, 27, 16, 24, 5, 29, 14, 30, 34, 35, 38, 32, 3, 17, 45, 7, 37, 4, 2, 25, 22, 33, 42, 44, 26, 36]
 1.   36
[21, 40, 1, 8, 15, 9, 11, 23, 31, 20, 10, 28, 13, 41, 19, 6, 12, 39, 43, 18, 27, 16, 24, 5, 29, 14, 30, 34, 35, 38, 32, 3, 17, 45, 7, 37, 4, 2, 25, 22, 33, 42, 44, 26]
 2.   26
  1 .  44
  2 .  42
  3 .  33
  4 .  22
  5 .  25
[21, 40, 1, 8, 15, 9, 11, 23, 31, 20, 10, 28, 13, 41, 19, 6, 12, 39, 43, 18, 27, 16, 24, 5, 29, 14, 30, 34, 35, 38, 32, 3, 17, 45, 7, 37, 4, 2]
family =  ['father', 'mother', 'I', 'sister']
1   -  father
2   -  mother
3   -  I
4   -  sister
range(4, 8)
  -  4
  -  5
  -  6
  -  7
카이사르 암호문 만들기 --------------------
  While 문    --------------------
1
2
3
4
5
6
7
8
9
10
  IF 문    --------------------
3364.0
 c == d
  구구단    --------------------
 8 * 1 = 8
 8 * 2 = 16
 8 * 3 = 24
 8 * 4 = 32
 8 * 5 = 40
 8 * 6 = 48
 8 * 7 = 56
 8 * 8 = 64
 8 * 9 = 72
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
*********************
 *******************
  *****************
   ***************
    *************
     ***********
      *********
       *******
        *****
         ***
          *
done.

 

반응형
반응형

http://www.centos.org/

 

http://mirror.teklinks.com/centos/6.3/isos/x86_64/

 

 

가상머신 : https://www.virtualbox.org/

 

https://www.virtualbox.org/wiki/Downloads

반응형

'프로그래밍 > Server' 카테고리의 다른 글

Ubunto 설치  (0) 2013.02.20
[Linux] Ubuntu on tablets  (0) 2013.02.20
리눅스 배포판 다운로드  (0) 2013.01.15
[NGINX] 차세대 웹서버 NGINX  (0) 2012.08.09
[NGINX] NGINX 커뮤니티 사이트  (0) 2012.07.17
반응형

크롬 브라우저 파이썬 쉘 - https://chrome.google.com/webstore

 

크롬브라우저에서 파이썬 쉘 사용하기.

APP과 확장 프로그램이 있는데, 둘다 차이점은 별로 없다.

 

 

반응형
반응형

 웹 파이썬 shell - http://shell.appspot.com/

 

설치 필요없이 인터넷에 연결되어 있으면 당장 파이썬을 사용해 볼 수 있는 방법.

 

반응형

+ Recent posts