Sunday, November 9, 2014

linux history with date

1, export HISTTIMEFORMAT='%F %T '

2, history

[ec2-user@ip-10-0-3-22 ~]$ history | grep log | grep rm
  398  2014-11-10 01:16:01  rm python_etl_today_error.log
  426  2014-11-10 01:16:01  rm sqlldr_log_folder
  765  2014-11-10 01:16:01  rm python_etl_dev.log
 1004  2014-11-10 01:25:28  history | grep log | grep rm
 1006  2014-11-10 01:33:03  history | grep log | grep rm

Sunday, September 21, 2014

bash


Bash Round
chang@ACPNEW:~/tmp$ echo "scale = 5; 5+50*3/20 + (19*2)/7" | bc -l | xargs printf "%2.3f\n"
17.929

Avg
chang@ACPNEW:~/tmp$ awk '{s+=$1}END{print "ave:",s/NR}' RS=" "  avg.txt
ave: 54.646

for loop

for i in {1..50}
do
  echo $i
done


chang@ACPNEW:~/tmp$ cat b.txt | tr -s " "


tab seperated
cut -d$'\t' -f2-

chang@ACPNEW:~/tmp$ cut -d$'\t' -f2- b.txt




Tuesday, August 19, 2014

wordpress menu get erased

My wordpress menu get erased randomly. And I cannot replicate this issue.

I duplicated my whole site to a testing site, and dump the DB.
One day, I found my menu is gone, and I check the database,

mysql> select post_title, post_name, post_type from wp_posts where post_type='nav_menu_item' ;

It return 0 menu.

I disabled the plugin  Stealth Publish and fixed the issue.

It took me 3 weeks find the solution.

Tuesday, May 13, 2014

rails paperclip disable validation

1, Disable from global config file: config/application.rb

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end

2, Disable from controller
class Logserver < ActiveRecord::Base
  has_attached_file :serverkey, :path => "public/keys/:id/:filename", :url => "/keys/:id/:basename.:extension"
  #validates_attachment_content_type :serverkey, :content_type => /\Atext.*\Z/
  do_not_validate_attachment_file_type :serverkey
 end

Wednesday, April 30, 2014

install awscli

apt-get install python-pip
pip install awscli

aws configure

aws ec2 describe-instances

aws ec2 run-instances --image-id ami-3495735c --count 1 --instance-type t1.micro