Coder Social home page Coder Social logo

eubnara / study Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 2.0 37.04 MB

C 67.44% Shell 0.47% Go 10.10% Python 1.28% JavaScript 1.48% HTML 0.39% CSS 2.04% TypeScript 0.03% XSLT 9.70% Scala 0.74% PHP 0.01% Makefile 3.49% Awk 1.33% Dockerfile 0.01% Pug 0.06% C++ 1.05% Java 0.38%

study's Introduction

Study

Subjects & Current status

study's People

Contributors

eubnara avatar

Stargazers

 avatar Bumsoo Kim avatar Seunggabi Kim avatar Christian avatar Choi Seungwee avatar Joosung Yoon avatar

Watchers

James Cloos avatar Choi Seungwee avatar Seunggabi Kim avatar  avatar Christian avatar

Forkers

myae3080

study's Issues

npm request 관련

설치: npm install request

var somevariable;
request('url', function(error, response, body) {
    somevariable = JSON.parse(body)['item'];
}

request('url', function(error, response, body) {
    console.log(somevariable);
}

두번째 호출에서 전역변수인 somevariable을 쓰려고 하였으나, 값이 없는 상태가 되버린다.

-> 순차실행이 아니라 async하게 실행되는 듯 싶다.

Channel, Buffering, Non-Blocking

Channel

  • go routine 에서 messages 라는 채널로 보내고
  • main 함수에서 받는 모습
package main
import "fmt"

func main() {
    messages := make(chan string)
    go func() { messages <- "ping" } ()
    msg := <-messages
    fmt.Println(msg)
}
  • 다음은 에러
  • fatal error: all goroutines are asleep - deadlock!
package main
import "fmt"

func main() {
    messages := make(chan string)
    messages <- "ping"
    msg := <-messages
    fmt.Println(msg)
}

Buffering

  • Channel 에서 에러가 났던 부분을 Buffering 을 통해 수정가능
  • make(chan string, 1)
package main
import "fmt"

func main() {
   messages := make(chan string, 1)
   messages <- "ping"
   msg := <-messages
   fmt.Println(msg)
}

Non-Blocking

  • select 에서 default: 부분
package main
import "fmt"

func main() {
    messages := make(chan string)
    select {
    case msg := <-messages:
        fmt.Println("received message", msg)
    default:
        fmt.Println("no activity")
    }
}

docker 간단한 작업

docker container 에서 파일 꺼내기

$ sudo docker cp hello-nginx:/etc/nginx/nginx.conf ./

shell expansion

https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html#Shell-Expansions

  • Brace Expansion: Expansion of expressions within braces.
  • Tilde Expansion: Expansion of the ~ character.
  • Shell Parameter Expansion: How Bash expands variables to their values.
  • Command Substitution: Using the output of a command as an argument.
  • Arithmetic Expansion: How to use arithmetic in shell expansions.
  • Process Substitution: A way to write and read to and from a command.
  • Word Splitting: How the results of expansion are split into separate arguments.
  • Filename Expansion: A shorthand for specifying filenames matching patterns.
  • Quote Removal: How and when quote characters are removed from words.

python argparse

ArgumentParser.add_argument(name or flags...[, action][, nargs][, const][, default][, type][, choices][, required][, help][, metavar][, dest])
Define how a single command-line argument should be parsed. Each parameter has its own more detailed description below, but in short they are:

name or flags - Either a name or a list of option strings, e.g. foo or -f, --foo.
action - The basic type of action to be taken when this argument is encountered at the command line.
nargs - The number of command-line arguments that should be consumed.
const - A constant value required by some action and nargs selections.
default - The value produced if the argument is absent from the command line.
type - The type to which the command-line argument should be converted.
choices - A container of the allowable values for the argument.
required - Whether or not the command-line option may be omitted (optionals only).
help - A brief description of what the argument does.
metavar - A name for the argument in usage messages.
dest - The name of the attribute to be added to the object returned by parse_args().

docker container 간단히 모두 종료시키기

$ sudo docker rm $(docker ps -aq)

docker ps -aq 명령어를 실행시켰을 때, container id 가 세로로 표시되지만, 띄어쓰기나 다름없으므로 docker rm 명령어의 인자 전달에는 문제가 없다.

hadoop Quota란?

종류

  • name quota: 최대 이름 수 제한(하둡은 큰 파일로 조금 있는 걸 좋아하지, 작은 파일로 여러 개 갖고 있는 걸 좋아하지 않는다. 그 이유는 네임노드가 얘네들에 대한 정보를 메모리에 들고 있는데, 작은파일이 지나치게 많다면 메모리 부족으로 죽어버릴 것이다.)
  • space quota: 말 그대로 용량 제한

https://hadoop.apache.org/docs/r2.7.1/hadoop-project-dist/hadoop-hdfs/HdfsQuotaAdminGuide.html

"."(current directory)를 PATH 환경변수에 넣으면 안되는 이유

tl;dr(요약)

  • PATH 환경변수 앞에 존재해서는 안된다.
    • 흔히 쓰이는 ls 와 같은 이름의 악의적인 프로그램을 만들어 두고, superuser 가 그걸 실행시키도록 유도할 수 있음
  • PATH 환경변수의 마지막에 위치해서도 안된다.
    • ls, more 과 같은 명령어를 현재 디렉터리에 있는 걸 우선적으로 실행시키진 않겠지만, mroe 와 같은 프로그램을 파일시스템 전역에 뿌려놓았을 때, superuser 가 오타로 mroe 를 입력하였을 때, 그 프로그램이 실행될 수 있다.

본문

(Practical UNIX and Internet Security, 3rd Edition 에서 발췌)
STEALING SUPERUSER
Once upon a time, many years ago, one of us needed access to the root account on an academic machine. Although we had been authorized by management to have root access, the local system manager didn’t want to disclose the password. He asserted that access to the root account was dangerous (correct), that he had far more knowledge of Unix than we did (unlikely), and that we didn’t need the access (incorrect). After several diplomatic and bureaucratic attempts to get access normally, we took a slightly different approach, with management’s wry approval.

We noticed that this user had “.” at the beginning of his shell search path. This meant that every time he typed a command name, the shell would first search the current directory for the command of the same name. When he did a su to root, this search path was inherited by the new shell. This was all we really needed.

First, we created an executable shell file named ls in the current directory:

#!/bin/sh
cp /bin/sh ./stuff/junk/.superdude
chmod 4555 ./stuff/junk/.superdude
rm -f $0
exec /bin/ls ${1+"$@"}
Then, we executed the following commands:
% cd 
% chmod 700 .
% touch ./-f

The trap was ready. We approached the recalcitrant administrator with the complaint, “I have a funny file in my directory I can’t seem to delete.” Because the directory was mode 700, he couldn’t list the directory to see the contents. So, he used su to become user root. Then he changed the directory to our home directory and issued the command ls to view the problem file. Instead of the system version of ls, he ran our version. This created a hidden setuid root copy of the shell, deleted the bogus ls command, and ran the real ls command. The administrator never knew what happened.

We listened politely as he explained (superciliously) that files beginning with a dash character (-) needed to be deleted with a pathname relative to the current directory (in our case, rm ./-f); of course, we knew that.

A few minutes later, he couldn’t get the new root password.

참고

  • Practical UNIX and Internet Security, 3rd Edition
    • Chapter 5, STEALING SUPERUSER
    • Chapter 16
    • Chapter 23

파일이름 한번에 바꾸는 명령어

예) ts 확장자를 js 로 모두 바꾸는 명령어

for f in *.ts; do mv "$f" "${f%.ts}.js"; done

Shell-Parameter-Expansion

${parameter%word}
${parameter%%word}

The word is expanded to produce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.

  • % 는 % 이하에 매칭되는 것을 삭제하는 명령. %와 %%의 차이는 shortest / longest matching 이다.
  • 위의 예시에서 ${f%.ts}.js 는 파일이름의 끝부분에 있는 .ts 를 지우고 뒤에 .js 를 붙이는 것이다.

npm install globally

https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/

npm 으로 다른 패키지들을 설치할 때, /usr/local 하위로 설치하여 globally 사용하고 싶을 때, --prefix /usr/local 을 사용한다.

cf)
npm, node 를 /usr/local 에 위치시키고 싶다면, nodejs 공식홈페이지에서 소스를 다운받은 후에, 압축을 풀어 하위 디렉터리에 있는 /bin /include /share /lib 등의 디렉터리를 /usr/local 하위로 복사하자.

그리고 난 뒤에 npm install -g npm 를 해주면 최신버전의 npm 이 설치된다.

maven repository

maven 에서 local repository 를 명시할 수도 있다.
local repository, central repository 에서 pom.xml 에 나와있는 package 들을 찾는다.

central repository 는 어디에 명시되어 있을까?

http://mirror.navercorp.com/apache/maven/maven-3/3.5.0/source/apache-maven-3.5.0-src.tar.gz

위 소스를 다운받아, apache-maven-3.5.0/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml 파일을 열어보면, Central Repositoryhttps://repo.maven.apache.org/maven2 로 명시되어있는 것을 볼 수 있다.

  • 어떠한 POM 이든, parent POM 을 가리킬 수 있는데, 만일 parent POM 이 없다면, superpom 을 가리키게 된다. 위에서 언급한 pom-4.0.0.xml 파일이 바로 superpom 이다. 다음과 같이 주석에도 명시가 되어 있다.

  • pom-4.0.0.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!-- START SNIPPET: superpom -->
<project>
  <modelVersion>4.0.0</modelVersion>

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
...

POM hierarcy

  • 출처: mastering apache maven 3

POM files maintain a parent-child relationship between them. A child POM file inherits all the configuration elements from its parent POM file. This is how Maven sticks to its design philosophy, which is convention over configuration.

"convention over configuration"

javascript의 for in은 python과 다르다.

javascript

for(var i in array) {
        console.log(array[i]);
}

자바스크립트 코드에서 i 는 array 의 한 원소를 가리키는 게 아니라 인덱스를 나타낸다(!)

var obj = {
    id: "myid",
    name: "myname"
}

for(var attr in obj) {
    console.log(attr);
}

배열이 아닌 객체의 요소들을 탐색하면 객체의 속성명이 들어가게 된다(!)

python

>>> someList = [1, 2, 3, 4]
>>> for item in someList:
...     print item
... 
1
2
3
4

파이썬 코드에서는 한 원소를 나타내게 된다.

Node.js에서 쉘스크립트 실행시키기

var exec = require('child_process').exec;
exec('node -v', function(error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
        console.log('exec error: ' + error);
    }
});
var exec = require('child_process').exec;

cf. 위 코드 부분을 app.listen() 함수 이후에 호출하면 정상적으로 동작하지 않는다. app.listen() 이후에 것을 구동하지 않는 듯 하다.

python 에서 asterisk(star)의 의미는 무엇일까?

args, kwargs

In [1]: def foo(*args):
   ...:     for a in args:
   ...:         print a
   ...:         
   ...:         

In [2]: foo(1)
1


In [4]: foo(1,2,3)
1
2
3
  • kwargs는 keyword arguments로서 dictionary 처럼 접근이 가능하다.
In [5]: def bar(**kwargs):
   ...:     for a in kwargs:
   ...:         print a, kwargs[a]
   ...:         
   ...:         

In [6]: bar(name='one', age=27)
age 27
name one

Jekyll으로 만든 웹사이트에서 제공하는 파일은 어떻게 명시하는가?

  • plain text를 작성하는 것만으로도 정적인 웹사이트를 손쉽게 만들 수 있게 해주는 것

알아볼 것

  • YAML front matter(머리말)이 없는 경우에, Jekyll 디렉터리 내의 모든 파일을 있는 그대로 제공할 수 있다.
  • _config.yml 파일에서 exclude 설정을 하면 제외시킬 수 있다.
  • 예) _config.yml
...

exclude:
   - Gemfile
   - Gemfile.lock
...
  • _site 디렉터리는 $ jekyll serve 명령을 실행시킬 때마다 새롭게 갱신된다.
  • 따라서, _site 디렉터리 내에 임의로 파일을 넣어주더라도 $ jekyll serve명령을 실행시키면 없어질 수 있다.
  • $ jekyll serve명령으로 생성된 사이트는 기본값으로 _site 디렉터리에 저장된다. 그렇다면, 명령이 실행될 때마다 새롭게 생성되는 셈이니까 굳이 git과 같은 저장소에 보낼 필요는 없을 것이다. 보통 .gitignore에 _site 디렉터리 path를 추가하곤 한다. jekyll document 참조

_site
This is where the generated site will be placed (by default) once Jekyll is done transforming it. It’s probably a good idea to add this to your .gitignore file.

ubuntu bash prompt 초기화

color_prompt=yes
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

오픈소스에 add class 후 빌드 에러 발생(Too many files with unapproved license)

출처: http://jjeong.tistory.com/1014

[ERROR] Failed to execute goal org.apache.rat:apache-rat-plugin:0.11:check (default) on project ambari-server: Too many files with unapproved license: 1 See RAT report in: /Users/hwjeong/git/ambari/ambari-server/target/rat.txt -> [Help 1]

이 에러는 뭐 오픈소스 사용하면서 class header 에 ASF 라이센스 정보를 작성 하지 않아서 발생하는 것입니다.
그러니 넣어 주시면 에러가 없어 집니다.

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

[FHS] /usr/bin/env /usr/bin /usr/local/bin ...

binary directory 가 참 많다.

/bin/
/sbin/
/usr/bin/
/usr/sbin/
/usr/local/bin/
/usr/local/sbin/
~/bin/

경로를 직접 지정해 주면, dependency 가 생기기 마련이다. env 명령어를 사용하여, PATH 환경변수에 있는 디렉터리에서 찾게끔 할 수 있다. 이렇게 한다면 경로를 직접 명시해서 발생하는 의존성을 줄일 수 있다.
다음은 shebang(hashbang) 에서 python 을 명시하는 방법이다.

#!/usr/bin/env python
print "hello world!"

아래와 같이 하면 less flexible

#!/usr/bin/python
print "hello world!"

cf. env 명령어

https://en.wikipedia.org/wiki/Env

-i 옵션을 주면, 현재 설정되어 있는 모든 환경변수를 무시하고 다른 명령어를 실행할 수 있다.
다음은 환경변수를 clear 하고 새로운 쉘을 켜는 방법이다.

$ env -i /bin/sh

binary directory 정리

출처: https://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux

/bin/
/sbin/
/usr/bin/
/usr/sbin/
/usr/local/bin/
/usr/local/sbin/
~/bin/
  1. /bin (and /sbin) were intended for programs that needed to be on a small / partition before the larger /usr, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh, although the original intent may still be relevant for e.g. installations on small embedded devices.
  2. /sbin, as distinct from /bin, is for system management programs (not normally used by ordinary users) needed before /usr is mounted.
  3. /usr/bin is for distribution-managed normal user programs.
  4. There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin.
  5. /usr/local/bin is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin because future distribution upgrades may modify or delete them without warning.
  6. /usr/local/sbin, as you can probably guess at this point, is to /usr/local/bin as /usr/sbin to /usr/bin.

locally compile 한다면, /usr/local/bin 혹은 /usr/local/sbin 에 위치시키는 것이 옳다.
/bin, /sbin ==> /usr/bin, /usr/sbin ?

FHS(Filesystem Hierarchy Standard)

http://www.pathname.com/fhs/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.