[Git] Delete branch at local and remote

We have 2 branch master and develop, and we want to delete branch develop at local and remote.

  • First, we must checkout to branch master
git checkout master
  • Next, delete branch at local
git branch -D develop
  • Next, delete branch at remote server
git push origin --delete develop

[Redis] Setup redis with Rails

  1. Install Gemfile
    gem 'redis'
    gem 'redis-namespace'
  2. Create file config: redis.yml
       host: hdev01
       port: 6479
       db: 0
       namespace: 4travel
  3. Create function for load file config
    def redis_config
      @redis_config ||= YAML.load(File.open(Rails.root.join("config/redis.yml"))).symbolize_keys[Rails.env.to_sym].symbolize_keys
  4. Create namspace redis with function config

    def redis
      @redis ||= Redis::Namespace.new(redis_config[:namespace], :redis => Redis.new(redis_config))
  5. Use redis to set and get data

    #set data
    redis.set(key, value, ex: expiration_time)
    #get data
    redis.keys('*').grep(...) # get all keys and use grep to filter

[Rails] Check request is_bot or not

def is_bot?(request)
 agent = request.env["HTTP_USER_AGENT"]
 # agent = request.user_agent
 matches = nil
 matches = agent.match(/(facebook|postrank|voyager|twitterbot|googlebot|slurp|butterfly|pycurl|tweetmemebot|metauri|evrinid|reddit|digg)/mi) if agent
 if ( agent.nil? or matches)
   return true
   return false

Another code:

def is_bot?
  http_user_agent = request.env["HTTP_USER_AGENT"] || ""

    ua = ""
    ua = URI.decode(http_user_agent)

  browser = Browser.new(ua: ua)
  return browser.bot?


1 example Googlebot smartphone user-agent

Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 
Mobile Safari/537.36 (compatible; Googlebot/2.1; +

We use agent.match(/(facebook|twitterbot|googlebot)/mi), it will search in user-agent string, find text match googlebot. 

/mi: search downcase and upcase

without /mi: search exactly with googlebot (Googlebot is not match)

Use grep command line

1.  Use grep to filter command line history

history | grep 'text'


2. Search text in all file of folder

grep -rnw '/path/to/folder/' -e 'text-to-search'
  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.


3. Find files with name

find | grep "name_file"


4. Search texts with no contain char



array = [“abcdx”, “abcex”, “abcfx”]

array.grep(/^abc(?!e).*/) => [“abcdx”, “abcfx”]

[Redis] Add 1 more port for Redis

  • Create a new redis .conf file
cp /etc/redis.conf /etc/redis_6479.conf
  • Edit /etc/redis_6479.conf
#modify pidfile
#pidfile /var/run/redis/redis.pid
pidfile /var/run/redis/redis_6479.pid

#modify port
#port 6379
port 6479

#modify logfile
#logfile /var/log/redis/redis.log
logfile /var/log/redis/redis_6479.log
  • Copy init script
cp /etc/init.d/redis /etc/init.d/redis_6479
  • and edit init script
  • Start 1 more redis with port 6479
sudo /etc/init.d/redis_6479 start

# or check status, restart
sudo /etc/init.d/redis_6479 status
sudo /etc/init.d/redis_6479 restart
  • Check port is running of redis:
ps aux |grep redis


Use “alias” in Linux

In file “~/.bash_profile“, we can use alias to define keyword shorter to run app faster 🙂

Example: In server has been installed redis. To run redis-server we must run command “/opt/redis/latest/bin/redis-server”. We can use alias in “~/.bash_profile“:

alias redis-server="/opt/redis/latest/bin/redis-server"

And with redis-cli we must run command: “/opt/redis/latest/bin/redis-cli”. We can use alias:

alias redis-cli="/opt/redis/latest/bin/redis-cli"

And now, we can type redis-server or redis-cli in terminal instead of long command: “/opt/redis/latest/bin/redis-server” and “/opt/redis/latest/bin/redis-cli”.


When we added alias to “~/.bash_profile“, we can reload “~/.bash_profile” by the way:

. ~/.bash_profile


Change the Command-Line Prompt Colour in the Ubuntu/Linux Terminal

First, open file bashrc

gedit ~/.bashrc

Find line has text: if [ “$color_prompt” = yes ]; then

Copy context in if clause and paste to else clause

Save, close and reopen terminal. 🙂

Optional information:

Black 0;30 – Dark Gray 1;30 – Blue 0;34 – Light Blue 1;34 – Green 0;32 – Light Green1;32 – Cyan 0;36 – Light Cyan 1;36 – Red 0;31 – Light Red 1;31 – Purple 0;35 – Light Purple 1;35 – Brown 0;33 – Yellow 1;33 – Light Gray 0;37 – White 1;37