Skip to content

Instantly share code, notes, and snippets.

View kuba--'s full-sized avatar
☮️
no war

Kuba Podgórski kuba--

☮️
no war
View GitHub Profile
@kuba--
kuba-- / KeyMapping.app
Created January 24, 2024 17:58
OSX Key Mapping
on run {input, parameters}
do shell script "hidutil property --set '{\"UserKeyMapping\":[{\"HIDKeyboardModifierMappingSrc\":0x700000064,\"HIDKeyboardModifierMappingDst\":0x700000035}]}'" with administrator privileges
return input
end run
@kuba--
kuba-- / exec.cpp
Created December 16, 2021 10:45
c++ exec system command
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
std::string exec(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
@kuba--
kuba-- / m4a_to_mp3.sh
Last active January 24, 2024 17:55
Music files
for i in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do find . -type f -name "${i}*" -print ; done > /tmp/files
cat /tmp/files | while read line || [[ -n $line ]]; do d=`dirname "${line}"`; b1=`basename "${line}"`; b2=`basename "${line}" | cut -c4-`; mv "${d}/${b1}" "${d}/${b2}"; done
find . -type f -name "*.m4a" -exec ffmpeg -v 5 -y -i '{}' -acodec libmp3lame -ac 2 -ab 192k '{}'.mp3 \; -print
@kuba--
kuba-- / disjoint.go
Created April 7, 2019 00:44
Disjoint Sets
package sets
import (
"fmt"
"strings"
)
// DisjointSet tracks a set of elements partitioned
// into a number of disjoint (non-overlapping) subsets.
type DisjointSet struct {
@kuba--
kuba-- / pairing.go
Created April 7, 2019 00:39
Pairing Heaps
package heaps
// Elem is a comparable element of the heap
type Elem interface {
Compare(elem Elem) int
}
// PairingHeap is a type of heap data structure
type PairingHeap struct {
elem Elem
#Delete local tags.
git tag -d $(git tag -l)
#Fetch remote tags.
git fetch
#Delete remote tags.
git push origin --delete $(git tag -l) # Pushing once should be faster than multiple times
#Delete local tags.
git tag -d $(git tag -l)
@kuba--
kuba-- / get_latest_release.sh
Created August 10, 2018 17:35 — forked from lukechilds/get_latest_release.sh
Shell - Get latest release from GitHub
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Usage
# $ get_latest_release "creationix/nvm"
# v0.31.4
execute pathogen#infect()
let g:go_fmt_command = "goimports"
let g:clang_format#detect_style_file=1
let g:clang_format#auto_format=1
let NERDTreeShowHidden=1
set autoindent
set tabstop=4 " Show existing tab with 4 spaces width
set shiftwidth=4 " When indenting with '>', use 4 spaces width
@kuba--
kuba-- / dist.go
Created June 6, 2017 22:31
Haversine formula
func dist(lat1, lon1, lat2, lon2 float64) float64 {
const R = 1000.0 * 6378.132 // Radius of earth in m.
lat := lat2*math.Pi/180.0 - lat1*math.Pi/180.0
lon := lon2*math.Pi/180.0 - lon1*math.Pi/180.0
a := math.Sin(lat/2.0)*math.Sin(lat/2.0) + math.Cos(lat1*math.Pi/180.0)*math.Cos(lat2*math.Pi/180.0)*math.Sin(lon/2.0)*math.Sin(lon/2.0)
c := 2.0 * math.Atan2(math.Sqrt(a), math.Sqrt(1.0-a))
d := R * c
return d
@kuba--
kuba-- / StringGenerator.java
Created May 30, 2017 11:48
String Generator
import java.security.SecureRandom;
import java.math.BigInteger;
final class StringGenerator {
private SecureRandom random = new SecureRandom();
public String next() {
return new BigInteger(128, random).toString(32);
}