Tuesday, September 10, 2019

Example Python Decorator

ex.1
====

from functools import wraps

from flask import request, jsonify

def token_admin_required(f):
    @wraps(f)
    def decorated(*agrs, **kwagrs):

        token = None

        if 'X-API-KEY' in request.headers:
            token = request.headers['X-API-KEY']

        if not token:
            return jsonify({'message': 'Token is missing.'})

        if token != 'token-key':
            return jsonify({'message': 'Your Token is Wrong or Invalid'})

       # check token
        # print('TOKEN: {}'.format(token) )
        return f(*agrs, **kwagrs)

    return decorated

ex.2
====

import time
import datetime


def decorators(f):
    def wrappers(*args, **kwargs):
        print('Before')
        ret = f(*args, **kwargs)
        print('After')
        return ret
    return wrappers


def timer(f):
    def wrappers(*args, **kwargs):
        before = time.time()
        ret = f(*args, **kwargs)
        print("Function took: ", time.time() - before, "second")
        return ret
    return wrappers


def logger(func):
    def wrappers(*args, **kwargs):
        with open('log.txt', 'a') as f:
            f.write("called function with " + " ".join(
                [str(arg) for arg in args]) + " at " + str(datetime.datetime.now()) + "\n")
            ret = func(*args, **kwargs)
            return ret
    return wrappers


@logger
def add(a, b):
    return a + b


print(add(3, 4))




Monday, September 9, 2019

MongoDB --auth Mode with Docker

#create volume mongo-auth
docker create volume --name mongo-auth

​#Start Container id with option --auth:
​docker run -d --name mongo_auth -p 27017:27017 -v mongo-auth:/data/db mongo --auth
docker exec -it container_id mongo admin

#Add administrator user for "admin" database
db.createUser({ user: 'admin', pwd: 'password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });

#Logout and Login Again with user/password
docker exec -it container_id mongo -u username databasename
ex.

docker exec -it container_id mongo -u admin admin

#Create News Database

use NEWDB

#Add AD admin user for "NEWDB" database
db.createUser({ user: 'app', pwd: 'password', roles: ["readWrite", "dbAdmin"] });

#Login New Mongo DB with user Authentication
​docker exec -it Container_ID mongo -u database_username  DatabaseName​
ex.

​docker exec -it Container_ID mongo -u app NEWDB​

Tuesday, August 27, 2019

Force start Oracle Goldengate Replicat from Sequence Number

Force start Oracle Goldengate Replicat from Goldengate Sequence Number

error:

OGG-00446 No data selecting position from checkpoint table GGATE.CHECKPOINTTABLE for group


REPLICAT   RMEIS     Last Started 2019-08-26 17:11   Status ABENDED
Checkpoint Lag       00:00:00 (updated 01:09:02 ago)
Log Read Checkpoint  File /data/ggate/dirdat/MEIS/rm000005
                     2019-08-27 09:37:19.154883  RBA 46919569

alter RMEIS extseqno 000005 extrba 46919569

Wednesday, July 24, 2019

VIM Setting Example

setup vundle

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim


edit .vimrc

set nocompatible
syntax on
"enable syntax

set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
colorscheme monokai
set visualbell

" enable line Number
set number

"show hiden charactor
set list

" turn relative line numbers on
set rnu
set paste
set cursorline

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'tpope/vim-surround'
Plugin 'scrooloose/nerdtree'
Plugin 'sickill/vim-monokai'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'Yggdroot/indentLine'

call vundle#end()

set autoindent
set smartindent

filetype plugin indent on


"disable arrows keys

nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>

inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>

" enable AirlineColorscheme bubblegum 
let g:airline_theme='bubblegum'

" Windows move shortcut
map <C-h> :call WinMove('h')<cr>
map <C-j> :call WinMove('j')<cr>
map <C-k> :call WinMove('k')<cr>
map <C-l> :call WinMove('l')<cr>

" Window movement shortcuts
" move to the window in the direction shown, or create a new window
function! WinMove(key)
    let t:curwin = winnr()
    exec "wincmd ".a:key
    if (t:curwin == winnr())
        if (match(a:key,'[jk]'))
            wincmd v
        else
            wincmd s
        endif
        exec "wincmd ".a:key
    endif

endfunction


Install ColorScheme Monokai
mkdir ~/.vim/colors
cd ~/.vim/colors
ln -s ./../bundle/vim-monokai/colors/monokai.vim monokai.vim

:PluginInstall

How to use vim in sqlplus

edit file $ORACLE_HOME/sqlplus/admin/glogin.sql

define_editor=vim

Wednesday, July 3, 2019

SSH Config file

vi ~/.ssh/config

Host *
        HostKeyAlgorithms +ssh-dss
        MACs hmac-sha1
        Ciphers aes256-ctr,aes128-cbc
        # KexAlgorithms diffie-hellman-group-exchange-sha256

        KexAlgorithms diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

Host old_host
  HostKeyAlgorithms +ssh-dss
  KexAlgorithms +diffie-hellman-group1-sha1
  Ciphers aes256-ctr,aes128-cbc


ssh option name check 

ssh -Q cipher       # List supported ciphers
ssh -Q mac          # List supported MACs
ssh -Q key          # List supported public key types
ssh -Q kex          # List supported key exchange algorithms

ALCATEL 6900

write memory copy running certified reload from working no rollback-timeout