Skip to content

Instantly share code, notes, and snippets.

@amroamroamro
amroamroamro / README.md
Last active June 5, 2024 11:32
[Python] Fitting plane/surface to a set of data points

Python version of the MATLAB code in this Stack Overflow post: https://stackoverflow.com/a/18648210/97160

The example shows how to determine the best-fit plane/surface (1st or higher order polynomial) over a set of three-dimensional points.

Implemented in Python + NumPy + SciPy + matplotlib.

quadratic_surface

@hellpanderrr
hellpanderrr / python polygon scale .md
Last active April 21, 2022 11:24
python convex polygon scaling
import itertools as IT
def scale_polygon(path,offset):
    center = centroid_of_polygon(path)
    for i in path:
        if i[0] > center[0]:
            i[0] += offset
        else:
            i[0] -= offset
        if i[1] > center[1]: 
@kaesetoast
kaesetoast / fix-duplicate icon
Created November 18, 2014 10:33
Fix duplicate Chrome icon in Plank
sudo sed -i -r 's/(\[.+\])$/\1\nStartupWMClass=Google-chrome-stable/g' /usr/share/applications/google-chrome.desktop
anonymous
anonymous / set_pantheon_terminal_solarized
Created August 12, 2014 21:19
Sets Pantheon Terminal (Elementary OS) to Solarized Theme
#!/bin/bash
echo
echo "This script sets the pantheon terminal to the Solarized theme."
echo
until [[ $scheme -eq 1 ]] || [[ $scheme -eq 2 ]] || [[ $scheme -eq 3 ]]; do
echo "Choose one:"
echo "1) Light"
echo "2) Dark"
@jonathansick
jonathansick / gal_radii_pb.py
Last active April 5, 2024 18:23 — forked from PBarmby/gal_radii_pb.py
Compute deprojected galactocentric distance using astropy.coordinates. (By @PBarmby)
from astropy.coordinates import ICRS, Distance, Angle
from astropy import units as u
import numpy as np
def correct_rgc(coord, glx_ctr=ICRS('00h42m44.33s +41d16m07.5s'),
glx_PA=Angle('37d42m54s'),
glx_incl=Angle('77.5d'),
glx_dist=Distance(783, unit=u.kpc)):
"""Computes deprojected galactocentric distance.
@umpirsky
umpirsky / A.markdown
Last active August 3, 2023 18:14 — forked from olivierlacan/An_example.markdown
Sublime Text Monokai Sidebar Theme.
@eteq
eteq / pyspherematch.py
Last active January 29, 2020 04:42
Match two sets of on-sky coordinates to each other. I.e., find nearest neighbor of one that's in the other. Similar in purpose to IDL's spherematch, but totally different implementation. Requires numpy and scipy.
"""
Match two sets of on-sky coordinates to each other.
I.e., find nearest neighbor of one that's in the other.
Similar in purpose to IDL's spherematch, but totally different implementation.
Requires numpy and scipy.
"""
from __future__ import division
import numpy as np
@bellbind
bellbind / genetic.py
Created December 15, 2010 10:46
[python]Genetic Algorithm example
"""Genetic Algorithmn Implementation
see:
http://www.obitko.com/tutorials/genetic-algorithms/ga-basic-description.php
"""
import random
class GeneticAlgorithm(object):
def __init__(self, genetics):
self.genetics = genetics
pass