Skip to content

Instantly share code, notes, and snippets.

View uhho's full-sized avatar

Lukasz uhho

  • Axelspace
  • Tokyo
View GitHub Profile
@uhho
uhho / LLA2ECEF.py
Last active February 6, 2019 01:26
LatLonAlt to ECEF
# WGS84 ellipsoid constants
WGS84_A = 6378137 # radius
WGS84_E = 8.1819190842622e-2 # eccentricity
def LLA2ECEF(lat, lon, alt):
"""
Converts latitude (deg), longitude (deg) and altitude (m) to ECEF frame
https://en.wikipedia.org/wiki/Geographic_coordinate_conversion#From_geodetic_to_ECEF_coordinates
Returns:
@uhho
uhho / angle_between.py
Created August 29, 2018 00:10
Calculate angle between two vectors
import numpy as np
def unit_vector(vector):
return vector / np.linalg.norm(vector)
def angle_between(v1, v2):
v1_u = unit_vector(v1)
v2_u = unit_vector(v2)
return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))
@uhho
uhho / gravitational_accelleration.py
Created June 18, 2018 23:36
Gravitational accelleration
def g_at_distance(g_base, radius, distance):
"""
Calculate gravitational accelleration at a distance
- above the surface G * (radius / distance)^2
- below the surface G * (distance / radius)
Parameters
----------
g_base : float
gravitational accelleration at the surface
@uhho
uhho / pnpoly.ipynb
Last active April 5, 2018 00:01
Check if a point lies within a polygon
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@uhho
uhho / qrcode_with_image.py
Created September 1, 2017 00:07
Generating QR code with image at the center.
import pyqrcode
from PIL import Image
# create background - QR code
qr = pyqrcode.create('Some text',error = 'H')
qr.png('output.png', scale=10)
im = Image.open('output.png')
im = im.convert("RGBA")
@uhho
uhho / pandas_s3_streaming.py
Last active December 2, 2022 18:57
Streaming pandas DataFrame to/from S3 with on-the-fly processing and GZIP compression
def s3_to_pandas(client, bucket, key, header=None):
# get key using boto3 client
obj = client.get_object(Bucket=bucket, Key=key)
gz = gzip.GzipFile(fileobj=obj['Body'])
# load stream directly to DF
return pd.read_csv(gz, header=header, dtype=str)
def s3_to_pandas_with_processing(client, bucket, key, header=None):
@uhho
uhho / MultivariateVsMultipleNormal.ipynb
Created April 4, 2017 01:22
Multivariate Normal vs Multiple Normal
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@uhho
uhho / gist:481c20f093d56e1fe59c
Created February 26, 2015 06:08
Extracting private key and key certificate from .pfx file.
// create private key (any password is ok)
openssl pkcs12 -in xxx.pfx -nocerts -out example.key
// remove password
openssl rsa -in example.key -out example.key
// generate private/public pair
openssl pkcs12 -in xxx.pfx -out privpub.pem
// get public certificate from privpub
@uhho
uhho / gaussian.js
Created June 27, 2014 04:57
Two-dimensional Gaussian function in JavaScript
/**
* Two-dimensional Gaussian function
*
* @param {number} amplitude
* @param {number} x0
* @param {number} y0
* @param {number} sigmaX
* @param {number} sigmaY
* @returns {Function}
*/
@uhho
uhho / lpf.js
Created April 7, 2014 10:42
Low Pass Filter
// array of values
var values = [10,8,12,10,11,9,10,12,8,50,10,12,8];
// smoothing whole array
function lpf(values, smoothing){
var value = values[0];
for (var i = 1; i < values.length; i++){
var currentValue = values[i];
value += (currentValue - value) / smoothing;
values[i] = Math.round(value);