Useful Code Snippets & Commands
Some of the contents in this page are not originally from me, every function or command that I found it very useful or something that I create by myself, I will put it in here.
< Back to homepage
Shell: SSH Tunnel Server Services to Local
- Host docker IP address:
172.17.0.1 - Server local IP address:
127.0.0.1 - Server private IP address:
192.168.10.111
# direct
ssh username@public_ip -L 3306:server_local_ip:3306 -L 27017:server_local_ip:27017
# to docker
ssh username@public_ip -L docker_host_ip:3306:server_local_ip:3306 -L docker_host_ip:27017:server_local_ip:27017
# with key
ssh -i ~/key.pem username@public_ip -L docker_host_ip:3306:server_private_ip:3306 #shell
JavaScript: Chunk an Array
function chunkItems(arr, chunkSize = 4) {
const chunks = Array.from(
{ length: Math.ceil(arr.length / chunkSize) },
(_, i) => {
const start = chunkSize * i;
return arr.slice(start, start + chunkSize);
}
);
} #javascript
JavaScript: Get Date
const date = new Date();
// change `default` to a specific TimeZone
const day = date.toLocaleString('default', { weekday: 'long' });
const month = date.toLocaleString('default', { month: 'short' });
const year = date.toLocaleString('default', { year: 'numeric' }); #javascript
JavaScript: Object Properties
const user = { id: 1, name: 'John Doe' };
const contact = { phone: 4722880, address: 'Akihabara' };
Object.keys(user); // getting the keys => ["id", "name"]
Object.values(user); // getting the values => [1, "John Doe"]
Object.assign(user, contact); // extend objects => {address: "Akihabara", id: 1, name: "John Doe", phone: 4722880} #javascript