Skip to content

Instantly share code, notes, and snippets.

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

Kuba Podgórski kuba--

☮️
stop war
View GitHub Profile
@kuba--
kuba-- / wc-tail.py
Created May 19, 2013 07:23
unix wc | tail commands in python
def wc (fname, options = "-l"):
p = subprocess.Popen(['wc', options, fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result, err = p.communicate()
if p.returncode != 0:
return -1
return int(result.strip().split()[0])
def tail (fname, n = 30, out = subprocess.PIPE):
@kuba--
kuba-- / service.md
Last active March 11, 2017 13:45 — forked from naholyr/_service.md

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@kuba--
kuba-- / git-reset.sh
Last active October 1, 2021 06:57 — forked from nicktoumpelis/repo-rinse.sh
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@kuba--
kuba-- / .vimrc
Last active May 5, 2017 11:36
.vimrc
" NeoBundle Scripts---------------------------------
if has('vim_starting')
set runtimepath+=~/.config/nvim/bundle/neobundle.vim/
set runtimepath+=~/.config/nvim/
endif
let neobundle_readme=expand('~/.config/nvim/bundle/neobundle.vim/README.md')
if !filereadable(neobundle_readme)
echo "Installing NeoBundle..."
@kuba--
kuba-- / elasticput.go
Created May 23, 2017 21:34
elasticsearch put index
package main
import (
"encoding/csv"
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
@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);
}
@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
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-- / 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
#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)