Power User

Sometimes I stumble upon interesting commands, settings or procedures that might be useful in the future as well, so I'll document them here and who knows, maybe someone else will find something interesting here as well.

Git


Checking out pull requests locally

git fetch origin pull/<ID>/head:<BRANCH>

Reset date or author

Start an interactive rebase and choose edit / e for the commits you want to change, then reset the author for each of them and continue.

git rebase -i <ref>
git commit --amend --reset-author --no-edit
git rebase --continue

Source #1

Remove bin and obj folders

Deletes all bin and obj folders below the current directory with PowerShell, to force a full rebuild.

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

Source #1

Remove submodule

  • git submodule deinit -f -- path/to/submodule
  • rm -r path/to/submodule
  • Remove submodule entry from .gitmodules
  • Remove submodule entry from .git/config
  • Commit
  • git rm -r --cached path/to/submodule

Resync from remote branch

Resets the local branch to the remote branch, either by name or through its upstream with @{u}.

git reset --hard origin/feature/...
git reset --hard @{u}

As an alias that fetches first:

git config --global alias.resync "!git fetch && git reset --hard @{u}"
git resync

Push shorthand

HEAD stands in for the current branch name, so you don't have to type it out.

git push -u origin HEAD

Windows


Stop Chrome from redirecting to HTTPS for localhost

Once Chrome noticed your site using HTTPS it will keep redirecting you to HTTPS even if the webserver doesn't even host HTTPS sites. You can clear the cache and cookies, try to delete the HSTS policy, but nothing works, except this:

  • Open site and get redirected to HTTPS
  • Open the developer tool (F12)
  • Right click on the refresh button next to the address bar
  • Click on "Empty Cache and Hard Reload"
  • Browse to the none HTTP site

Credit gots to Galaxy Internet

Convert video to GIF with FFmpeg

Here's a short batch script that allows you to convert a video to a GIF with FFmpeg.

SET filters="fps=%4,scale=%3:-1:flags=lanczos"
ffmpeg -v warning -i %1 -vf "%filters%,palettegen" -y palette.png
ffmpeg -v warning -i %1 -i palette.png -lavfi "%filters% [x]; [x][1:v] paletteuse" -y %2
DEL palette.png

Usage: togif.bat <input.mp4> <output.gif> <width> <fps>

Disable AMD's VariBright "feature"

VariBright is responsible for automatically adjusting the brightness of your display depending on the content shown on the screen. While an interesting idea, it generally doesn't work as expected and leads to a very annoying brightness pumping.

  • Open the registry editor by pressing Win+R and typing in regedit
  • Browse to: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000
  • Right-Click on the 0000 key (it looks like a folder).
  • Select New->Dword.
  • Name the new registry entry PP_VariBrightFeatureEnable
  • Double-click on the PP_VariBrightFeatureEnable entry you just created.
  • Make sure it has a value of 0
  • Click OK, close the registry editory, and restart the machine.

Credit goes to Luke Taylor

Prevent the Logitech G930 headset from turing off after 15min

  • Close the Logitech Gaming Software
  • Start your favorite text editor with admin privileges
  • Open the file C:\Program Files\Logitech Gaming Software\Resources\G930\Manifest\Device_Manifest.xml
  • Set turnOffInterval="900" to 0 or any other time interval in seconds
  • Save and restart the Logitech Gaming Software
  • Don't forget to manually turn off your headset after use!

Starting application with elevated privileges

  • Windows Key
  • Search for your application
  • Ctrl + Shift + Enter
  • Wait for the UAC window
  • Select "Yes"

Remove ads in Viber

  • Start Notepad as administrator
  • Open the hosts file: %SystemRoot%\System32\drivers\etc\hosts
  • Add the follow line and save it
0.0.0.0 ads.viber.com

Remove ads in Skype

  • Start Notepad as administrator
  • Open the hosts file: %SystemRoot%\System32\drivers\etc\hosts
  • Add the follow two lines and save it
0.0.0.0 rad.msn.com
0.0.0.0 apps.skype.com

Finding timers which wake the computer

  • Open an elevated CMD session
  • Run powercfg /waketimers
  • Windows Key + R
  • Type in taskschd.msc and press Enter
  • Find the corresponding entries and disable them
  • Some application might activate the task again, so make sure to disable it in the given application as well

Preventing USB devices from waking the computer

  • Open an elevated CMD session
  • Run powercfg /devicequery wake_armed
  • Windows Key + R
  • Type in devmgmt.msc and press Enter
  • Find the corresponding device, Right Click on it and open their properties
  • Go to the Power Management tab
  • Uncheck Allow this device to wake the computer
  • Close PortableApps
  • Open the location of your PortableApps installation in Explorer
  • Browse to the directory X:\PortableApps\PortableApps.com\Data
  • Open the file PortableAppsMenu.ini in your favorite text editor
  • Change the GlobalHotKey key combination
  • Save the file and close the editor
  • Start PortableApps again
Allowed key combinations are: CTRL-ALT-SPACE, CTRL-ALT-P, CTRL-ALT-M, CTRL-SPACE, WIN-ALT-SPACE and DISABLED.
Note that WIN-ALT-SPACE will not work on many versions of Windows, but for me it works on Windows 10.

Disable Snap Assist

When you use a Windows Key + ← → ↑ ↓ hotkey in Windows 10, you'll get a suggestion of what other window you want to snap. This can be helpful, but is most of the time just annoying and requires you to press ESC. Here's how you disable Snap Assist.

  • Open the Settings app from the Start Menu
  • Select the System category
  • On the left side select Multitasking
  • Disable the third option "When I snap a window, show what I can snap next to it"

Debian


Partition and Format a Disk with Ext4

Get disk information

sudo fdisk -l

Partition the disk

parted /dev/sdX mklabel gpt
parted /dev/sdX mkpart primary 0% 100%
parted /dev/sdX print
parted /dev/sdX name 1 CoolName

Format the partition

mkfs -t ext4 -E lazy_itable_init=1 /dev/sdX1

Source #1, #2

Reverse SSH Tunnel

Local

ssh -i ~/.ssh/id_rsa -f -N -R 9999:localhost:22 remote.user@remote.host

Remote

ssh -i ~/.ssh/id_rsa -p 9999 local.user@localhost

AutoSSH Local

autossh -- -i ~/.ssh/id_rsa -o ControlPath none -R 9999:localhost:22 remote.user@remote.host -N

Generate SSH Key

Generate

ssh-keygen -t rsa -b 4096

Upload

ssh-copy-id user@host

Or

cat ~/.ssh/id_rsa.pub | ssh user@host "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

See also the GitHub help page and the Digital Ocean help page.

Listing active connections

sudo netstat -taupen

Running Node.js behind Apache

Installations

Install Node.js

sudo apt-get install nodejs nodejs-legacy

Install NPM - Node Package Manager

curl https://www.npmjs.com/install.sh | sudo sh

Install PM2 - To manage and daemonize Node.js apps

sudo npm install pm2 -g

Start PM2 with the OS

sudo pm2 startup debian

Install proxy mod (might already be installed)

sudo apt-get install libapache2-mod-proxy-html

Setting up the Node.js app

Create example app

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/');

Test app

node hello.js

Setup app with PM2

pm2 start hello.js

Additional PM2 commands

pm2 restart <app name>
pm2 info <app name>
pm2 stop <app name>
pm2 list
pm2 monit

Configure Apache

Activate proxy mod

sudo a2enmod proxy proxy_html
sudo service apache2 restart

Adjust virtualhost

<VirtualHost *:80>
    ServerAdmin admin@domain.tld
    ServerName domain.tld
    ServerAlias www.domain.tld
 
    ProxyRequests off
 
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
 
    <Location />
        ProxyPass http://127.0.0.1:8080/
        ProxyPassReverse http://127.0.0.1:8080/
    </Location>
</VirtualHost>

Reload apache configuration

sudo service apache2 reload

RouterOS


Securing your router

Check the official confluence page for more details. The wiki page is more for reference.

Port forwarding

You need a NAT rule per port that you're trying to forward.

Traffic that comes in from the WAN interface list on a specific port, should be forwarded (dst-nat) to a specific IP and port.

/ip firewall nat
add chain=dstnat protocol=tcp dst-port=80 in-interface-list=WAN action=dst-nat to-address=192.168.1.10 to-ports=80
add chain=dstnat protocol=tcp dst-port=443 in-interface-list=WAN action=dst-nat to-address=192.168.1.10 to-ports=443

See also: https://help.mikrotik.com/docs/spaces/RKB/pages/154042388/Port+forwarding

Referencing dynamic public IP address

For some firewall rules you're required to provide the public IP address. With a dynamic IP you would have to update the firewall rule every time the IP changes, which can be rather annoying and with many rules also time consuming.

Instead it's best to just add a new address list which then can be referenced and if the IP changes there's only one place you need to update.

/ip firewall address-list add address <IP>

The command line will then prompt you for a name, pick something descriptive like for example PUBLIC.

Hairpin NAT / NAT loopback

/ip firewall nat

add chain=srcnat src-address=192.168.1.0/24 dst-address=192.168.1.10 out-interface-list=LAN action=masquerade

add chain=dstnat dst-address-list=PUBLIC action=dst-nat to-address=192.168.1.10

EdgeOS


How to use the CLI

EdgeOS is basically a modified Debian system and supports a lot of the commonly known commands.

The most important command or rather key is the ?. It will list all available commands in the given situation.

With configure you switch into configuration mode where you can change the router settings. Leave this mode with exit.

Use commit to apply changes and save to write them to disk.

See the CLI Primer (part 1), CLI Primer (part 2) and CLI Primer (part 3) for more useful tips!

Restart lighttpd

sudo killall -SIGHUP lighttpd

Load an old configuration via CLI

  • Download configuration to router: curl -O http://...
  • Switch to config mode: configure
  • Load the config: load /config/config-old.boot
  • Commit to apply the changes: commit
  • Save and exist: save; exit

For reference and more information see this article.

Update system image via CLI

  • Download and add new image: add system image http://dl.ubnt.com/...
  • Check system images: show system image
  • Reboot system: reboot

For reference and more information see this article.