Git: Show git branch with colors in bash/terminal in Ubuntu

Tags

, ,

Edit the bashrc file.
$ sudo vi ~/.bashrc
Copy/paste the script and place at the bottom of bashrc file.

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt

# force_color_prompt=yes

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

Ref: https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt

Advertisements

OpenShift v3: not authorized to execute command

Tags

,

Problem:
If you’re using mongodb in OpenShift v3 platform you may encounter an error that says “not authorized on {databasename}” even though that you’ve successfully connected to mongo instance.

{"error":{"name":"MongoError","message":"not authorized on microblogdb to execute command { find: \"posts\", filter: {}, sort: { updated_at: -1 }, projection: {} }","ok":0,"errmsg":"not authorized on microblogdb to execute command { find: \"posts\", filter: {}, sort: { updated_at: -1 }, projection: {} }","code":13}}


{"name":"MongoError","message":"not authorized on microblogdb to execute command { insert: \"users\", documents: [ { email: \"user3@mail.com\", passwordHash: \"$2a$08$AIqmMQHjc/5/Nz7hOWMHNurkiKS.ErjXJ.TFAfl686ODPSJ5JS1xi\", fullname: \"Jack Bauer\", articles: [], _id: ObjectId('59ae68867b28c70018e8938f'), __v: 0 } ], ordered: false, writeConcern: { w: 1 } }","ok":0,"errmsg":"not authorized on microblogdb to execute command { insert: \"users\", documents: [ { email: \"user3@mail.com\", passwordHash: \"$2a$08$AIqmMQHjc/5/Nz7hOWMHNurkiKS.ErjXJ.TFAfl686ODPSJ5JS1xi\", fullname: \"Jack Bauer\", articles: [], _id: ObjectId('59ae68867b28c70018e8938f'), __v: 0 } ], ordered: false, writeConcern: { w: 1 } }","code":13}

Solution:
I’ve change the connection string format from
mongodb://192.168.100.1:27017/microblogdb
into
mongodb://myusername:mypassword@192.168.100.1:27017/microblogdb

So build and deploy again. It finally works!

How to install Firefox in Ubuntu

Tags

,

How to install Firefox 55 on Linux Mint, Ubuntu, Debian, CentOS, Fedora…
… or any other Linux distribution.

This red panda (Firefox) has not much to do with installing Firefox on Linux

This how-to explains how to install Firefox 55 on Linux, with or without replacing an existing Firefox installation.

Firefox 55 was released on August 8, 2017.
Firefox 56 will be released on September 26, 2017.

More information on Firefox release dates (including beta, nightly and ESR versions) can be found on the official RapidRelease calendar.

Warning for unexperienced Linux users: stick to the Firefox version included with your Linux distribution! Firefox can be installed or uninstalled through the package management system (Software Center, Software Manager, Synaptic, apt…) of all major distributions. Concerning updates: they will appear automatically in the package manager. It may take a few days after the official Firefox release for the update to show on, because the new release has to be tested with each distribution.
Summary

A. Install Firefox 55 in 5 easy steps
B. Ubuntu’s case, Mint and Debian
C. Uninstall Firefox
D. Run multiple profiles or instances at the same time

A. Install Firefox in 5 easy steps
1. Download

Download Firefox from the official Mozilla Firefox page:
http://www.mozilla.com/firefox/
Download alternative versions (beta, developer edition, nightly) from the official channels page:
http://www.mozilla.com/firefox/channels/
A 64 bit build is also available in the x86_64 directory of Mozilla’s FTP.

This how-to supposes that the downloaded file is saved in the “Downloads” directory located in your home directory.
2. Extract

The downloaded file is a compressed .tar.bz2 archive. In case you want to learn more on these extensions: tar, bzip2. To extract this juicy archive, open the Downloads directory. Look for a file named firefox-55.0.tar.bz2, right-click on it and select “extract here”.

Alternatively, you can extract the archive from the command line:
cd ~/Downloads/
tar xjf firefox-55.0.tar.bz2

For those interested, here are the tar arguments used in the command:
x : eXtract
j : deal with bzipped file
f : read from a file (rather than a tape device)

3. Move to /opt

External programs like LibreOffice, Google Chrome, the defunct Adobe reader, … are all installed in the /opt directory. If you want more info about why /opt is the right place to install programs on Linux, check out these two links:
Where to install my products on Linux?
Filesystem Hierarchy Standard

If you already had a previous Firefox version installed in the /opt directory, remove it with the following command:
sudo rm -r /opt/firefox

Now move the firefox directory (which was created in your Downloads folder during extraction) to /opt:
sudo mv firefox /opt/firefox55
4. Set up symbolic links

Depending on your usage pattern, follow the instructions for case 1 OR for case 2.

How to install Firefox 55 on Linux Mint, Ubuntu, Debian, CentOS, Fedora…
… or any other Linux distribution.

This red panda (Firefox) has not much to do with installing Firefox on Linux

This how-to explains how to install Firefox 55 on Linux, with or without replacing an existing Firefox installation.

Firefox 55 was released on August 8, 2017.
Firefox 56 will be released on September 26, 2017.

More information on Firefox release dates (including beta, nightly and ESR versions) can be found on the official RapidRelease calendar.

Warning for unexperienced Linux users: stick to the Firefox version included with your Linux distribution! Firefox can be installed or uninstalled through the package management system (Software Center, Software Manager, Synaptic, apt…) of all major distributions. Concerning updates: they will appear automatically in the package manager. It may take a few days after the official Firefox release for the update to show on, because the new release has to be tested with each distribution.
Summary

A. Install Firefox 55 in 5 easy steps
B. Ubuntu’s case, Mint and Debian
C. Uninstall Firefox
D. Run multiple profiles or instances at the same time

A. Install Firefox in 5 easy steps
1. Download

Download Firefox from the official Mozilla Firefox page:
http://www.mozilla.com/firefox/
Download alternative versions (beta, developer edition, nightly) from the official channels page:
http://www.mozilla.com/firefox/channels/
A 64 bit build is also available in the x86_64 directory of Mozilla’s FTP.

This how-to supposes that the downloaded file is saved in the “Downloads” directory located in your home directory.
2. Extract

The downloaded file is a compressed .tar.bz2 archive. In case you want to learn more on these extensions: tar, bzip2. To extract this juicy archive, open the Downloads directory. Look for a file named firefox-55.0.tar.bz2, right-click on it and select “extract here”.

Alternatively, you can extract the archive from the command line:
cd ~/Downloads/
tar xjf firefox-55.0.tar.bz2

For those interested, here are the tar arguments used in the command:
x : eXtract
j : deal with bzipped file
f : read from a file (rather than a tape device)

The firefox-55.0.tar.bz2 archive can now be deleted.
3. Move to /opt

External programs like LibreOffice, Google Chrome, the defunct Adobe reader, … are all installed in the /opt directory. If you want more info about why /opt is the right place to install programs on Linux, check out these two links:
Where to install my products on Linux?
Filesystem Hierarchy Standard

If you already had a previous Firefox version installed in the /opt directory, remove it with the following command:
sudo rm -r /opt/firefox

Now move the firefox directory (which was created in your Downloads folder during extraction) to /opt:
sudo mv firefox /opt/firefox55
4. Set up symbolic links

Depending on your usage pattern, follow the instructions for case 1 OR for case 2.
Case 1: you want to use Firefox 55 as your default browser:

“Backup” the old Firefox launcher:
sudo mv /usr/bin/firefox /usr/bin/firefox-old

Create a symbolic link pointing to the new Firefox version:
sudo ln -s /opt/firefox55/firefox /usr/bin/firefox

There is no need to update your icons/shortcuts; they should now launch the new version of Firefox.

Your old Firefox version is still available. If you want to use it, run firefox-old in a terminal or create shortcuts/icons referring to firefox-old.
Case 2: you want to keep using your “old” Firefox by default:

Create a symbolic link pointing to the new Firefox version:
sudo ln -s /opt/firefox55 firefox /usr/bin/firefox55

Launch the newly installed Firefox by running firefox55 in a terminal, or create shortcuts/icons referring to firefox55.
5. Updates

Firefox will manage its own updates independently of your system’s package manager, an download subsequent releases. There will be no need to repeat the whole “procedure”… Enjoy Firefox!

http://libre-software.net/how-to-install-firefox-on-ubuntu-linux-mint/

Nodemon or supervisor keeps crashing or restarting even no file changes

Tags

, ,

When running the node.js(expressJS) app using nodemon or supervisor it keeps crashing and restarting.

$ supervisor ./bin/www
crashing child
Starting child process with 'node ./bin/www'
crashing child
Starting child process with 'node ./bin/www'
$ nodemon
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./bin/www`
[nodemon] restarting due to changes...
[nodemon] starting `node ./bin/www`

I remember that I have a gulpfile.js in which it generates an angular config file(config.js) on-the-fly and place it inside the public folder.
To solve it, we ignore the folder where the generated file takes place.

$ supervisor --ignore public ./bin/www
$ nodemon --ignore public

Reference: https://github.com/remy/nodemon/issues/763

Target filesystem doesn’ t have requested /sbin/init No init found. Try passing init = bootarg.

Tags

mount: mounting /dev/loop0/ on /root failed : Invalid argument
mount: mounting /dev on /root/dev failed: No such file or directory
mount: mounting /sys on /root/sys failed: No such file or directory
mount: mounting /proc on /root/proc failed: No such file or directory
Target filesystem doesn' t have requested /sbin/init
No init found. Try passing init = bootarg.

BusyBox v1.21.1 (Ubuntu 1:1:21.0-1ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands

(initramfs) _

Solution #1:

To solve this problem you must follow these steps:
* When Windows lets you choose between Windows and Ubuntu choose Ubuntu
* When the computer exits from the OS choosing screen restart your computer, and try to boot Ubuntu while holding the Shift key on your keyboard
* Then there will appear a screen from Grub (boot loader for Ubuntu) and it will be almost empty. Press ‘e’ key on your keyboard (to load boot commands for Ubuntu)
* After pressing ‘e’ key computer will display a set of commands that Grub use for booting Ubuntu
* In those boot commands try to find the line that contains ro quiet splash and change the ‘ro’ word to ‘rw’. It should now read rw quiet splash.
* Down at the bottom of the screen there is a key to press to boot (for me it was CRTL+X or F10), press that key and Grub will boot Ubuntu with your modified boot commands.

References:
https://askubuntu.com/questions/452631/ubuntu-14-04-doesn-t-boot-after-upgrade-from-12-04-installed-inside-windows-8-1
https://askubuntu.com/questions/454143/upgraded-to-14-04-reboot-fail

boot2docker: Configure boot2docker terminal console with ConEmu

Tags

,

First, download the ConEmu installer at Github.
https://github.com/Maximus5/ConEmu
http://bit.ly/ConEmuPack1612067z

Configure ConEmu:
In menu, click the Settings->Startup->Tasks.
Add a predefined task by clicking the + button.
Follow the information below:

Name: Boot2Docker
Task parameters:
/dir "C:\Program Files\Boot2Docker for Windows"
Commands:
"-new_console:C:c:\Program Files\Boot2Docker for Windows\boot2docker.ico" -new_console:n -new_console:t:Boot2Docker "-new_console:d:C:\Program Files\Boot2Docker for Windows" "%ProgramFiles(x86)%\Git\bin\sh.exe" --login -i "c:\Program Files\Boot2Docker for Windows\start.sh"

Note: Please check the directory path and modify them according to your system.
That’s it.

Docker: How to install docker machine in Windows

Tags

,

If you are running with Windows with git bash:

## change to root directory
$ cd ~  
$ if [[ ! -d "$HOME/bin" ]]; then mkdir -p "$HOME/bin"; fi && \
curl -L https://github.com/docker/machine/releases/download/v0.12.2/docker-machine-Windows-x86_64.exe > "$HOME/bin/docker-machine.exe" && \
chmod +x "$HOME/bin/docker-machine.exe"

Test the docker machine if it works

$ docker-machine --version
docker-machine.exe version 0.12.2, build 9371605

If it is working then let’s create our first docker machine name ‘dev’

$ docker-machine create --driver virtualbox dev
Creating CA: C:\Users\hax0r\.docker\machine\certs\ca.pem
Creating client certificate: C:\Users\hax0r\.docker\machine\certs\cert.pem
Running pre-create checks...
(dev) You are using version 4.3.28r100309 of VirtualBox. If you encounter issues, you might want to upgrade to version 5 at https://www.virtualbox.org
(dev) Image cache directory does not exist, creating it at C:\Users\hax0r\.docker\machine\cache...
(dev) No default Boot2Docker ISO found locally, downloading the latest release...
(dev) Latest release for github.com/boot2docker/boot2docker is v17.06.0-ce
(dev) Downloading C:\Users\hax0r\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v17.06.0-ce/boot2docker.iso...
(dev) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(dev) Copying C:\Users\hax0r\.docker\machine\cache\boot2docker.iso to C:\Users\hax0r\.docker\machine\machines\dev\boot2docker.iso...
(dev) Creating VirtualBox VM...
(dev) Creating SSH key...
(dev) Starting the VM...
(dev) Check network to re-create if needed...
(dev) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(dev) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #3"
(dev) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(dev) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(dev) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Users\hax0r\bin\docker-machine.exe env dev

Next, login into a machine with ssh

$ docker-machine ssh

Heroku: Install heroku cli on Windows using npm

Tags

$ npm install -g heroku-cli
$ heroku --version
$ heroku login
Enter your Heroku credentials:
Email: sudogem@gmail.com
Password: ******************
Logged in as sudogem@gmail.com

$ ls -alh ~/.ssh
-rw-r--r-- 1 Arman Ortega 197121 1.2k Jul  3 22:00 id_boot2docker
-rw-r--r-- 1 Arman Ortega 197121  501 Jul  3 22:00 id_boot2docker.pub
-rw-r--r-- 1 Arman Ortega 197121 1.7K Jul  3 22:00 id_rsa_heroku
-rw-r--r-- 1 Arman Ortega 197121  407 Jul  3 22:00 id_rsa_heroku.pub
# We've found an existing ssh key for Heroku that we can use.

$ cat ~/.ssh/id_rsa_heroku.pub
ssh-rsa AAAAB3NzaC1yc....

$ heroku keys:add ~/.ssh/id_rsa_heroku.pub
Uploading C:/Users/armano/.ssh/id_rsa_heroku.pub SSH key... done

# Let's validate the connection
$ ssh -v git@heroku.com
...
...
debug1: Offering RSA public key: /c/Users/armano/.ssh/id_rsa_heroku
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to heroku.com ([50.19.85.132]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
PTY allocation request failed on channel 0
shell request failed on channel 0

Note: When executing the command just use Windows Command Prompt or cmder.

Git: Setup multiple github account on same environment/machine

Tags

Assume that we’ve already created a git repo

## Need to update the ssh config, see below:
$ vi ~/.ssh/config

# github account
Host *github.com   
  User git
  IdentityFile ~/.ssh/id_rsa_sudogem-github

# another github account
Host *github-slashd0t
  Hostname github.com
  User git
  IdentityFile ~/.ssh/id_rsa_slashd0t

# another github account
Host *github.ibm.com  # If using the Github Enterprise
  User git
  IdentityFile ~/.ssh/id_rsa_ibmgithub

Take note on the HOST ALIAS “github-slashd0t”.
## From your root directory of the project, we’ll add the origin of the repo

$ git remote add origin git@github-slashd0t:slashd0t/docker-mysql57.git

If there’s an existing remote origin, we’re going to remove it and re-add it using the syntax above.

$ git remote rm origin

## Set local git user & email for that repo

$ git config user.name "slash d0t" && git config user.email d3v0ps00001@gmail.com

## Test the ssh connection if it is using the correct git user.

$ ssh -vT git@github-slashd0t
....
....
Hi slashd0t! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
....
....

https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts–net-22574