Posts

Showing posts from April, 2020

getLongest

func main () { fmt . Print ( getLongest ( "111131111" )) } func getLongest ( input string ) string { arr := make ([][] bool , len ( input )) for i := range arr { arr [ i ] = make ([] bool , len ( input )) } r := input [ 0 : 1 ] for i := 0 ; i < len ( input ); i ++ { arr [ i ][ i ] = true if i != len ( input )- 1 && input [ i ] == input [ i + 1 ] { r = input [ i : i + 1 ] arr [ i ][ i + 1 ] = true } } for lenght := 3 ; lenght <= len ( input ); lenght ++ { for i := 0 ; i < len ( input ); i ++ { j := i + lenght - 1 if j < len ( input ) && isPar ( i , j , input , arr ) { arr [ i ][ j ] = true r = input [ i : j + 1 ] } } } return r } func isPar ( i , j int , s string , arr [][] bool ) bool { if i == j { arr [ i ][ j ] = true return true } else { if i + 1 == j && s [ i ] == s [ j ]...

dpkg remove program

ref :  https://www.howtogeek.com/229699/how-to-uninstall-software-using-the-command-line-in-linux/ dpkg --list and remove You can use the remove and force flags: $ sudo dpkg -r --force-all pkg_name Alternatively, if you installed it through Ubuntu Package Manager, you can remove it with apt: $ sudo apt remove --purge pgk_name Installing .deb debian package file in Ubuntu Double click the .deb file , it will be automatically opened with the GDebi Package manager and you can install it From command line , use this command to install a package . sudo dpkg -i PACKAGEFILE.deb Uninstalling a package in Ubuntu From command line, use this command sudo dpkg -r PACKAGENAME

apt remove program

apt-get remove packagename will remove the binaries, but not the configuration or data files of the package  packagename . It will also leave dependencies installed with it on installation time untouched. apt-get purge packagename  or  apt-get remove --purge packagename will remove about  everything  regarding the package  packagename , but not the dependencies installed with it on installation. Both commands are equivalent. Particularly useful when you want to 'start all over' with an application because you messed up the configuration. However, it does not remove configuration or data files residing in users home directories, usually in hidden folders there. There is no easy way to get those removed as well. apt-get autoremove removes orphaned packages, i.e. installed packages that used to be installed as an dependency, but aren't any longer. Use this after removing a package which had installed dependencies you're no longer interested in....

Apt and apt-get tutorial

Let’s see which apt command replaces which apt-get and apt-cache command options. apt command the command it replaces function of the command apt install apt-get install Installs a package apt remove apt-get remove Removes a package apt purge apt-get purge Removes package with configuration apt update apt-get update Refreshes repository index apt upgrade apt-get upgrade Upgrades all upgradable packages apt autoremove apt-get autoremove Removes unwanted packages apt full-upgrade apt-get dist-upgrade Upgrades packages with auto-handling of dependencies apt search apt-cache search Searches for the program apt show apt-cache show Shows package details apt list Lists packages with criteria (installed, upgradable etc) apt edit-sources Edits sources list

How to list all installed apps in Linux debian

That depends on your distribution. 1. Aptitude-based distributions (Ubuntu, Debian, etc): dpkg -l 2. apt list --installed 3. snap list 2. RPM-based distributions (Fedora, RHEL, etc): rpm -qa 3. pkg*-based distributions (OpenBSD, FreeBSD, etc): pkg_info 4. Portage-based distributions (Gentoo, etc): equery list or eix -I 5. pacman-based distributions (Arch Linux, etc): pacman -Q 6. Cygwin: cygcheck --check-setup --dump-only * 7. Slackware: slapt-get --installed

install golang

Open your terminal and navigate to your downloads folder cd /root/Downloads Extract the files tar -C /usr/local/ -xzf go1.13.6.linux-amd64.tar.gz Add variables for GO by modifying  “~/.bashrc” vim ~/.bashrc Add the following paths to the end of the file export GOPATH=/root/go-workspace export GOROOT=/usr/local/go PATH=$PATH:$GOROOT/bin/:$GOPATH/bin Now we need to refresh the bashrc to get the updated variables source ~/.bashrc

Snap tutorial

ref:  https://snapcraft.io/docs/getting-started 0. install snapd $ apt update $ apt install snapd $ systemctl enable --now snapd apparmor $ systemctl start snapd 1. snap version 2. snap list       or               $ snap list --all app_name bonh@kali:~$ snap version snap    2.44.1-2 snapd   2.44.1-2 series  16 kali    2020.2 kernel  5.4.0-kali2-amd64 bonh@kali:~$ snap list Name               Version                     Rev   Tracking       Publisher   Notes core               16-2.44.1                   8935  latest/stable  canonical✓  core core18             20200311      ...

10 things to do after installing Kali linux OS

1. Enable sound system systemctl --user enable pulseaudio 2. install snapd service $ apt update $ apt install snapd $ systemctl enable --now snapd apparmor $ systemctl start snapd 3. Install your app with snap 4. Install evolution Open a terminal and type commands below (one line at a time) sudo apt-get remove evolution sudo apt-get update sudo apt-get install evolution sudo apt-get install evolution-ews 5. Install Ibus-Unikey: type the command below to install : run with sudo # apt-get update # apt-get install ibus-unikey # shutdown -r now 6. Install java 7. Install go 8. Install gedit 9. Install alien Install alien (and deps), its available in Debian, Ubuntu repository: sudo apt-get install alien dpkg-dev debhelper build-essential 10. Setting Xfce or Gnome in Debian By default Debian brings GNOME despite it allows to choose different X Window managers, luckily you can always change your desktop environment easily thanks to the...

Add constraint FK and remove

ALTER TABLE IXU_MEMBERSHIP_HISTORY DROP CONSTRAINT FK_IXU_MEMBERSHIP_HISTORY; ALTER TABLE IXU_MEMBERSHIP_HISTORY ADD CONSTRAINT FK_IXU_MEMBERSHIP_HISTORY FOREIGN KEY (MEMBERSHIP_TYPE_ID)     REFERENCES IXU_MEMBERSHIP_TYPE(ID)

CREATE TABLE IN ORACLE

DROP TABLE IXU_TRANSACTION_HISTORY; CREATE TABLE IXU_TRANSACTION_HISTORY ( ID number(10) NOT NULL, TCBSID varchar2(20), ROLE varchar2(20), AWARD_TYPE varchar2(20), ACTION varchar2(20), REFERENCE_ID number(10), REFERENCE_LOCATION varchar2(50), CAMPAIGN_ID number(5), POINT number(20,2), OUTSTANDING number(20,2), ISSUED_DATE DATE, EXPIRED_DATE DATE, CREATED_DATE timestamp, UPDATED_DATE timestamp, DESCRIPTION nvarchar2(1000), CHECKSUM varchar2(100), HISTORY_KEY varchar2(100), SOURCE varchar2(100), CONSTRAINT PK_IXU_TRANSACTION_HISTORY PRIMARY KEY (ID) ); -- Generate ID using sequence and trigger CREATE SEQUENCE IXU_TRANSACTION_HISTORY_SEQ START WITH 1 INCREMENT BY 1; CREATE OR REPLACE TRIGGER IXU_TRANSACTION_HISTORY_SEQ_TR  BEFORE INSERT ON IXU_TRANSACTION_HISTORY FOR EACH ROW  WHEN (NEW.ID IS NULL) BEGIN  SELECT IXU_TRANSACTION_HISTORY_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL; END;

How to fake httprequest in golang to write unittest for an api

func scanAndPushMsg ( w http . ResponseWriter , r * http . Request ) { ctx := r . Context () log := ctx . Value ( "RequestLogger" ).(* logger . Entry ) if r . Body != nil { defer r . Body . Close () } roles := r . FormValue ( RolesKey ) actions := r . FormValue ( ActionsKey ) awardTypes := r . FormValue ( AwardTypesKey ) campaignIds := r . FormValue ( CampaignIdsKey ) log . Infof ( "scanAndPushMsg input: roles --%v--, actions --%v-- , awards --%v-- ,campaignid --%v--" , roles , actions , awardTypes , campaignIds ) var reqBody jarvis . FilterCfgBody reqBody . Roles = strings . TrimSpace ( roles ) reqBody . Actions = strings . TrimSpace ( actions ) reqBody . CampaignIDs = strings . TrimSpace ( campaignIds ) reqBody . AwardTypes = strings . TrimSpace ( awardTypes ) log . Infof ( "FilterCfgBody : %+v" , reqBody ) resp , err := scanAndPushSrv . ScanAndPush ( reqBody , ctx ) if err != nil { ...

How to write unittest and fake response api in golang

This is our code that need to write unittest  func ( s * emailServiceImpl ) send ( envelope * jarvis . EmailEnvelop , ctx context . Context ) error { byteData , err := xml . Marshal ( envelope ) if err != nil { return err } client := apmhttp . WrapClient (& http . Client { Timeout : s . timeout * time . Minute ,}) req , err := http . NewRequest ( "POST" , s . url , bytes . NewBuffer ( byteData )) if err != nil { return errors . Wrap ( err , "Create new request failed" ) } req . SetBasicAuth ( s . authentication . Username , s . authentication . Password ) req . Header . Add ( "Content-Type" , "text/xml;charset=UTF-8" ) req . Header . Add ( "Accept" , "UTF-8" ) req . Header . Add ( "SOAPAction" , "sendEmailWithBBC" ) resp , err := client . Do ( req . WithContext ( ctx )) if err != nil { logrus . Errorf ( "Send email fail %v" ,...