웹페이지에서 URL에 사용되는 문자열을 encode하고 decode 해보자.


환경 및 선수조건

  • Javascript


Percent-encoding

  • Percent-encoding이란 URI 혹은 URL에 문자를 표현하는 인코딩 방식으로 RFC 3986에 따라서 알파벳이나 숫자 등 몇몇 문자를 제외한 문자들에 대해서 옥텟 값으로 묶어서 16진수 값으로 코딩하는 방식

  • 예시 : "/internet url" -> "internet%20url"


encodeURI()와 decodeURI() 함수

  • encodeURI() : 일반 문자열을 퍼센트 인코딩된 문자열로 변환
  • decodeURI() : 인코딩된 문자열을 일반 문자열로 변환

var uri = "my test.asp?name=ståle&car=saab";
var enc = encodeURI(uri);
var dec = decodeURI(enc);

console.log(enc); //"my%20test.asp?name=st%C3%A5le&car=saab"
console.log(dec); //"my test.asp?name=ståle&car=saab"


참고자료

Python에서 연산자 ‘/’와 ‘//’의 차이를 알아보자


환경

  • Python


연산자 ‘/’와 ‘//’의 차이

  • /는 나눗셈을 의미하며 결과가 float로 나타납니다.
  • //는 나눗셈을 의미하며 결과가 int로 나타납니다.


코드

  • /의 경우
>>> type(5/2)
<class 'float'>
  • //의 경우
>>> type(5//2)
<class 'int'>

알고리즘 문제풀이 Github 포스트 링크

혼자 공부하고 가볍게 정리하는 Github 저장소


문제풀이 Github 주소


주어진 문자열이 palindrome(회문)인지 확인하는 코드를 작성해보자


환경 및 선수조건

  • Python
  • C++


Palindrome(회문)이란?

  • Palindrome(회문)은 문자열을 거꾸로 해도 원래의 문자열과 같은 문자열인 특징을 가지고 있는 문자열을 가리키는 말입니다.
  • 예시 : 토마토, abdba, 토마토맛토마토, 1234567654321


코드

  • 시간복잡도 : O(n)


C


#include <stdio.h>
#include <string.h>

int is_palindrome(char * s){

	int len = strlen(s);

	int left = 0;
	int right = len-1;


	// 왼쪽과 오른쪽을 하나씩 가운데로 향하면서 비교
	// (right - left) > 1
	// [홀수 길이의 경우] 가운데 원소만 남겨두거나
	// [짝수 길이의 경우] left + 1==right일 때까지!
	while ( (right - left) > 1 ) {

		if( s[right] != s[left] ){
			return 0;
		}
		left += 1;
		right -= 1;
	}

	return 1;

}


int main (){


	char * palindrome = "abcdcba";
	char * non_palindrome = "abcdefg";

	printf("%d\n", is_palindrome(palindrome));
	printf("%d\n", is_palindrome(non_palindrome));

	return 0;

}


C++


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool is_palindrome(string s){

	string s_reverse = s;
	reverse(s_reverse.begin(), s_reverse.end());
	return s == s_reverse ? true : false;

}


int main (){

	string s1 = "abcde1edcba";
	string s2 = "asdlkfjaw;oefjao;iwefja;ow";

	cout << is_palindrome(s1) << '\n';
	cout << is_palindrome(s2) << '\n';

	return 0;

}


Python


def is_palindrome(s):
	return s == s[::-1]


s1 = "abcde1edcba"
s2 = "fjaw;"

print(is_palindrome(s1))
print(is_palindrome(s2))


참고자료

Setting Python and Node.js environment in Travis CI, build and test using Appium.


Environment and Prerequisite

  • Travis CI
  • Experience of test Android using local Appium(Server+python-client)


Process

We can use default Android environment in Travis CI. We will set up Appium(Node.js and Python) environment in yml.


  1. Android Setting
    • language and base setting
    • sdk and android related setting
  2. Python Environment Setting
    • install pyenv and virtualenv
    • set virtual environment and install packages(pytest, Appium-Python-Client etc…)
  3. Node.js Environment Setting
    • install node.js
    • install appium
  4. Run Appium
  5. Run Emulator
  6. Build and Test


1. Android Setting

Our Travis CI already serves all environment for android. Just type somethings like SDK or build-tools and others.

language and base setting

.travis.yml

language: android
sudo: required # We need sudo
jdk: oraclejdk8 # Can be changed by your preference


.travis.yml

language: android
sudo: required # We need sudo
jdk: oraclejdk8 # Can be changed by your preference

android:
    components:

        # Below codes are for using latest Android SDK Tools
        - tools
        - platform-tools

        # build-tools
        - build-tools-26.0.2

        # The SDK version used to compile your project
        - android-26
        - android-22
        - android-24

        # Additional components
        - extra-google-google_play_services
        - extra-google-m2repository
        - extra-android-m2repository
        - addon-google_apis-google-26

        # System image for your emulator
        # You need at least one system image
        - sys-img-armeabi-v7a-android-22
        - sys-img-armeabi-v7a-android-24


2. Python Environment Setting

Install pyenv and virtualenv for python environment. We need python for installing Appium-Python-Client in Appium

install pyenv and virtualenv

.travis.yml


...

# I just type install codes in before_install part
before_install:
    - sudo apt-get update

    # Install ubuntu packages for later usage
    - sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev
      libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

    # Set up pyenv
    - git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    - echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    - echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    - echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

    # Set up virtualenv
    - git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
    - echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
    - source ~/.bash_profile
    - pyenv versions


set virtual environment and install packages

Below requirements.txt is package list. You can type your packages if you want.

.travis.yml


...

    # Install python 3.6.1
    - pyenv install 3.6.1

    # Set up virtual environment (virtualenv name is undang in this case)
    - pyenv virtualenv 3.6.1 undang
    - pyenv activate undang
    - python -V

    # Install packages
    # Essential packages : Appium-Python-Client, pytest
    - pip install -r requirements.txt


3. Node.js Environment Setting

install node.js

You can check installation guide in here “[Ubuntu](EN) Install latest npm and nodejs by using ppa

.travis.yml


...

    # Install node.js and npm
    - curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
    - sudo apt-get install nodejs
    - sudo apt-get install build-essential


install appium

.travis.yml


...

    # Add $JAVA_HOME/bin to PATH (for Appium executing)
    - PATH=$PATH:$JAVA_HOME/bin

    # Install appium and appium-doctor
    - npm install appium
    - npm install appium-doctor


4. Run Appium

.travis.yml


...

    # Run appium-doctor
    - "./node_modules/.bin/appium-doctor"

    # Run appium in background and logging to appium_log.txt file
    - "./node_modules/.bin/appium --log-level info > appium_log.txt &"


5. Run Emulator

.travis.yml


...


before_script:

    # Create emulator (emulator image version should be exist in previous android setting)
    - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a

    # Run emulator
    - emulator -avd test -no-skin -no-window &
    - android-wait-for-emulator
    - adb shell input keyevent 82 &


6. Build and Test

.travis.yml


script:
    - "./gradlew assemble" # Build
    - pytest # Test

after_script:
    - cat ./appium_log.txt # Check appium log


Final result of .travis.yml

.travis.yml

language: android
sudo: required
jdk: oraclejdk8
android:
    components:
        - tools
        - platform-tools
        - build-tools-26.0.2
        - android-26
        - android-22
        - android-24
        - extra-google-google_play_services
        - extra-google-m2repository
        - extra-android-m2repository
        - addon-google_apis-google-26
        - sys-img-armeabi-v7a-android-22
        - sys-img-armeabi-v7a-android-24
before_install:
    - sudo apt-get update
    - sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev
      libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
    - git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    - echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    - echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    - echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
    - git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
    - echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
    - source ~/.bash_profile
    - pyenv install 3.6.1
    - pyenv virtualenv 3.6.1 undang
    - pyenv activate undang
    - pip install -r requirements.txt
    - curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
    - sudo apt-get install nodejs
    - sudo apt-get install build-essential
    - PATH=$PATH:$JAVA_HOME/bin
    - npm install appium
    - npm install appium-doctor
    - "./node_modules/.bin/appium-doctor"
    - "./node_modules/.bin/appium --log-level info > appium_log.txt &"
before_script:
    - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
    - emulator -avd test -no-skin -no-window &
    - android-wait-for-emulator
    - adb shell input keyevent 82 &
script:
    - "./gradlew assemble"
    - pytest
after_script:
    - cat ./appium_log.txt


Reference