Friday, May 15, 2020

Install a package in centos

# tar -xvf findutils-4.7.0.tar
# cd findutils-4.7.0
# ./configure
#make
#make install
# xargs --version
xargs (GNU findutils) 4.7.0
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.


Thursday, January 4, 2018

VIM - Tips

MAPPING

# mapping ESC key to F5
:imap <f5> <esc>

SEARCH

# search white space 15 or more
/\s\{15,}


# searches for trailing white space and deletes it everywhere in the buffer
:%s/\s\+$//e
:%s/\s\+$ or :%s/\s\+$//
The "e" flag tells ":substitute" that not finding a match is not an error.

# selected ares, search _eng, add # in the beginning of the line
:'<,'>g/\%V_eng/s/^/#/

# Visual Select
:'<,'>s/\%V1/0/g
selected area, replace 1 to 0

# replace selected lines
:'<,'>s/eqr/pattern":"fsfpb0ph","

:'<,'>s/\%V-/ /g
#replace "-" with " " in selected area

#replace space with new line
:%s/ /\r/g

# To change to the directory of the currently open file for all windows
:cd %:p:h

# To change to the directory only for the current window
:lcd %:p:h
     % gives the name of the current file,
     %:p gives its full path,
     %:p:h gives its directory (the "head" of the full path).

# replace " " with a new line
:%s/ /\r/g

# combine multiple lins to one line
%j

# Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
:%s/foo/bar/g

# Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
:s/foo/bar/g

# search [00:49:33.151] with any number
/[..:..:..\....\]

zz - move current line to the middle of the screen
zt - move current line to the top of the screen
zb - move current line to the bottom of the screen
z<enter> - move current line to the bottom of the screen

# Show all tabs:
/\t

# Show spaces before a tab:
/ \+\ze\t

# Convert tabs to space
:retab

# Show trailing whitespace:
/\s\+$

# Show trailing whitespace only after some text (ignores blank lines):
/\S\zs\s\+$

# ignore case
:set ignorecase
:set ic

# consider case
se noic

# search a pattern and add a character at the beginning of the line
:%g/_eng/substitute/^/#/

Recording macro

Each register is identified by a letter a to z.

# To enter a macro, type:
q<letter><commands>q

# To execute the macro
 <number> times (once by default), type:

<number>@<letter>

# So, the complete process looks like:
qd  start recording to register d
... your complex series of commands
q   stop recording
@d  execute your macro
@@  execute your macro again
# end of recording macro #

# to join all lines in a file into a single line
# "ggVG" visually selects all lines, and "J" joins them.
ggVGJ

# Align Colmun
:%!column -t #Align Colmun

# search square bracket of "A" char
/\["A", *[0-9-e.]*\]                                                                                                                                          2230,461      44%

# search square bracket of "A" char and replace
:%s/\["A", *[0-9-e.]*\]/["A", "auto"]/

# align column for selected column
:'<,'>%!column -t

# select columbn and override it
???

# split window horizontal
:sp filename

# split window vertical
:vs filename

# grep file names and open it
gvim `grep tmLatchTrim patterns/* -l`

# Switching case of characters
Toggle case "HellO" to "hELLo" with g~ then a movement.
Uppercase "HellO" to "HELLO" with gU then a movement.
Lowercase "HellO" to "hello" with gu then a movement.

Saturday, September 9, 2017

Python: control statement

scope=[1,2,3]
for x in scope
   print(x)
   break
else:
   print("Perfect")

Output:
1

break를 지우면,
Output:
1
2
3
Perfect


while condition:
   repeating_code
   continue   # return to while condition
   ...
   break       # exit while condition


Saturday, August 26, 2017

Python: tips for variables

키워드를 변수로 사용 : SyntaxError
키워드 확인
>>> import keyword
>>> keyword.kwlist

module 이름을 변수로 사용: 모듈사용못함, 하면 TypeError
>>> abs=1 # now abs type is 'int'
# How to use abs() function?

>>> abs = 1
>>> type(abs)
<type 'int'>         # abs is int variable
>>> abs(-2)        # TypeError

Traceback (most recent call last):
  File "<pyshell#137>", line 1, in <module>
    abs(-2)
TypeError: 'int' object is not callable
>>> del abs       # delete int variable; remain internal function abs()
>>> type(abs)
<type 'builtin_function_or_method'>
>>> abs(-2)
2
>>>

Python: calling a class/method with parenthesis vs. no-parenthesis? whats the diff?

calling a class/method with parenthesis vs. no-parenthesis? whats the diff?



>>> class Service:
secret = "He is a alian."
def setname(self, name):
self.name=name
def sum(self,a,b):
print "{}, {}+{} = {}".format(self.name,a,b,a+b)

code source: https://wikidocs.net/28


aman = Service()
awoman = Service

>>> type(aman)
<type 'instance'>
>>> type(awoman)
<type 'classobj'>
>>> 

classobj can assign a instance.

>>> kim=awoman()
>>> type(kim)
<type 'instance'>

>>> aman.setname("Strong")
>>> awoman.setname("Beauty")

Traceback (most recent call last):
  File "<pyshell#58>", line 1, in <module>
    awoman.setname("Beauty")
TypeError: unbound method setname() must be called with Service instance as first argument (got str instance instead)
>>>