Skip to content

Instantly share code, notes, and snippets.

View habibutsu's full-sized avatar

Alexander Verbitsky habibutsu

View GitHub Profile
@habibutsu
habibutsu / distance.py
Last active October 29, 2021 15:38
Different ways calculate geo-distance in Python
'''
Requirements:
geographiclib==1.46.3
pyproj==1.9.5.1
geopy==1.11.0
git+https://github.com/xoolive/geodesy@c4eb611cc225908872715f7558ca6a686271327a
geo-py==0.4
'''
from math import radians, sin, cos, asin, sqrt, pi, atan, atan2, fabs
from time import time
@habibutsu
habibutsu / fake_circle.js
Created February 12, 2017 14:59
Fake circle for mapbox-gl-js
function metersToPixelsAtMaxZoom(latitude, radius){
// ~0.075m/px (meters per pixel)
return radius / 0.075 / Math.cos(latitude * Math.PI / 180)
}
map.addSource("point", {
type: 'FeatureCollection',
features: [
{
"type": "Feature",
"geometry": {
@habibutsu
habibutsu / Makefile
Created May 24, 2017 16:48
Executing Python from Go
init:
pip install msgpack-python==0.4.8
go get gopkg.in/vmihailenco/msgpack.v2
run:
go run main.go
@habibutsu
habibutsu / Makefile
Created June 6, 2017 12:46
Running Raspberry in QEmu
IMAGE_TAG=2017-04-10
data/${IMAGE_TAG}-raspbian-jessie-lite.img:
mkdir -p data
wget \
-O data/${IMAGE_TAG}-raspbian-jessie-lite.zip \
http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-${IMAGE_TAG}/${IMAGE_TAG}-raspbian-jessie-lite.zip
unzip data/${IMAGE_TAG}-raspbian-jessie-lite.zip -d ./data
data/kernel-arm.img:
@habibutsu
habibutsu / docker_cleanup.sh
Created September 4, 2017 08:31
Docker cleanup
# Remove unused docker images
docker rmi $(docker images | grep "<none>"| awk -F' ' '{print $3}')
docker rmi $(docker images -aq --filter dangling=true)
# Remove orphaned docker volumes
docker volume rm $(docker volume ls -qf dangling=true)
# Remove dead containers
docker ps --filter status=dead -aq | xargs -r docker rm -v
@habibutsu
habibutsu / json.elm
Last active October 10, 2017 10:52
Elm examples
import Html exposing (text)
import Json.Decode
type alias Car =
{ sensor1: Int
, sensor2: Int
}
type DrivingMode
@habibutsu
habibutsu / image_hlp.py
Last active February 11, 2018 18:32
Python helpers
import io
import logging
import math
import cv2
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
@habibutsu
habibutsu / bulbacon_test.py
Created January 31, 2019 11:01
Solution of bulbacon's task (https://goo.gl/cCqrJw)
import itertools
import random
import sys
import operator
import functools
import types
import math
import numpy as np
@habibutsu
habibutsu / remote_file.py
Created May 31, 2019 15:30
Reading remote file through http
import io
from http import HTTPStatus
from urllib.request import Request, urlopen
from urllib.error import HTTPError
class RemoteFile(io.IOBase):
'''
Example of usage
@habibutsu
habibutsu / python_memory_management.md
Last active September 6, 2019 13:44
Управление памятью в питоне

Управление памятью в Python

Организация памяти

Память в Python организована в несколько уровней.

  • Слой 3 (Уровень ядра) - предназначен для non-object данных самого интерпрeтатора
  • Слой 2 - выделение памяти под объекты
  • Слой 1 - PyMem_ API