A developer in trench
enable two factor authentication on home ssh

found an article to enable two factor authentication on ssh access with google authenticator (http://www.howtogeek.com/121650/how-to-secure-ssh-with-google-authenticators-two-factor-authentication/)

Basic steps:

1) install libpam-google-authenticator

sudo apt-get install libpam-google-authenticator

2) run google-authenticator to create authentication key

google-authenticator

3) Activate Google Authenticator for ssh

in /etc/pam.d/sshd

auth required pam_google_authenticator.so

in /etc/ssh/sshd_config

ChallengeResponseAuthentication yes

restart sshd

sudo service ssh restart
colorify git

in ~/.gitconfig

[color]
        branch = auto
        diff = auto
        status = auto
[color "branch"]
        current = yellow reverse
        local = yellow
        remote = green
[color "diff"]
        meta = yellow bold
        frag = magenta bold
        old = red
        new = cyan
[color "status"]
        added = yellow
        changed = green
        untracked = cyan
Open multiple files once in Emacs
  1. Open the parent directory

    M-x find-dired
    
  2. Find the files

     -name '*.php" or -type f
    
  3. Mark the files you need to edit

     Press "t" to toggle marks all or press "m" to pick one by one
    
  4. have this block in .emacs

    (eval-after-load "dired"
      '(progn
         (define-key dired-mode-map "F" 'my-dired-find-file)
         (defun my-dired-find-file (&optional arg)
           "Open each of the marked files, or the file under the point, or when prefix arg, the next N files "
           (interactive "P")
           (let* ((fn-list (dired-get-marked-files nil arg)))
             (mapc 'find-file fn-list)))))
    
  5. Use shift+F to open them all

Notes:

  • dired-x mode dired-do-find-mark-files only open a limits number of files
Best alternative to Macbook Pro 15”

The best alternative to Macbook Pro 15” is Macbook Pro 15” with ubuntu. Everything else is just a joke.

Macbook Pro is beautiful, xxx (name everything compliment here), except I am not really into OS X. So I tried to find out if there is an alternative, In fact, I am particular looking for

  • 15” ( or at least 14”) or above. Any size smaller is not for programmer.
  • 8G+ memory. I do compile while watching video.
  • 1600 x 900 + screen size.
  • No VGA port, only HDMI
  • No DVD or blu-ray. Please! They are junkies
  • Equal or slightly thicker than Macbook Pro.

Sadly, all PC vendors don’t produce anything close to this.

Force SSH password authentication

for some reason you want to disable public key authentication temporarily when ssh into a host:

#ssh -o PubkeyAuthentication=no user@machine

You should get the prompt for the password.

This goes without saying, but ChallengeResponseAuthentication (at least on Debian) must be set to yes on the server side for this to work.

origin link: http://blog.wains.be/2010/08/31/force-ssh-password-authentication/

connect android ics to ubuntu for file transfer

install mtp tools and utilities

#sudo apt-get install mtp-tools mtpfs

add udev rules

connect nexus to pc, find out the device vendor and product id

#sudo mtp-detect | grep idVendor
....
   idVendor: 0408
#sudo mtp-detect | grep idProduct
....
   idProduct: 685c

create udev rules for android in /etc/udev/rules.d/51-android.rules

SUBSYSTEM=="usb", ATTR{IDVENDOR}=="18d1", ATTR{IDPRODUCT}=="4e42", MODE="0666"

prepare fuse

#sudo mkdir /media/galaxynexus & sudo chmod a+rwx /media/galaxynexus
#sudo adduser <yourname> fuse
#sudo echo "user_allow_other" >> /etc/fuse.conf

add command in .bash_alias

alias nexus-connect='mtpfs -o allow_other /media/galaxynexus'
alias nexus-disconnect='fusermount -u /media/galaxynexus'
git checkout non-standard svn repository

Assuming svn repo is http://svn.domain.org/svn, trunk is trunk/myproject and dev branch is branches/myproject/dev

  1. Clone with a prefix so git will not confuse local branch name with svn branch name, and only starts from revision 500

    git svn clone http://svn.domain.org/svn/ \
         -r500:HEAD \
         --prefix=svn/ \
         --trunk=trunk/myproject myproject
    
  2. add svn branch as a remote

    cd myproject
    git config --add svn-remote.dev.url http://svn.domain.org/svn
    git config --add svn-remote.dev.fetch branches/myproject/dev:refs/remotes/svn/dev
    git svn fetch -r500:HEAD dev
    git checkout -b dev remotes/svn/dev
    
check unwanted trailing spaces before commit

Credits: http://blog.yesmeck.com/archives/use-git-pre-commit-hook-to-check-unwanted-trailling-whitespace/

Put following shell to your .git/hook folder.

#!/bin/sh

red="\033[1;31m"
color_end="\033[0m"

# Check unwanted trailing whitespace or space/tab indents;

if [[ `git diff --cached --check` ]]; then
    echo -e ${red}Commit failed${color_end}
    git diff --cached --check
    exit 1
fi

Don’t forget give execute permission to it.

$ chmod +x pre-commit
Git log trick

Good git log trick

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

migrate code from git repo to perforce

It sucks! Here is how a degeneration done to preserve master branch commits logs in git repo when migration into p4.

You need perforce and git-p4, one client is for purely perforce p4-repo, another client is for git-p4 git-p4-repo, Following this article https://git.wiki.kernel.org/index.php/Git-p4_Usage to make git-p4 works.

in p4-repo, create a dummy file which has no name conflict with all you files in git repo under expected module path, and submit. In this way, we basically create the module

#mkdir -p /depot/foo/main
#echo "this is dummy" > /depot/foo/main/dummy.txt 
#p4 add /depot/foo/main/dummy.txt
#p4 submit -d "create mainline of foo module"

Now go to git-p4-repo, clone the module out, setup git remote repo, pull changes, rebase and submit

#git p4 clone //depot/foo/main foo-main
#cd foo-main
#git remote add github git@github.com:example/foo.git
#git p4 rebase
#git p4 submit

A few notes:

  • This method does not always works, p4 is so sucks that it does not alllow certain symbol “.@#” in file name, if you happens has such file name even in history, it will not work

  • git p4 submit will prompt you to vi EVERY git log into p4 message, it is extremely annoying, you may need get around by setting P4EDITOR to /bin/true and add these in .gitconfig

[git-p4] skipSubmitEditCheck=true

  • git-p4 could be used to create branch or detect branch, I have no mode to use it