Thursday, May 31, 2018

Terminal display messed up when using tmux vim and docker container

Terminal display messed up when using tmux vim and docker container

Solution 1:

$ echo $TERM $LINES $COLUMNS

screen-256color 41 146

$ docker exec -it -e TERM=$TERM -e LINES=$LINES -e COLUMNS=$COLUMNS YOUR_CONTAINER_NAME bash

Solution 2:

$ reset

Solution 3:

$ stty size

41 146

$ stty rows 41 cols 146

Sunday, May 13, 2018

AutoHotkey

example.ahk:

; reload the autohotkey script.
^!r::Reload

; input date and time
#d::
  FormatTime, mydatetime,, M/d/yyyy HH:mm:ss
  SendInput, %mydatetime%
return

; input date
#f::
  FormatTime, mydate,, M/d/yyyy
  SendInput, %mydate%
return

; input date
#y::
  FormatTime, mydate,, yyyy-MM-dd
  SendInput, %mydate%
return

; press ctrl-alt 1
^!1::
SendInput, Hello World
return

; In command prompt window, press shift + insert to paste from clipboard
#IfWinActive ahk_class ConsoleWindowClass
<+Insert::
  SendInput, {Raw}%clipboard%
return
#IfWinActive

grep number

grep number

$ go version | grep -Eo '[0-9.]+'

String length in bytes in JavaScript

String length in bytes in JavaScript

(new TextEncoder('utf-8').encode('foo')).length

Reference:

https://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript

Photoshop alternative tool

Photoshop alternative tool

GIMP (GNU Image Manipulation Program) is a free and open-source raster graphics editor[6] used for image retouching and editing, free-form drawing, converting between different image formats, and more specialized tasks.

https://en.wikipedia.org/wiki/GIMP

Sketch is a proprietary vector graphics editor for Apple's macOS, developed by the Dutch company Bohemian Coding.

https://en.wikipedia.org/wiki/Sketch_(application)

Sunday, May 6, 2018

To connect to a remote MySQL Server via an SSH Tunnel

A SSH tunnel is a exactly as the name suggests, a tunnel over SSH on which we'll forward a specific port. The port will be accessible on your local machine, but will be automatically forwarded to the remote machine so it appears as if you're remote service (MySQL in this case) is actually local.

To connect to a remote MySQL Server via an SSH Tunnel:

$ ssh -i ubun-exp.pem -p 22 -L 127.0.0.1:3308:127.0.0.1:3306 username@example.com
$ mysql -u root -p -P 3308 -h 127.0.0.1

Note: The command above will open a pseudo terminal.

Note: You have to specify host with -h and put 127.0.0.1 instead of localhost since mysql will try to connect to the local MySQL socket on your computer instead of the TCP connection via port 3306.

If you only want to create a tunnel you can use the -NnT option:

$ ssh -i ubun-exp.pem -p 22 -NnT -L 127.0.0.1:3308:127.0.0.1:3306 username@example.com

Note: -N wich will disable the ability to execute a remote command.
Note: -n will prevent reading from stdin.
Note: -T will disable the pseudo-terminal allocation.

Reference: https://hostpresto.com/community/tutorials/how-to-connect-to-a-remote-mysql-server-via-an-ssh-tunnel/