Posts

Showing posts from 2018

Golang - For loop

Three-component loop sum := 0 for i := 1; i < 5; i++ { sum += i } fmt.Println(sum) // 10 (1+2+3+4) This version of the Go for loop works just as in C/Java/JavaScript. The init statement,  i := 0 , runs. The condition,  i < 5 , is evaluated. If it’s true, the loop body executes, otherwise the loop terminates. The post statement,  i++ , executes. Back to step 2. The scope of  i  is limited to the loop. While loop If the init and post statements are omitted, the Go  for  loop behaves like a C/Java/JavaScript while loop: power := 1 for power < 5 { power *= 2 } fmt.Println(power) // 8 (1*2*2*2) The condition,  i < 5 , is evaluated. If it’s true, the loop body executes, otherwise the loop terminates. Back to step 1. Infinite loop By also leaving out the condition, you get an infinite loop. sum := 0 for { sum++ // repeated forever } fmt.Println(sum) // unreachable For each loop Looping over elements in slices, arrays, maps, channels and

Golang - Writing data to file

package main import ( "bufio" "fmt" "os" ) func main() { fileHandle, _ := os.Create("output.txt") writer := bufio.NewWriter(fileHandle) defer fileHandle.Close() fmt.Fprintln(writer, "String I want to write") writer.Flush() }

Golang - Read a file line by line

import ( "bufio" "os" ) func FileToLines ( filePath string ) ( lines [] string , err error ) { f , err := os . Open ( filePath ) if err != nil { return } defer f . Close () scanner := bufio . NewScanner ( f ) for scanner . Scan () { lines = append ( lines , scanner . Text ()) } err = scanner . Err () return }

Scanning a Linux Server for Malware and Virus by ClamAV

Image
The ClamAV antivirus software and how to use it to protect your server or desktop (Linux/Windows platform. It's also worth noting that ClamAV doesn't behave like a Windows antivirus. It doesn't hog up RAM or run in the background all the time. It also doesn't have all of the extra bells and whistles. It scans for viruses, and that's about all. 1. SETUP - Install on Fedora/CentOS/Redhat yum install clamav - Install on Debian/Ubuntu apt-get install clamav - Compile from source code   + Download:  http://www.clamav.net/downloads/production/clamav-0.100.0.tar.gz   + Compile: tar xvf  clamav-0.100.0.tar.gz cd clamav-0.100.0/ ./configure --prefix=/opt/clamav make sudo make install All pages will be placed in /opt/clamav 2. CONFIGURING All Clamav's configuration in /opt/clamav/etc (contains 2 files: clamav.conf and freshclam.conf) - clamd.conf (The configuration file save all Clamav's configrations) # BASIC LogFile /var/log/clamd.log

Building webserver with golang

Image
How to build a simple webserver with Go Code: package main import ( "fmt" "net/http" ) func main () {     http. HandleFunc ("/", func (w http.ResponseWriter, r *http.Request) { fmt. Fprintf (w, " Golang webserver. ")     })     http. HandleFunc ("/hello", func(w http.ResponseWriter, r *http.Request) { fmt. Fprintf (w, " Hello World! ")     })     fs := http. FileServer (http.Dir("static/"))     http. Handle ("/static/", http. StripPrefix ("/static/", fs))     http. ListenAndServe (":3000", nil) }

Using mutt email client to check mail

Image
What is Mutt? Mutt is a command line based Email client. It’s a very useful and powerful tool to send and read mails from command line in Unix based systems. Mutt also supports POP and IMAP protocols for receiving mails. It opens with a coloured interface to send Email which makes it user friendly to send emails from command line. Features Its very Easy to install and configure. Allows us to send emails with attachments from the command line. It also has the features to add BCC (Blind carbon copy) and CC (Carbon copy) while sending mails. It allows message threading. It provides us the facility of mailing lists. It also support so many mailbox formats like maildir, mbox, MH and MMDF. Supports at least 20 languages. It also support DSN (Delivery Status Notification). 1. INSTALLATION - Ubuntu/Debian apt-get install mutt - Fedora/CentOS yum install mutt 2. CONFIGURATION 2.1. Configuring for an account mail Create mkdir -p ~/.mutt/cache/headers mkdir ~/.mutt/cac

ZSH tips

Image
ZSH's tips man zsh Zsh overview man zshmisc Anything not fitting into the other sections man zshexpn Zsh command and parameter expansion man zshparam Zsh parameters man zshoptions Zsh options man zshbuiltins Zsh built-in functions man zshzle Zsh command line editing man zshcompwid Zsh completion widgets man zshcompsys Zsh completion system man zshcompctl Zsh completion control man zshmodules Zsh loadable modules man zshzftpsys Zsh built-in FTP client man zshall Meta-man page containing all of the above info --index-search=age zsh # get man info for zsh function age *N* zinfo(){info --index-search=$1 zsh} *N* /usr/share/zsh/htmldoc/zsh_toc.html Install on Linux > yum install zsh *N* > yum update zsh *N* # install from source ver=5.5.1 wget --no-check-certificate https://sourceforge.net/projects/zsh/files/zsh/$ver/zsh-$ver.tar.gz tar zxvf zsh-$ver.tar.gz yum install gcc ncurses-devel # if required cd zsh-$ver &a

[Programming] How to setup Scrapy on Centos 7

Scarpy is An open source and collaborative framework for extracting the data you need from websites. In a fast, simple, yet extensible way. This tut which I'll guide to install Scrapy on Centos 7: - Step 1: Install dependences for Scrapy sudo yum install python-devel libxml2-devel libxslt-devel pyOpenSSL - Step 2: Setup Scrapy via Pip sudo pip install Scrapy --Done--