Workstation

Babun – a nice Windows shell

Set default shell type to  bash instead of zsh

The zsh (with .oh-my-zsh) is the default babun’s shell.

Executing the following command will output your default shell

babun shell

In order to change your default shell execute

babun shell /bin/bash

 

Fix WARNING: UNPROTECTED PRIVATE KEY FILE!
chgrp -R Users ~/.ssh/
chmod -R 700 ~/.ssh/
sudo chmod 600 ~/.ssh/my_key

Sync Sublime text across Windows computers

We will be using google drive as a sync service by creating symlink to the user folder in Sublime text folder.

  1. Close Sublime Text
  2. Open PowerShell by right-clicking and selecting Run as administrator

In source machine

cd "$env:appdata\Sublime Text 3\Packages\"
mkdir "D:\Google Drive\Settings\Sublime"
mv User "D:\Google Drive\Settings\Sublime"
cmd /c mklink /D User "D:\Google Drive\Settings\Sublime\User"

In other computers

cd "$env:appdata\Sublime Text 3\Packages\"
rmdir -recurse User
cmd /c mklink /D User "D:\Google Drive\Settings\Sublime\User"

Source: packagecontrol.io

Delete deep nested folders in Windows

Trying to delete a nodeJs project the other day but had a bug with long file names in windows.. so here’s the fix:

Posted by Michael Whelan

Deleting Nested node_modules Folders

When using Node Package Manager (NPM) on Windows, it has an annoying habit of creating massively nested node_modules folders that exceed the 260 character path length limit. This makes it extremely painful to try to delete and causes problems with most windows tools. In Visual Studio, for example, I cannot Refresh Folder when I am in a website project (as opposed to a web application project).

Fortunately, the fix is pretty simple.

First, you need to install RoboCopy. If you are on Windows 8, I suggest you use the version from the Windows Server 2003 resource kit as there appear to be issues with the Windows 8 version. Next, create an empty directory and use the RoboCopy mirror flag to mirror the empty directory to the problematic node_modules folder. You can then delete the empty directory in the normal way. Cunningly, deleting the mirrored directory also deletes the node_modules directory.

mkdir new_empty_directory && robocopy new_empty_directory .build /MIR

Credit to toby1kenobi for this clever solution!

Finally, you just have to restore the deleted node packages. From the application directory, just run npm update:

npm update

This command will update all the packages listed in the packages.json file to the latest version. It will also install missing packages.

Vagrant & Virtual box in Windows 10: errors and fixes

Work in porogress..

Running vagrant and Oracle Virtualbox on the new Windows 10 isn’t a smouth experience. This is how you can fix issues related to page loading time etc..

Almasmaris wrote:  I don’t really know how i fixed this but i’m fixed it after doing this:
Uninstall/and Download latest Vagrant (1.7.4) and VirtualBox (5.0.6).

  1. Run with compatibility: Go to the C:\Program Files\Oracle\VirtualBox folder, right click on VirtualBox.exe, go to compatibility, check the “Run in compatibility mode” checkbox and choose Windows 7. Click OK to close the window. Repeat step 2. for VBoxManage.exe and VBoxHeadless.exe
  2. update ‘laravel/homestead’ box if not up to date.
  3. RESTART
  4. run homestead in virtualbox GUI, it worked
  5. testing in cmd, it worked

if the vagrant already running but cannot connect to the site:
1. In Virtualbox preferences -> network -> host-only networks create new Host-Only adapter and add 192.168.10.1 as IP address, So,there are 2 Host-Only adapter with IP 192.168.56.1 and IP 192.168.10.1.
2. Select homestead box in Virtualbox and go to settings -> network -> adapter 2 and select Host-only network (the one created in step above, 192.168.10.1)
3. So, homestead using adapter 1 (NAT) and adapter 2 (host-only)

Here are also some tips to debug slow vagrant box.

 

Folder sharing

Running Vagrant on windows has many limitations:

  • Using SMB needs the command to be run on elevated privileges which opens a security hole in terms of getting infected by viruses! I had a ransom-ware hidden on one of the projects I was working on and had windows defender installed.. Once I run the CLI as admin I opened the door to this virus and ended up formatting my whole machine to remove it!
  • Installed AVG but have to stop it each time when I start the machine

Killing the process

Cannot start the machine as a process is using it

tasklist /fi "Imagename eq vboxsvc.exe"

tasklist /fi "Imagename eq ruby.exe"

taskkill /PID 13192 /f  

 

Finally a fix for the VirtualBox Guest Additions warning.

https://github.com/dotless-de/vagrant-vbguest

 

Memory issues

If you face memory issues when running some php commands (example of composer update) then you need to create some swap files:

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 && sudo /sbin/mkswap /var/swap.1 && sudo /sbin/swapon /var/swap.1

Failed to open a session for the virtual machine

Do a vagrant halt then kill the processes named “Vbox Interface” or “Vbox manage” and try again. If not, then just check if an update version of the VIrtualBox is available and install it: this fixed the issue for me.