Removing a directory from the git repository after adding it to .gitignore

If a directory was added to .gitignore before pushing to the repository, it does not get pushed. But if the directory was already pushed, and later added to .gitignore, then to remove it from the repository:

git rm -r --cached dirToIgnore
git commit -m 'Removing the gitignored dir'
git push

The directory dirToIgnore should now be removed from the git repository.

Fixing Apache localhost/~username resolve on macOS Mojave

Edit /etc/apache2/httpd.conf

sudo vi /etc/apache2/httpd.conf

Uncomment the following lines:

#LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
#Include /private/etc/apache2/extra/httpd-vhosts.conf
#LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf

Uncomment the following in /private/etc/apache2/extra/httpd-userdir.conf :

#Include /private/etc/apache2/users/*.conf

Create the file /private/etc/apache2/users/yourUserName.conf if it doesn’t exist:

sudo vi /private/etc/apache2/users/yourUserName.conf

Add the following in this file:

<Directory "/Users/yourUserName/Sites/">
  Options Indexes MultiViews
  AllowOverride None
  Require all granted
</Directory>

For running PHP, uncomment the following line in /etc/apache2/httpd.conf . The version of PHP in the module name may vary as per the currently installed version (7 in this case):

#LoadModule php7_module libexec/apache2/libphp7.so

Restart Apache server:

sudo apachectl restart

The local webserver should now be available at http://localhost/~yourUserName/ , referring to the location ~/yourUserName/Sites/

using git to deploy on server

Install git on the remote server (if it is not already).

On Ubuntu:

sudo apt-get update
sudo apt-get install git

Create an SSH key pair (locally):

ssh-keygen -C "email@domain.com"

Accept the default file to save the key. If a passphrase is entered, it would have to be entered every time during ‘git push‘. The following two files would be created in ~/.ssh/

id_rsa.pub (public key)
id_rsa (identification)

Create an authorized_keys file (if it is not present) on the remote server in ~/.ssh/ for the SSH daemon to accept the key:

touch ~/.ssh/authorized_keys

Copy the local SSH ID/key to the remote server’s authorized_keys in ~/.ssh/ as:

ssh-copy-id user@remoteServerIP

It would prompt for the passphrase if it was entered while generating the key (using ssh-keygen).

Create a local git repository, in a project directory (say ~/project01) that needs to be uploaded to the server. Then create a file in it to test the git transfer later:

cd ~/project01
git init
echo 'testing deployment via git' > example.txt 

On the remote server, initialise a bare repository in a directory (say ~/project01.git):

mkdir ~/project01.git && cd ~/project01.git
git init --bare

Set up a post-receive hook for ~/project01.git on the remote server, to ‘checkout’ the git files into a remote project directory (say ~/project01, as the local):

mkdir ~/project01
nano ~/project01.git/hooks/post-receive

Enter the following script code in this post-receive file:

#!/bin/sh
export GIT_WORK_TREE=/home/user/project01
git checkout -f master

Make post-receive executable:

chmod +x ~/project01.git/hooks/post-receive

Set up remote origin to the server (bare) repository, at the local end:

git remote add origin user@remoteServerIP:project01.git

Stage the content of the local repository and commit it:

cd ~/project01
git add example.txt
git commit -m "New sample file to test git transfer"

Push the sample file to the server, setting the remote as upstream:

git push --set-upstream origin master

The file should be available on the remote server at ~/project01 (created earlier).

Note: It is recommended against using git as a deployment tool, for reasons as it does not track permissions. Read here.

komorebi

komorebi – sunlight filtering through the trees

木漏れ日

木 – tree

漏れ – leakage

日 – sun

byobu

http://byobu.co/

A text-based window manager for linux and terminal multiplexer; displays system info in the CLI, such as battery, hdd, thermal stats.

battery status on linux via CLI

acpi (battery stats – basic)

acpi -i (battery stats – more info)

acpi -V (battery & thermal stats)

sudo tlp-stat -b (battery info)

sudo tlp-stat -s (system info)

booting ubuntu in text mode

back-up grub:

sudo cp /etc/default/grub /etc/default/grub-orig

edit the following in /etc/default/grub:

#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

GRUB_CMDLINE_LINUX="text"

GRUB_TERMINAL=console

update grub:

sudo update-grub

Set systemd target. The multi-user.target unit groups many daemons and starts services such as NetworkManager.service and activates another target unit named basic.target

sudo systemctl set-default multi-user.target

check default target:

systemctl get-default

The above command links to: /etc/systemd/system/default.target

List all target units:

systemctl list-units --type target --all

To reset to graphical target:

sudo systemctl set-default graphical.target 

hostname dns resolve

This is a collection of some commands to diagnose the DNS resolution problems, from OSX in a local network having linux and mac machines.

On linux, edit: /etc/avahi/avahi-daemon.conf to set ‘use-ipv6’ to ‘no’, so avahi resolves the hostname to ipv4 address. Not sure if this affects the DNS resolution from a mac, but I set it to ipv4 anyway.

use-ipv6=no

Restart avahi-daemon on linux:

sudo systemctl restart avahi-daemon.service

Resolve mDNS/DNS hostname to IP address and vice-versa:

avahi-resolve-host-name onizu-asus.local
avahi-resolve-address 192.168.0.110

Scan for mDNS/DNS-SD services published on the local network:

mdns-scan

on OSX, run the DNS Service Discovery tool:

dns-sd -E

The domain should be listed in the output of the above command. But for me it doesn’t list anything..

A system reboot works for me. The local hostname starts resolving on the mac. Not able to figure out why it stops working after a while..

ISP blocked inbound port 80 – workaround using dynamic DNS service feature

Tried setting up dynamic DNS for a local server using no-ip , but the bloody ISP has blocked the inbound port 80 🙁

The no-ip service does have a feature to redirect port 80 though to the desired port on which the web-server is running locally.

(While trying out different options, I also discovered that the ISP had blocked 443 too.)

angular on ubuntu

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

check nodejs installation:

nodejs -v

check npm installation:

npm -v
sudo npm install -g npm@latest
sudo npm cache verify
npm -i
sudo npm install --no-optional
sudo npm init
sudo npm install -g @angular/cli

Unhandled rejection Error: EACCES: permission denied, open ‘/home/onizu/.npm/_cacache/tmp/b5bc4345’S: permission denie

sudo chown -R $USER:$GROUP ~/.npm 
sudo chown -R $USER:$GROUP ~/.config

sudo chown -R root:YOUR_USERNAME /usr/local/lib/node_modules/
sudo chmod -R 775 /usr/local/lib/node_modules/

install git (if not installed):

sudo apt-get install git
git config --global user.email "you@example.com"
git config --global user.name "your name"

create workspace & app:

ng new my-app

serve app:

cd my-app
ng serve --open

the app should be available at: http://localhost:4200/