Skip to content

Instantly share code, notes, and snippets.

@parkjinwoo
Last active March 27, 2017 01:09
Show Gist options
  • Save parkjinwoo/65210739a21bcafd1039719f18b83407 to your computer and use it in GitHub Desktop.
Save parkjinwoo/65210739a21bcafd1039719f18b83407 to your computer and use it in GitHub Desktop.
work

Command Editing Shortcuts

  • Ctrl + a – go to the start of the command line
  • Ctrl + e – go to the end of the command line
  • Ctrl + k – delete from cursor to the end of the command line
  • Ctrl + u – delete from cursor to the start of the command line
  • Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
  • Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
  • Ctrl + xx – move between start of command line and current cursor position (and back again)
  • Alt + b – move backward one word (or go to start of word the cursor is currently on)
  • Alt + f – move forward one word (or go to end of word the cursor is currently on)
  • Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
  • Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
  • Alt + u – make uppercase from cursor to end of word
  • Alt + l – make lowercase from cursor to end of word
  • Alt + t – swap current word with previous
  • Ctrl + f – move forward one character
  • Ctrl + b – move backward one character
  • Ctrl + d – delete character under the cursor
  • Ctrl + h – delete character before the cursor
  • Ctrl + t – swap character under cursor with the previous one

Command Recall Shortcuts

  • Ctrl + r – search the history backwards
  • Ctrl + g – escape from history searching mode
  • Ctrl + p – previous command in history (i.e. walk back through the command history)
  • Ctrl + n – next command in history (i.e. walk forward through the command history)
  • Alt + . – use the last word of the previous command

Command Control Shortcuts

  • Ctrl + l – clear the screen
  • Ctrl + s – stops the output to the screen (for long running verbose command)
  • Ctrl + q – allow output to the screen (if previously stopped using command above)
  • Ctrl + c – terminate the command
  • Ctrl + z – suspend/stop the command

Bash Bang (!) Commands : Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.

  • !! – run last command
  • !blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
  • !blah:p – print out the command that !blah would run (also adds it as the latest command in the command history)
  • !$ – the last word of the previous command (same as Alt + .)
  • !$:p – print out the word that !$ would substitute
  • !* – the previous command except for the last word (e.g. if you type ‘find some_file.txt /‘, then !* would give you ‘find some_file.txt‘)
  • !:p – print out what ! would substitute
## resize image
for i in {1..7}; do sips -z 43 43 71x53_$i.jpg --out 43x43_$i.jpg; done
## capture a packet trace
sudo tcpdump -i en0 -s 0 -B 524288 -w ~/Desktop/DumpFile01.pcap
sudo tshark -V -r ~/Desktop/DumpFile01.pcap > ~/Desktop/DumpFile01.txt
## kill tomcat proc.
ps -ef | grep tomcat | awk '{print $2}' | xargs kill -9
## find grep
find . -name "*.ext" -exec grep -Zrwl "pattern"
## find grep sed
find . -name "*.ext" -exec grep -Zrwl "pattern" \; | xargs -0 sed -i '' "s/[[:<:]]pattern[[:>:]]/replace/g"
find -name "*.ext" -exec sed -s --in-place=.bak -e 's/firstWord/newFirstWord/g;s/secondWord/newSecondWord/g;s/thirdWord/newThirdWord/g' {} \;
find ./ -type f -exec sed -i 's/string1/string2/' {} \;
## jdk 1.7
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/
## log filter
awk '$3 ~ /^14:/ && $7 == "[ExecutionTime]" && $8 > 20000' catalina.out | perl -ne 'print "$1\n" if /(\/\*(.*?)\*\/)/' | sort | uniq -c
## Mac netstat alter.
lsof -i :9012
## IPython Shortcut
Ctrl + p, n : History
Ctrl + r : History
Ctrl + Shift + v : Clipboard to Paste
Ctrl + c : Break
Ctrl + a, e : Home, End
Ctrl + f, b : cursor move
Ctrl + k : delete text
Ctrl + u : delete text
Ctrl + l : clear
## IPython Magic
? ??
%quichref : Help
%magic : help
%debug : debugger
%hist : history
%pdb : debugger
%paste : clipboard
%cpaste : prompt
%reset : reset
%page OBJECT :
%run script.py :
%run -p :
%prun statement : cProfile
%time statement :
%timeit statement :
%who, %who_ls, %whis : display var
%xdel var : remove
%alias :
%bookmark :
%logstart, %logoff, %logon, %logstate, %logstop: logging
!unix_cmd
%%store
%store someout >> file.log
커서이동
Ctrl f, b, n, p (화살표와 동일)
Ctrl v, Alt v (PgUp, PgDn)
Ctrl a, Ctrl e (Home, End)
Alt f, b (단어단위로 앞뒤이동)
Alt a, e (문단 앞, 뒤로 이동)
Alt <, > (파일의 처음, 끝으로 이동)
Alt r (커서를 페이지의 처음,끝,가운데로 이동)
Ctrl l (커서가 포함된 줄을 화면 처음, 끝, 가운데로 이동)
Alt g - Alt g (원하는 줄로 이동)
삽입
Ctrl o (빈줄 삽입, 커서 제자리)
Ctrl j (빈줄 삽입, 커서 아래로)
Ctrl x - i (파일 삽입)
Ctrl y (kill한 내용 삽입)
삭제
Ctrl d (커서에있는 글자삭제)
BackSpace (커서 앞에있는 글자삭제)
Alt d (커서에 있는 단어삭제)
Alt BackSpace (커서 앞에있는 단어삭제)
Ctrl k (커서부터 줄끝까지 삭제)
Ctrl w (선택영역 kill)
영역
Ctrl Space (영역선택시작, 종료)
Ctrl x - Ctrl x (선택영역 시작지점 변경)
Ctrl x - h (전체선택)
Alt w (복사와 비슷)
Ctrl w (잘라내기와 비슷)
Ctrl y (붙여넣기와 비슷)
검색
Ctrl s (아래로검색)
Ctrl r (위로검색)
Ctrl % (치환)
Alt u (단어 대문자로 변경)
Alt l (단어 소문자로 변경)
Alt c (단어중 맨 앞글자만 대문자로변경)
Ctrl x - Ctrl t (윗줄과 내용을 바꿈)
Alt t (앞단어와 내용을 바꿈)
Ctrl t (커서가 줄선두에 있을때 윗줄로 글자보냄)
Dired 모드 (디렉토리 모드)
f (파일 열기, 없으면 생성)
v (파일 열기, 읽기전용)
D (파일 삭제)
g (디렉토리 목록갱신)
R (파일 이름 변경)
C (파일 복사)
Alt x - make-directory - Enter (디렉토리 생성)
+ (디렉토리 생성)
Ctrl x - d (dired 모드 진입)
Alt x - dired - Enter (dired 모드 진입)
인코딩
Ctrl x - Enter - r (인코딩 보는방식 변경)
Ctrl x - Enter - f (인코딩 저장방식 변경)
(팁:미니버퍼에서 tab 누르면 목록 나옴)
(euc-kr, cp949, utf-8, utf-16-le 등..)
Ctrl \ (한글, 영어 변경)
leftShift Space (한글, 영어 입력방식 변경)
F9 (한글이나 자음등을 한자, 특수문자등으로 변환)
파일
Ctrl x - Ctrl f (파일열기, 없을시 새로생성)
Ctrl x - Ctrl s (파일 저장)
Ctrl x - Ctrl w (다른이름으로 저장)
Ctrl x - k (버퍼 닫기)
Ctrl x - b (버퍼 이동, 화살표 위아래키로 목록열람가능)
Ctrl x - Ctrl b (새 프레임을 열고 버퍼 목록 표시)
프레임(스프릿)
Ctrl x - 2 (상하로 프레임분리)
Ctrl x - 3 (좌우로 프레임분리)
Ctrl x - 1 (현제프레임만 남기도 나머지 없애기)
Ctrl x - 0 (현제프레임을 없애고 하나로 합치기)
Ctrl x - ^ (현제프레임 수직크기 키우기, 보통 Ctrl - u 와 함께씀)
Ctrl x - {, } (현제프레임 좌우크기 조절)
Ctrl + (프레임들 크기 일정하게)
Ctrl x - o (프레임간 이동)
기타
Ctrl g (명령취소)
Ctrl / (실행취소)
Ctrl x - u (실행취소)
Ctrl u - 숫자 (반복작업)
Alt ! (간단한 쉘명령)
Alt - shell - Enter (쉘 불러오기)
Alt x - hexl-mode - Enter (헥사모드)
Ctrl x - Enter - r - cp437 (nfo 파일볼때)
Alt ; (주석 처리)

monad

  • visitor pattern : operation 추가 쉬워지고, data 추가 어려워짐 (oop에서의 workaround)
  • Category : id , composition operator 정의
  • Monad : id, bind (application, apply) 정의
  • Promise, Future,
  • 렌즈, 펑터 확장, getter setter 조합 등에 응용- 렌즈, 펑터 확장, getter setter 조합 등에 응용

monad review

  • a -> ma (return)
  • ma -> (a -> mb) -> mb (>>= bind)
  • a -> (a -> b) -> b (function application)
  • Category : id, composition 정의
  • (b -> mc) -> (a -> mb) -> (a -> mc) (>=>. >>>)
  • (b -> c) -> (a -> b) -> (a -> c) (function composition)

monad transformer

  • mtl
  • 성능 트레이드오프

Multi-armed Bandit

  • 변인통제: A/B Test
  • A/B Test의 문제: 장기 유지시(탐험하기) 잘 안되는 것에서 손해
  • 탐험하기(exploration)/뽑아먹기(exploitation) 딜레마
  • "Good decisions come from experience, and experience comes from bad decisions."
  • 여러 시안이 있고, 각 시안에 따라 웹 사이트의 성과에 차이가 있음
  • 가장 적은 비용으로 가장 성과가 좋은 시안을 찾고 싶다면 어떤 시안을 어떤 순서로 얼마나 많이 노출해야 할까?

A/B Testing as a MAB Algorithm

  • 정해진 기간동안은 탐험만 하기
  • 그 기간 이후에는 평생 뽑아먹기
  • 세상이 바뀌면 어떻게 하나?
  • 실험 기간 동은은 성과가 안 좋은 버전에 계속 사용자를 밀어 넣어야 하나?
  • 사용자 수가 적거나, 실험 안의 갯수가 많거나, 실험 기간이 짧으면 어떻게 할까?
  • 비윤리적인 행위를 해도 되는가?

MAB 알고리즘: e-Greedy

  • 0에서 1 사이의 난수를 생성
  • 이 수가 e보다 크면 뽑아먹기를 수행
  • 그렇지 않으면 탐험하기를 수행
  • e값: 보상률 차이가 클수록 낮게 잡는다

MAB 알고리즘: Softmax

  • A/B 비율만큼 분배
  • 성과 차이가 클 때 유용
  • 온도에 따라 e-Greedy or A/B

MAB 알고리즘: UCB1

  • 아직 한번도 테스트를 안해본 팔이 있으면 그 팔을 당긴다
  • 모든 팔을 최소 한번씩 당겨본 상태라면 각 팔에 대해여 다음을 계산하여 그 값이 가장 큰 팔을 당긴다.
  • 보상률이 좋은 팔에는 기회를 더 준다.
  • 당겨본 횟수가 적은 팔에는 기회를 더 준다.

A/A 테스팅

  • 같은 걸 넣어 봄: UCB1은 통과하지 못 함

Etc

  • 새로 관측한 값에 가중치를 두어야 하지 않을까?
  • 결론: Google Analytics의 Content experiment를 써라
#!/usr/bin/env bash
display_usage() {
echo "This script must be run with super-user privileges."
echo -e "\nUsage:\n`basename $0` [arguments] \n"
}
while [ "$#" -gt "0" ]; do
case $1 in
-O|--only)
ONLY=1
;;
-A|--after)
shift
AFTER=$1
;;
-B|--before)
shift
BEFORE=$1
;;
-C|--context)
shift
CONTEXT=$1
;;
-h|--help)
display_usage
exit 0
;;
*)
echo "Syntax Error"
display_usage
exit 1
;;
esac
shift
done
while [ "$#" -gt 0 ]; do
case "$1" in
-n) name="$2"; shift 2;;
-p) pidfile="$2"; shift 2;;
-l) logfile="$2"; shift 2;;
--name=*) name="${1#*=}"; shift 1;;
--pidfile=*) pidfile="${1#*=}"; shift 1;;
--logfile=*) logfile="${1#*=}"; shift 1;;
--name|--pidfile|--logfile) echo "$1 requires an argument" >&2; exit 1;;
-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done
echo "ONLY=${ONLY}"
echo "AFTER=${AFTER}"
echo "BEFORE=${BEFORE}"
echo "CONTEXT=${CONTEXT}"

Pro React

import React, { Component, PropTypes } from 'react'
constructor() {
  super(...arguments);
  this.state = {
    showDetails: false
  };
}
<ul>
  {fileredContacts.map(
    (contact) => <ContactItem key={contact.email}
                              name={contact.name}
                              email={contact.email} />
  )}
</ul>
Counter.propTypes = { initialCount: React.PropTypes.number };
Counter.defaultProps = { initialCount: 0 };
static defaultProps = {
  btnHide: false
};
static propTypes = {
  heading: PropTypes.string,
  editMode: PropTypes.bool,
  btnHide: PropTypes.bool,
  btnLabel: PropTypes.string
};
{(() => {
  switch (this.state.color) {
    case "red":   return "#FF0000";
    case "green": return "#00FF00";
    case "blue":  return "#0000FF";
    default:      return "#FFFFFF";
  }
})()}
python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read()))"
python -c "import urllib, sys; print urllib.unquote(sys.stdin.read())"
python3 -c "import sys; from urllib.parse import quote; print(quote(sys.stdin.read()))"
python -c "import urllib, sys; print urllib.quote(sys.stdin.read())"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment