Skip to content

Instantly share code, notes, and snippets.

View liflovs's full-sized avatar
⚔️

Serhii liflovs

⚔️
View GitHub Profile

Bionic Reader Bookmarklet

This bookmarklet is inspired by Bionic Reader API that is truly incredible. However I have issues with service APIs that are not clear on how they handle the privacy and security of my data. So I made a quick and dirty bookmarklet to do the job locally.

  • Create a new bookmark in your browser
  • Use this script as the address:
javascript:(function(){!function(){window.hasOwnProperty("bionicWordWrapApplied")||(!function(e){var n,t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,null);for(;n=t.nextNode();){for(var o,r=n.parentNode,d=n.nodeValue;o=d.match(/^(\s*)(\S+)/);){d=d.slice(o[0].length),r.insertBefore(document.createTextNode(o[1]),n);var a=Math.ceil(o[2].length/2),c=r.insertBefore(document.createElement("b"),n);c.appendChild(document.createTextNode(o[2].slice(0,a)));var i=r.insertBefore(document.createElement("span"),n);i.appendChild(document.createTextNode(o[2].slice(a)))}n.nodeValue=d}}(document.body),window.bionicWordWrapApplied=!0
@liflovs
liflovs / wsl_nameserver.sh
Last active April 27, 2022 15:26
WSL force custom nameserver (Temporary failure in name resolution issue)
sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf
^(https?\:\/\/)?(www\.youtube\.com|youtu\.be)\/.+$
@liflovs
liflovs / pg.js
Created December 13, 2021 16:50
Postgres quick solutions cheatsheet
/* get all absent ('' and NULL) values as 0 */
coalesce(cast(nullif("value",'') as float),0)
@liflovs
liflovs / git_cleanup.sh
Created December 13, 2021 04:26
Cleanup merged local branches
git branch --merged | grep -v "\*" | grep -Ev "(\*|master|develop|staging)" | xargs -n 1 git branch -d
@liflovs
liflovs / setup_git_ssh.sh
Created November 23, 2021 10:45
Git SSH key from environmental variable
#!/usr/bin/env bash
# Init .ssh dir and expand $SSH_KEY
mkdir -p ~/.ssh
echo -e "${SSH_KEY//_/\\n}" > ~/.ssh/id_rsa
chmod og-rwx ~/.ssh/id_rsa
# Uncomment to debug
# ls -la ~/.ssh
# cat ~/.ssh/id_rsa
@liflovs
liflovs / port_forward.ps1
Last active January 11, 2022 14:56
WSL2 port forwarding to windows host
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
Write-Output "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@liflovs
liflovs / themeswitcher.ps1
Last active March 30, 2021 16:05
Powershell windows theme switch automation
function Delete-ScheduledTask([string] $taskName)
{
Write-Host "Delete schedule task for $taskName"
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
}
function DeleteIfExists-ScheduledTask([string] $taskName)
{
$exists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName}
@liflovs
liflovs / exchange_rate.js
Created December 9, 2020 13:45
Exchange rate Google App Sript example (EUR to UAH)
function getEuroUahRate(date) {
var str = Utilities.formatDate(date,'GMT+3', 'yyyyMMdd')
var jsonArr = JSON.parse(UrlFetchApp.fetch('https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=' + str + '&json').getContentText())
var json = null
for (var i = 0; i < jsonArr.length; ++i) {
if (jsonArr[i].cc == 'EUR') {
json = jsonArr[i]
}
}
if (json && json.rate) {