Skip to content

Instantly share code, notes, and snippets.

View mCzolko's full-sized avatar

Michael Czolko mCzolko

View GitHub Profile
@mCzolko
mCzolko / .bash_profile
Last active October 8, 2019 11:33
NVM automatic switch
# Install NVM or FVM
# https://github.com/nvm-sh/nvm
# https://github.com/Schniz/fnm
cd () { builtin cd "$@" && chpwd; }
chpwd () {
NVM_PATH="$PWD/.nvmrc"
if test -f "$NVM_PATH"; then
nvm use
@mCzolko
mCzolko / RightClick.js
Last active May 10, 2021 08:58
ReactJS right click (contextmenu) handler
import { createElement, useEffect, useRef } from 'react'
const RightClick = ({ as = 'div', onRightClick, children, ...rest }) => {
const ref = useRef()
useEffect(() => {
const handler = e => {
e.stopPropagation()
e.preventDefault()
onRightClick(e)
@mCzolko
mCzolko / progressBar.ts
Created September 29, 2021 09:37
Simple progress bar in TS
export default (prc: number) => {
const cols = process.stdout.columns - 7
const oneBar = cols / 100
let i = 0
let progressBar = '['
@mCzolko
mCzolko / install-mac.sh
Last active June 29, 2025 13:05
Install Mac Apps
# Install homebrew
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install wget
# Install applications
brew install --casks slack maccy google-chrome warp rectangle messenger github visual-studio-code jetbrains-toolbox spotify 1password keepingyouawake
# Docker stuff
@mCzolko
mCzolko / cns.kt
Last active September 7, 2022 21:40
CNS calculation
import kotlin.math.abs
import kotlin.math.log
import kotlin.math.max
import kotlin.math.min
/**
* Shortcuts for the most common operations:
* AAP = absolute atmospheric pressure
* ppO2 = partial pressure of oxygen
* fO2 = oxygen fraction
@mCzolko
mCzolko / md.sh
Last active September 7, 2022 23:32
Maximum operational depth - Command line app
#!/bin/node
const calculate = (arg) => {
const o2percentage = Number(arg)
const fO2 = o2percentage / 100
const mod = (ppO2) => Number((((ppO2 / fO2) - 1) * 10).toFixed(2))
console.log(`EAN${o2percentage} (content ${o2percentage}% oxygen)`)
@mCzolko
mCzolko / geolocation.ts
Created October 3, 2022 10:47
Geolocation typescript function
const geolocation = (): Promise<GeolocationPosition> => new Promise((resolve, reject) => {
const geo = navigator.geolocation
if (!geo) {
reject('Geolocation is not supported')
return
}
geo.getCurrentPosition(
resolve,
@mCzolko
mCzolko / .gitconfig
Last active November 10, 2022 10:12
[core]
excludesfile = ~/.gitignore
[alias]
co = checkout
ci = commit
pp = push
s = status -s
st = status -s
df = diff --color --color-words --abbrev
aa = add --all
@mCzolko
mCzolko / .bash_profile
Created October 13, 2022 13:54
add `source ~/.bash_profile` to .zprofile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
alias reload="source ~/.bash_profile && echo Bash profile reloaded"
alias ll="ls -al"
alias cdw="cd ~/workspace"
@mCzolko
mCzolko / magbat.js
Created April 23, 2023 14:27
Magic Battery - Get the battery percentage of your Apple Magic devices (Keyboard, Trackpad)
// npm install ioreg --save
const ioreg = require('ioreg')
async function getExternalDevicesBatteryPercent() {
const devices = await ioreg('AppleDeviceManagementHIDEventService')
const externalDevices = devices.filter(device => !!device['BatteryPercent'])
return externalDevices.map(device => ([ device['Product'], device['BatteryPercent'] ]))
}
async function main() {