Skip to content

Instantly share code, notes, and snippets.

View mCzolko's full-sized avatar

Michael Czolko mCzolko

View GitHub Profile
@mCzolko
mCzolko / OSVC.ts
Created February 19, 2024 10:46
Výpočet daně, socka a zdrávka pro rok 2024 (po reformě)
export class OSVC {
public readonly percentageDiscount = 0.6
constructor(public readonly expectedIncome: number) {}
get totalExpenses(): number {
return this.healthInsurance + this.socialInsurance + this.taxes
}
get netIncome(): number {
@mCzolko
mCzolko / BinaryIntervalSearch.kt
Last active October 20, 2023 23:49
Binary Interval Search
class BinaryIntervalSearch(
private val initialValue: Int,
private val estimationStep: Int,
private val maxValue: Int,
val meetsCondition: () -> Boolean = { true }
) {
fun search(doWork: (newValue: Int) -> Unit): Int {
if (this.maxValue < initialValue) {
throw Error("Max value cant be smaller than initial value")
@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() {
@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 / .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 / 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 / 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 / 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 / install-mac.sh
Last active November 2, 2023 08:42
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 maccy google-chrome warp rectangle mimestream messenger github visual-studio-code jetbrains-toolbox spotify 1password keepingyouawake
# Docker stuff
@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 = '['