Get the current weather (with graphics!) in your terminal

Developer @igor_chubin has created a new awesome tool for displaying the current weather in beautiful graphs right inside your terminal.

All you have to do is curl the website, wttr.in

If your distro don’t include cURL already, install it (for Debian/Ubuntu-based distros) by running

sudo apt install curl

Then you can simply run

curl wttr.in

to see the weather come to life!

Add text color to Linux bash scripts

Bash supports coloring text, but I never remember the syntax, so here’s a little cheat sheet. During my little research it also seems you can enter the color codes in two ways as illustrated below:

echo -e "\033[0;32m Hello world!"
echo -e "\e[32m Hello world!"

Some more examples:

Difficult syntax:
\033[0;xxm (where xx is color code)
Easier syntax:
\e[xxm (where xx is color code)

I’m not sure if there’s any reason to choose one or the other, but the latter example is arguably easier to remember.

All color codes:

Reset color   0
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown/Orange 0;33
Light Gray 0;37
Dark Gray 1;30
Light Blue 1;34
Light Green 1;32
Light Cyan 1;36
Light Red 1;31
Light Purple 1;35
Yellow 1;33
White 1;37

You can also do lots of other things in bash, such as blinking text, bold, etc. Take a look at this site for more examples.

If you like to create CLI tools, adding some colors will make it a lot more immersive and easier to read output, like this example:

How to brutally kill a process in Windows environment

Today we’ll go over the various methods to kill a process. Can be useful especially if the process is stuck somehow and you’re having trouble closing/killing it.

Kill process with WMI queries

Open cmd.exe and run command:

wmic process where name='myprocessname.exe' delete

Batch kill in command prompt

Open cmd.exe and run command:

taskkill /IM "myprocessname" /T /F

/IM is required to pick process, but the extra parameters /T and /F are optional. They’re quite useful though:

/T = also kills child processes
/F = force termination of your process

Kill it the powerful way

Indeed. You can also kill it using Powershell, but you need to find the process ID first. Open Powershell prompt and simply type

Get-Process myprocessname | Select -expand id
# use the id returned in the next command:
kill -id id

Kill process using graphical user interface

You’re probably familiar with Task Manager. Open it by right-clicking on the taskbar and click on “Task Manager”. If that fails, or if you need to run it as another user, you can browse to %windir%\system32\ and run the executable file, taskmgr.exe.

If you’re lucky you can just kill the process and get on with your life. But, if you want to figure out what’s wrong, then a great tip is to open the Resource Monitor and Filter by process. This will show you all disk I/O file handles related to your process so you might actually see what exactly is hanging.

Managing WiFi profiles in Windows 10

Windows 10 removed the ability to list saved WiFi profiles in the Network and Sharing Center, so now we have to resort to the CLI.

 

To list all existing profiles (WLAN networks you’ve connected to in the past):

netsh wlan show profiles

 

To remove a network from your cache:

netsh wlan delete profile name="SSID"

Replace SSID with the profile/network you wish to delete.

Create a su command for Windows Command Prompt

As an IT tech I often have to open my command prompt as my domain administrator user which has administrator access on remote computers. I always forgets to right-click cmd and choose “Run as …” so I figured out a little shortcut for those times to mimic the su function in Linux.

Please note this won’t turn your currently open command prompt into an elevated one, it will just run a new cmd.exe process as the user you need.

Open an elevated command prompt and change directory to %windir%\system32 and run this command:

echo runas /user:domain\username "cmd" > sudo.bat

Now you can type “sudo” wherever (in your Run window or an existing cmd prompt) and it will prompt you for the password and open a new cmd window with the pre-defined user.

Task Manager for remote computer

It’s not possible to run the Task Manager GUI on a remote computer, but using the tasklist cmdlet you’ll be able to retrieve all running processes in all sessions (user processes, services, etc)

The command is as easy as:

tasklist /S remotehost

Remember you will need local administrator access for the remote computer (i.e. domain admin). Then you can either start cmd.exe as domain admin, or add the credentials to the tasklist command:

tasklist /S remotehost /U domain\username /P password

Output will look like:

Delete entry from Bash history

First type history to see your bash command history.

Find the entry/command you’d like to erase from history and note the id on the left column.

history -d 1234

Replace 1234 with the actual ID.

Example:

$ history
  640  cd ~
  641  ls -la
  642  crontab -e
  643  exit
  644  free -h
  645  df -h
$ history -d 645
$ history
  640  cd ~
  641  ls -la
  642  crontab -e
  643  exit
  644  free -h

As you can see, the df -h command was erased from the history.

Make an app with Atom Electron

1: Install Node.js (also includes npm)

2: Create your app (requires index.html, main.js, package.json) [1]

3: Optionally mask your source files to an .asar file. [2]

3: Run npm install electron-packager -g to install the electron-packager [3]

4: Run electron-packager <sourcedir> <appname> --platform=<platform> --arch=<arch> [optional flags...]

Examples:

electron-packager . --platform=win32 --arch=x64 --version="0.35.0" --out="App" asar="true"

electron-packager . --platform=win32 --arch=x64 --version="0.37.6" --out="App" 5.1.8

electron-packager . --platform=win32 --arch=x64 --appname="BinHexDec" --icon="monitoricon.ico" --version="0.37.6" --out="App" --version-string.FileDescription="Binary Hex Decimal Converter" --app-copyright="Teknix" --version-string.OriginalFilename="BinHexDec.exe" --version-string.CompanyName="Teknix" --version-string.ProductName="BinHexDec" --build-version="1.0.0" --app-version="1.0.0" BinHexDec-1.0.2

Sources:

[1] http://electron.atom.io/docs/latest/tutorial/quick-start/
[2] https://github.com/electron/asar
[3] https://www.npmjs.com/package/electron-packager

Add remote access to MySQL server

Follow the commands below to setup a new user and open up for remote access to a specific database on your MySQL server.

$ mysql -u root -p
Enter your MySQL root password.
mysql> CREATE USER 'itdb_admin';
mysql> CREATE DATABASE itdb_db;
mysql> GRANT ALL PRIVILEGES ON itdb_db.* to 'itdb_admin'@'%' IDENTIFIED BY 'my-password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
$ sudo nano /etc/mysql/my.cnf
Comment the following line by setting a # in front (to disable it):
bind-address = 127.0.0.1
$ sudo service mysql restart

Quick summary:

1) Open the MySQL CLI
2) Create a new database
3) Create a new user
4) Give the user full access to the database. Notice the '%' which means we’re talking about remote access. The same user can have different access levels based on the connection (whether it’s remote or local)
5) Flush/refresh the privileges so they become active
6) Disable bind-address so the MySQL server will listen on any source address
7) Restart the MySQL service to reload the config file