Author: Roman Leonenkov
Java Optional implementation in Golang
On the moment of writing generics in Golang (v1.26) are not very flexible, however you can implement something which almost feels like true Java.
Code snippet to print out a go app memory status
|
1 2 3 4 5 6 7 |
// For clearer results it's better to call this function after runtime.GC() invocation. // The code was borrowed from 100 go mistakes book. func printAlloc() { var m runtime.MemStats runtime.ReadMemStats(&m) fmt.Printf("%d KB\n", m.Alloc/1024) } |
Golang – Debug a unit test manually
GoTo – a simple cross-platform command line SSH manager
GoTo is a wrapper around SSH client. The difference with Putty is that GoTo is a command line application that does not depend on any OS-specific graphic libraries and thus is very portable across platforms, however it lacks any connection logic therefore SSH client needs to be available in your binary $PATH.
Grep cheatsheet for SysAdmins
Find all files which contain specific text and print these file names to the console
|
1 2 3 |
# q = quiet; that means that grep will exit with status "0" (success) # if a file contains either word "some" or word "text" find . -type f -exec bash -c "grep -q -e some -e text {} && echo {}" \; |
Restore UNIX acess permissions for all subfolders and files of the specified directory
|
1 2 3 4 |
# Reset access rights to 'rwxr-xr-x' for all subfolders of the specified directory find /home/username/public -type d -exec chmod 0755 {} \; # Reset access rights to 'rw-r--r--' for all files of the specified directory find /home/username/public -type f -exec chmod 0644 {} \; |
Be aware – this site doesn’t use cookies!
The image was taken from here.
Simple repeat function implementation in JS
|
1 |
const repeat = (func, times) => [...Array(times).keys()].map(func); |
How to compare two folders in UNIX using diff
|
1 2 |
# If it's required to compare two folders by their files names $ diff <(cd folder1 && find | sort) <(cd folder2 && find | sort) |
|
1 2 |
# ... or if you want deep comparison $ diff --brief -rb folder1 folder2 |
Set access and modification time for all files and subfolders in a UNIX directory
All files in current folder were created on 24 of January 2021, …
Use Datalist tag to provide autocomplete options for Input field
Here is an example …
Swapping 2 JS variables’ values in one line
|
1 2 3 |
let a = 10, b = 20; [a, b] = [b, a]; console.log(a, b); // => 20, 10 |
Handy JS in operator
The ‘in’ operator can help to check if an Array contains specified index or an Object contains a specified key …
His favorite language…
The hilarious image above was taken from this post on reddit. I just couldn’t hold myself from copying it here.
Conditionally add a key to a JS Object or Array
Remove a key from a JS Object using Spread operator
Nice tricks with Switch operator in JavaScript
NetworkManager – set route metric
|
1 |
$ ip route |
How to calculate ISIN checksum digit
How to calculate CUSIP checksum digit
How to ssh to your linux boxes without a password
1. Generate your ssh key pair if you haven’t one. Use default values, don’t set password …
Генерируем SSL сертификат с помощью Let’s Encrypt
Здесь описан процесс получения сертификатов letsencrypt в ручном режиме(это когда мы переносим сертификат на сервер вручную)
- Клонируем репо letsencrypt’а
1git clone https://github.com/letsencrypt/letsencrypt
- Запускаем генерацию командой:
1sudo -H ./letsencrypt-auto certonly --renew-by-default --manual -d www.МОЙ_ДОМЕН.com [-d МОЙ_ДРУГОЙ_ДОМЕН.com]
Анимация загрузки страницы без JavaScript
Если у Вас есть приложение, загрузка которого занимает значительное количество времени, то было бы здорово установить заставку, чтобы немного оживить страницу и не дать загрустить пользователю. Часто, анимацию делают с помощью JavaScript, забывая, что CSS дает нам весьма широкие и более легковесные решения.
…