Skip to content

Instantly share code, notes, and snippets.

@unicornist
unicornist / guide.md
Last active October 15, 2023 17:43
Bidirectional network connection between WSL2 and Windows

Get WSL2 IP in Windows:

wsl hostname -i

Get Windows IP in WSL2:

export hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
@unicornist
unicornist / package.json
Created April 22, 2021 10:45 — forked from chalist/package.json
pckage.json for coompile and lint scss files and minify css, lint and minify js, inject css with browserSync and watch files
{
"name": "bookism",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"scss": "node-sass --output-style compressed --watch src/scss -o dist/css",
"serve": "browser-sync start --proxy 0.0.0.0:9999 --files 'dist/css/*.css'",
"clean": "rimraf dist/{css/*,js/*}",
"lint": "eslint src/js || true",
@unicornist
unicornist / complete-example.js
Last active May 9, 2021 13:36
Limited parallel async operations (aka Queue/Workers) in JavaScript ES6 (most compact code - essential parts only)
const queueSize = 10
const parallelWorkerCount = 3
const sampleQueue = ','.repeat(queueSize).split(',').map(()=>Math.floor(Math.random()*1000))
console.log('sampleQueue:', sampleQueue)
const queueGenerator = (function *(){
for (const item of sampleQueue) yield item;
})()
@unicornist
unicornist / .colors
Last active November 30, 2020 23:23 — forked from daytonn/.colors
Bash Color functions
black="\033[0;30m"
blackb="\033[1;30m"
white="\033[0;37m"
whiteb="\033[1;37m"
red="\033[0;31m"
redb="\033[1;31m"
green="\033[0;32m"
greenb="\033[1;32m"
yellow="\033[0;33m"
yellowb="\033[1;33m"
@unicornist
unicornist / mongo-dbs-collections.sh
Last active November 16, 2020 01:01
Get all MongoDB database names and collections names for each, using mongo binary and jq
dbs=$(
mongo --quiet --eval "db.adminCommand('listDatabases')" |
jq ".databases[].name|select((.!=\"admin\") and (.!=\"config\") and (.!=\"local\"))" |
sed "s/\"//g"
)
for db in $dbs
do
collections=$(
mongo $db --quiet --eval 'db.getCollectionNames()' |
jq .[] |
@unicornist
unicornist / checkFont.js
Last active November 16, 2020 02:15
Detect actual browser font support via `Canvas`-based measurement
(function () {
const options = {
text: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*()_+`-={}|[]\\:";\'<>?,./',
fontSize: 72,
baseFont: 'monospace'
}
this.checkFont = (input) => {
const fonts = (typeof input === 'string') ? input : (getComputedStyle(input).getPropertyValue('font-family') || input.style.fontFamily)
const ctx = document.createElement('canvas').getContext('2d')
@unicornist
unicornist / ssh-copy-id for Windows.md
Created September 23, 2019 21:04
ssh-copy-id for Windows

having any kind of command prompt that allows you to run basic linux commands (e.g. CAT) you could do the following:

cat ~/.ssh/id_rsa.pub | ssh user@server "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys"

If you have no id_rsa.pub file you can create one like this:

ssh-keygen -t rsa

@unicornist
unicornist / people-query.js
Created January 28, 2019 16:54
Hotjar Application Problem
module.exports = (people) => people.reduce((result, person) => {
if (person.age>30 && person.age<40)
result[person.gender].push(person.name)
return result;
}, {"Male": [], "Female": []});
@unicornist
unicornist / Persian CharFix Arabic (Selection).sublime-macro
Created January 12, 2019 20:53
SublimeText Macros to convert some Arabic chars (yeh, keh, digits) and convert English digits to their correct Persian alternatives.
[
{"command": "insert_snippet", "args": {"contents": "${SELECTION/(?<1>\\x{661})|(?<2>\\x{662})|(?<3>\\x{663})|(?<4>\\x{664})|(?<5>\\x{665})|(?<6>\\x{666})|(?<7>\\x{667})|(?<8>\\x{668})|(?<9>\\x{669})|(?<10>\\x{660})|(?<11>\\x{64A})|(?<12>\\x{643})/(?{1}\\x{6F1}:(?{2}\\x{6F2}:(?{3}\\x{6F3}:(?{4}\\x{6F4}:(?{5}\\x{6F5}:(?{6}\\x{6F6}:(?{7}\\x{6F7}:(?{8}\\x{6F8}:(?{9}\\x{6F9}:(?{10}\\x{6F0}:(?{11}\\x{6CC}:\\x{6A9})))))))))))/gm}"}}
]
@unicornist
unicornist / Coda Persian Fixes.user.js
Last active January 2, 2020 11:29
Collection of: UserScripts (GreeseMonkey / TamperMonkey)
// ==UserScript==
// @name Coda Persian Fixes
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://coda.io/*
// @grant GM_addStyle
// ==/UserScript==