Archive for the Programing Category

Install Bad Wolf Color for Vim

| August 14th, 2015

So we have a good color for vim which give your more visualization about vim editor.

Bad Wolf looks like a good candidate
https://github.com/sjl/badwolf/

Here is the instruction how to install color for vim

1. Copy colors/badwolf.vim to ~/.vim/colors/badwolf.vim; create directories if needed. Alternatively, git clone into ~/.vim/bundles/ and use the Pathogen package manager, or specify the repository with the Vundle package manager, etc.

2. In your ~/.vimrc, put / replace any existing :colorscheme command with:
colorscheme badwolf

more »

When you are using special fonts for your terminal and it could not display correctly. We need to install these front to make it work better

So Powerline fonts is a good candidate and easy to install on MacOS and Linux
https://github.com/powerline/fonts
more »

Because I investigated this for a project, Linux (at least RHEL) mailx can use a remote SMTP server, thus enabling us to test whether that server allows email sending from our application.

mailx -S smtp=<smtp-server-address> -r <from-address> -s <subject> -v <to-address> < content.txt

Where “-S smtp ” is the crucial component (that apparently AIX mail/mailx doesn’t support) allowing you to send through a remote server rather than a locally-configured server.

-v is "verbose"
content.txt is a local file that contains the body of the test message I'm sending.


more »

Puppet supports “if” and “unless” statements, case statements, and selectors.

if $is_virtual {
  warning('Tried to include class ntp on virtual machine; this node may be misclassified.')
}
elsif $operatingsystem == 'Darwin' {
  warning('This NTP module does not yet work on our Mac laptops.')
}
else {
  include ntp
}

more »

Some conditional statements that you can use on puppet templates:

<% if @hostname == ("srv01") then -%>
... ... ...
<% end -%>
<% if @hostname != ("srv01") then -%>
... ... ...
<% end -%>
<% if @hostname == ("srv01" or "srv02") then -%>
... ... ... 
<% end -%>

Here is some command to test your puppet syntax

# "bundle exec rake spec" <= check whole puppet script
# "bundle exec rake spec SPEC_OPTS=-fd" <= with debug mode
# "bundle exec rake syntax" <= check syntax
# "bundle exec rspec spec/hosts/server_spec.rb" <= check puppet script on specific host

We can test to parse your log file before implement it on your server to test syntax, etc.

For example, we have log format as below

Nov 26 09:41:22 webserver8 mydomain.com-error: 2013/11/26 09:41:13 [warn] 2787#0: *39595376 a client request body is buffered to a temporary file /var/lib/nginx/body/0000251155, client: 127.0.0.1, server: myserver.com, request: "POST /some_request.php HTTP/1.1", host: "www.mydomain.com", referrer: "https://www.mydomain.com/advanced_search_result.php?keywords=someword"

more »

Here is example config of gitolite to denied the access of specific group to specific branch.

My config, that is working now:

@gatekeepers = ustimenko
@developers  = ustimenko user1 user2
@deployers   = puppet

@project     = repo1
@project     = cakephp

repo @project
    RW+                 = @gatekeepers
    R   master develop  = @developers
    -   master develop  = @developers
    RW+                 = @developers
    R                   = @deployers

more »

These are more compact and versatile forms of Hamish’s answer. They handle any mixture of upper and lower case letters:

read -r -p "Are you sure? [y/N] " response
case $response in
    [yY][eE][sS]|[yY])
        do_something
        ;;
    *)
        do_something_else
        ;;
esac

more »