var while can be called multiple times, let acts like variable from java, can be called only once if it is declared globally.

 

var acts as global variable all the time while let functions only in the declared block.

 

const is final from java. 

 

arrow syntax function is lamba from java.

 

javascript allows for default value

 

 

'ETC' 카테고리의 다른 글

FCM notification send  (0) 2020.02.11
Regular Expressions  (0) 2020.02.10
JSON APIs and Ajax  (0) 2020.02.10
Basic Javascript  (0) 2020.02.08
jsp에서 컨트롤러갈때 한글 깨짐현상(02/07/20 cudo notes 5)  (0) 2020.02.07

<script>

  document.addEventListener('DOMContentLoaded'function(){

    // Add your code below this line



    // Add your code above this line

  });

</script>

 

document.getElementsByClassName('')[0].textContent = 'dd';

 

json apis are sent in bytes, application receives it as string. in order to use it in javascript, it needs to be converted into javascript object. JSON.parse does that for us.

 

 

  document.addEventListener('DOMContentLoaded'function(){

    document.getElementById('getMessage').onclick = function(){

      // Add your code below this line

const req = new XMLHttpRequest();

req.open('GET','/json/cats.json',true);

req.send();

req.onload = function(){

  const json = JSON.parse(req.responseText);

  document.getElementsByClassName('message')[0].innerHTML = JSON.stringify(json);

}

 

another way to request externa data is through fetch method.

 

fetch('/json/cats.json')

   .then(response => response.json())

   .then(data => { document.getElementById('message').innerHTML = JSON.stringify(data); })

 

[ ] -> Square brackets represent an array
{ } -> Curly brackets represent an object
" " -> Double quotes represent a string. They are also used for key names in JSON

 

 

'ETC' 카테고리의 다른 글

Regular Expressions  (0) 2020.02.10
es6  (0) 2020.02.10
Basic Javascript  (0) 2020.02.08
jsp에서 컨트롤러갈때 한글 깨짐현상(02/07/20 cudo notes 5)  (0) 2020.02.07
mysql password change(02/06/20 cudo notes 4)  (0) 2020.02.06

JavaScript provides seven different data types which are undefined, null, boolean, string, symbol, number, and object.

 

When JavaScript variables are declared, they have an initial value of undefined. If you do a mathematical operation on an undefined variable your result will be NaN which means "Not a Number". If you concatenate a string with an undefined variable, you will get a literal string of "undefined".

 

 camelCase =  first word in lowercase and the first letter of each subsequent word is capitalized.

 

 Mad Libs style ex. var ourStr = "Hello, our name is " + ourName + ", how are you?";

 

Zero-based indexing = programming languages start counting from number 0 not 1;

 

Javascript array array methods

push(), pop(), shift()(removes the first element), unshift()(adds to the beginning of an array) 

 

 

Difference between parameters and arguments : 

In JavaScript, scope refers to the visibility of variables. Variables which are defined outside of a function block have Global scope.

Variables which are used without the var keyword are automatically created in the global scope.

 

== does type conversion, === is strict equality which does not automatically performs type conversion.

 

 

you access the data in objects through what are called properties.

if your object has any non-string properties, JavaScript will automatically typecast them as strings.

 

an example of javascript object notation aka json:

The Call Stack

Recursive functions use something called “the call stack.” When a program calls a function, that function goes on top of the call stack. This similar to a stack of books. You add things one at a time. Then, when you are ready to take something off, you always take off the top item.

 

Math random number range: 

Math.floor(Math.random() * (max - min + 1)) + min

 

Last picture explaination:

arrayRange's data type is set at line 3.

Since recursion always happens as call stack, if wanted print value is from 1 ~ 5, have to think of top book, which is the number 5. 5 gets unshift, then 4 all the way up to 1 which results 1 ~ 5 as answer. 

'ETC' 카테고리의 다른 글

es6  (0) 2020.02.10
JSON APIs and Ajax  (0) 2020.02.10
jsp에서 컨트롤러갈때 한글 깨짐현상(02/07/20 cudo notes 5)  (0) 2020.02.07
mysql password change(02/06/20 cudo notes 4)  (0) 2020.02.06
Applied Accesbility  (0) 2020.02.05

해당  apache server.xml에 URIEncoding="UTF-8" 를 추가하자.

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"  URIEncoding="UTF-8" />

 

이방식은 get만 적용이되니 form태그를 get방식으로 보내야한다. 

 

 

'ETC' 카테고리의 다른 글

JSON APIs and Ajax  (0) 2020.02.10
Basic Javascript  (0) 2020.02.08
mysql password change(02/06/20 cudo notes 4)  (0) 2020.02.06
Applied Accesbility  (0) 2020.02.05
Basic settings for web(02/05/20 cudo notes 3)  (0) 2020.02.05

sudo mysqld_safe --skip-grant-tables

mysql -u root -p

UPDATE mysql.user SET authentication_string=null WHERE User='root';

FLUSH PRIVILEGES;

exit;

mysql -u root

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';

<div> - groups content

<section> - groups related content

<article> - groups independent, self-contained content

 

----

 <fieldset>

        <legend>What level ninja are you?</legend>

        <input id="newbie" type="radio" name="levels" value="newbie">

        <label for="newbie">Newbie Kitten</label><br>

        <input id="intermediate" type="radio" name="levels" value="intermediate">

        <label for="intermediate">Developing Student</label><br>

        <input id="master" type="radio" name="levels" value="master">

        <label for="master">Master</label>

      </fieldset>

display: flex;

flex-direction: row or column;

 

example : 

<style>

  body {

    font-family: Arialsans-serif;

  }

  headerfooter {

    display: flex;

    flex-direction: row;

  }

  header .profile-thumbnail {

    width: 50px;

    height: 50px;

    border-radius: 4px;

  }

  header .profile-name {

    display: flex;

  flex-direction: column;

    margin-left: 10px;

  }

  header .follow-btn {

    display: flex;

    margin: 0 0 0 auto;

  }

  header .follow-btn button {

    border: 0;

    border-radius: 3px;

    padding: 5px;

  }

  header h3header h4 {

    display: flex;

    margin: 0;

  }

  #inner p {

    margin-bottom: 10px;

    font-size: 20px;

  }

  #inner hr {

    margin: 20px 0;

    border-style: solid;

    opacity: 0.1;

  }

  footer .stats {

    display: flex;

    font-size: 15px;

  }

  footer .stats strong {

    font-size: 18px;

  }

  footer .stats .likes {

    margin-left: 10px;

  }

  footer .cta {

    margin-left: auto;

  }

  footer .cta button {

    border: 0;

    background: transparent;

  }

</style>

<header>

  <img src="https://freecodecamp.s3.amazonaws.com/quincy-twitter-photo.jpg" alt="Quincy Larson's profile picture" class="profile-thumbnail">

  <div class="profile-name">

    <h3>Quincy Larson</h3>

    <h4>@ossia</h4>

  </div>

  <div class="follow-btn">

    <button>Follow</button>

  </div>

</header>

<div id="inner">

  <p>I meet so many people who are in search of that one trick that will help them work smart. Even if you work smart, you still have to work hard.</p>

  <span class="date">1:32 PM - 12 Jan 2018</span>

  <hr>

</div>

<footer>

  <div class="stats">

    <div class="Retweets">

      <strong>107</strong> Retweets

    </div>

    <div class="likes">

      <strong>431</strong> Likes

    </div>

  </div>

  <div class="cta">

    <button class="share-btn">Share</button>

    <button class="retweet-btn">Retweet</button>

    <button class="like-btn">Like</button>

  </div>

</footer>

 

justify-content property set to any of these values: center, flex-start, flex-end, space-between, space-around, or space-evenly.

Activity 생명주기

존재하지 않음 -> onCreate() -> onStart -> onResume -> onPause() -> onStop() -> onDestroy -> 존재하지 않음

 

Problem 1 : 

If Android Emulator screen does not flip to landscape mode, check if flipping is blocked on avd manager.

allow flipscreen on avd manager.

 

-----------------

 

Basic web.xml settings you need

 

1. welcome file list for start up

 

<welcome-file-list>

<welcome-file>/</welcome-file>

</welcome-file-list>

 

2. for database access

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring/root-context.xml</param-value>

</context-param>

 

3. to read other languages beside english

 

<filter>

<filter-name>encodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>utf-8</param-value>

</init-param>

<init-param>

<param-name>listings</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

 

4. Setting path way from servlet-context.xml

 

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

 

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

 

5. etc

 

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

 

----------

setting path for servlet-context.xml

 

1. enables annotations

 

<annotation-driven />

<context:annotation-config/>

 

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->

<resources mapping="/resources/**" location="/resources/" />

 

<resources mapping="/style/**" location="/style/"/>

 

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<beans:property name="prefix" value="/WEB-INF/jsp/" />

<beans:property name="suffix" value=".jsp" />

</beans:bean>

 

<context:component-scan base-package="com.test.taewon">

<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

        <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>

        <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>

</context:component-scan>

 

-----

 

root-context.xml

 

<context:property-placeholder

location="classpath:/mybatis/config/datasource.properties" />

<context:annotation-config />

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="${driver}" />

<property name="url" value="${url}" />

<property name="username" value="${id}" />

<property name="password" value="${pw}" />

</bean>

<bean id="sqlSessionFactoryBean"

class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="mapperLocations"

value="classpath:/mybatis/mappers/*Mapper.xml" />

<property name="typeAliasesPackage"

value="com.test.taewon.vo" />

</bean>

<bean id="sqlSession"

class="org.mybatis.spring.SqlSessionTemplate">

<constructor-arg index="0" ref="sqlSessionFactoryBean"></constructor-arg>

</bean>

<bean id="TransactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource"></property>

</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="com.test.taewon.mapper"></property>

</bean>

 

----

datasource.properties stuff:

 

dbname=mysql

driver=com.mysql.cj.jdbc.Driver

url=jdbc:mysql://localhost:3306/taewonboard?serverTimezone=UTC

id=

pw=

'ETC' 카테고리의 다른 글

mysql password change(02/06/20 cudo notes 4)  (0) 2020.02.06
Applied Accesbility  (0) 2020.02.05
안드로이드 스튜디오 계산기 mainactivity.java  (0) 2020.02.04
계산기 strings.xml  (0) 2020.02.04
계산기 activity_main.xml  (0) 2020.02.04
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package com.example.calculatorfeb03;
 
 
 
 
public class MainActivity extends AppCompatActivity {
 
    //기준은 애플 계산기
    //에러 보기 기능
    //top messages
    private TextView introduction;
    private int randomNum = 0;
    String[] randomIntroduction = {"neat""could try better..""just seeing cool nums""way to go!""pretty smart"};
 
    //버튼들
    private Button calculation_result, button_c, button_plusMinus, button_percent, button_divide, button_7, 
button_8, button_9, button_multiply, button_4, button_5, button_6, button_minus, button_1,
button_2, button_3, button_plus, button_0, button_dot, button_equals;
 
    //숫자 에딧텍스트
    private EditText edit;
    //숫자 값 저장 변수
    private Double a = 0.00;
 
    //음수(negative number), 정수(positive number)시 비교해야하는 .charAt()이 달라서 사용하는 변수
    private int plusMinusCharNumber = 0;
 
    //애플 계산기 처럼 연산을 눌렀을 경우 숫자를 입력하기 전까지 기존에 있던 숫자가 보이게하는 조건
    //checks if operation( *, %, -, +, =) was used
    //true= used
    //false= hasnt been used
    private boolean testing = false;
 
    //연산 번호
    //( 2 = divide, 3 = multiply, 4 = minus, 5 = plus)
    private int where = 0;
 
    //음수 또는 정수 역할 정하는 불리언
    //number starts as positive so default value must be false.
    //true = need to remove '-'
    //false = need to add '-'
    boolean plusMinus = false;
 
    //랜덤으로 배열에 담긴 메세지 출력하는 재미로해본 기능
    //For TextView introduction, random index generator from 0 ~ 4
    private void randomGenerator(){
        randomNum = (int)(Math.random() * 5);
        introduction.setText(randomIntroduction[randomNum]);
        //introduction.setText();
    }
 
    //연산을 클릭하면 저장
    //Saves number to a and resets edit
    private void saveNumber(){
        introduction.setText("Arrived at saveNumber()");
        a = Double.valueOf(edit.getText().toString().trim());
        testing = true;
        settingText();
    }
 
    //소수점이 필요한지 확인하는 기능
    //Checs if decimal point is needed or not
    private void settingText(){
        //만약 1로 나눴을 시 나머지가 0이면 정수
        if(a % 1 == 0){
            edit.setText(String.valueOf(Math.round(a)));
        } else {
            edit.setText(Double.toString(a));
        }
 
        //계산 후 음수이면 바꿔주기
        if(a < 0) plusMinus = true;
    }
 
    //숫자입력시 확인하는 메소드
    //for number pad
    private void typingNumber(int number){
        //0이 시작일 경우 숫자입력
        if(edit.getText().toString().charAt(0== '0') {
            introduction.setText("arrived");
            edit.setText(String.valueOf(number));
            testing = false;
        //0이 시작이지만 앞에 - 사인이 있을때
        } else if(plusMinus && edit.getText().toString().charAt(plusMinusCharNumber) == '0'){
            edit.setText('-' + String.valueOf(number));
            plusMinus = true;
            plusMinusCharNumber = 0;
        //연산을 눌렀을 경우 첫 숫자 입력하기
        } else if(testing){
            edit.setText(String.valueOf(number));
            plusMinus = false;
            testing = false;
        //연산 후, 숫자 더 추가
        }else {
            plusMinus = false;
            testing = false;
            edit.setText(edit.getText().toString() + String.valueOf(number));
        }
    }
 
    //퍼센트 버튼 클릭시 연산하는 메소드
    private void percentNumber(){
        a = Double.valueOf(edit.getText().toString());
        a *= 0.01;
        edit.setText(String.valueOf(a));
    }
 
    //소수점 추가하기
    private void addDecimalPoint(){
        String checking = edit.getText().toString();
        //'.' 없을시 추가하기
        if(!checking.contains(".")){
            edit.setText(edit.getText().toString() + ".");
        }
    }
 
    //+ or - 추가하는 메소드
    private void addPlusMinus(){
        //plusMinus가 false시 - 추가하고, plusMinus true바꿔주고, 숫자가 -0일수도 있으니 plusMinusCharNumber 1로 변경
        if(!plusMinus) {
            edit.setText("-" + edit.getText().toString());
            plusMinus = !plusMinus;
            plusMinusCharNumber = 1;
        }
        //plusMinus true시 '-' 없이 저장, plusMinus false바꿔주고, CharNumber 0로 변경
        else if(plusMinus /*|| edit.getText().toString().charAt(0) == '-'*/){
            edit.setText(edit.getText().toString().substring(1, edit.getText().toString().length()));
            plusMinus = !plusMinus;
            plusMinusCharNumber = 0;
        }
    }
 
    //연산해주는 메소드
    private void checkEquals(){
        //2 = /, 3 = *, 4 = -, 5 = +
        if(where == 2){
            a /= Double.valueOf(edit.getText().toString().trim());
            settingText();
            randomGenerator();
        } else if(where == 3){
            a *= Double.valueOf(edit.getText().toString().trim());
            settingText();
            randomGenerator();
        } else if(where == 4){
            a -= Double.valueOf(edit.getText().toString().trim());
            settingText();
            randomGenerator();
        } else if(where == 5){
            a += Double.valueOf(edit.getText().toString().trim());
            settingText();
            randomGenerator();
        }
    }
 
    //계산기 리셋해주는 메소드
    public void checkC(){
        edit.setText("0");
        a = 0.00;
        plusMinus = false;
        testing = false;
    }
    //시작시 만들자
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(getApplicationContext(), "Calculator", Toast.LENGTH_SHORT).show();
 
        //Button ids
        introduction = findViewById(R.id.calculation_introduction);
 
        button_c = findViewById(R.id.button_c);
        button_plusMinus = findViewById(R.id.button_plusMinus);
        button_percent = findViewById(R.id.button_percent);
        button_divide = findViewById(R.id.button_divide);
 
        button_7 = findViewById(R.id.button_7);
        button_8 = findViewById(R.id.button_8);
        button_9 = findViewById(R.id.button_9);
        button_multiply = findViewById(R.id.button_multiply);
 
        button_4 = findViewById(R.id.button_4);
        button_5 = findViewById(R.id.button_5);
        button_6 = findViewById(R.id.button_6);
        button_minus = findViewById(R.id.button_minus);
 
        button_1 = findViewById(R.id.button_1);
        button_2 = findViewById(R.id.button_2);
        button_3 = findViewById(R.id.button_3);
        button_plus = (Button)findViewById(R.id.button_plus);
 
        button_0 = findViewById(R.id.button_0);
        button_dot = findViewById(R.id.button_dot);
        button_equals = findViewById(R.id.button_equals);
 
        edit = findViewById(R.id.calculation_result);
 
        //Listener functions
        View.OnClickListener cl = new View.OnClickListener(){
 
            @Override
                public void onClick(View v) {
                    if(v == button_1) typingNumber(1);
                    else if(v == button_2) typingNumber(2);
                    else if(v == button_3) typingNumber(3);
                    else if(v == button_4) typingNumber(4);
                    else if(v == button_5) typingNumber(5);
                    else if(v == button_6) typingNumber(6);
                    else if(v == button_7) typingNumber(7);
                    else if(v == button_8) typingNumber(8);
                    else if(v == button_9) typingNumber(9);
                    else if(v == button_0) typingNumber(0);
                    else if(v == button_percent) percentNumber();
                    else if(v == button_dot) addDecimalPoint();
                    else if(v == button_c) checkC();
                    else if(v == button_plusMinus) addPlusMinus();
                    else if(v == button_divide){
                        saveNumber();
                        where = 2;
                    } else if(v == button_multiply){
                        saveNumber();
                        where = 3;
                    } else if(v == button_minus){
                        saveNumber();
                        where = 4;
                    } else if(v == button_plus){
                        saveNumber();
                        where = 5;
                    } else if(v == button_equals) checkEquals();
            }
        };
 
        //Sets the listeners per button
        button_c.setOnClickListener(cl);
        button_plusMinus.setOnClickListener(cl);
        button_percent.setOnClickListener(cl);
        button_divide.setOnClickListener(cl);
 
        button_7.setOnClickListener(cl);
        button_8.setOnClickListener(cl);
        button_9.setOnClickListener(cl);
        button_multiply.setOnClickListener(cl);
 
        button_4.setOnClickListener(cl);
        button_5.setOnClickListener(cl);
        button_6.setOnClickListener(cl);
        button_minus.setOnClickListener(cl);
 
        button_1.setOnClickListener(cl);
        button_2.setOnClickListener(cl);
        button_3.setOnClickListener(cl);
        button_plusMinus.setOnClickListener(cl);
 
        button_0.setOnClickListener(cl);
        button_dot.setOnClickListener(cl);
        button_equals.setOnClickListener(cl);
 
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'ETC' 카테고리의 다른 글

Applied Accesbility  (0) 2020.02.05
Basic settings for web(02/05/20 cudo notes 3)  (0) 2020.02.05
계산기 strings.xml  (0) 2020.02.04
계산기 activity_main.xml  (0) 2020.02.04
android studio(2/03/20~2/04/20 cudo notes 3)  (0) 2020.02.03

+ Recent posts