Skip to content

Instantly share code, notes, and snippets.

Michael Pilosov mpilosov

Block or report user

Report or block mpilosov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mpilosov
mpilosov / jetplane.py
Created May 31, 2018
Three-Dimensional Projections (with Linear Algebra)
View jetplane.py
import numpy as np
from matplotlib import pyplot as plt
## DEFINE RE-USABLE METHODS
def rotX(theta): # build a rotation matrix around the y-axis
R = np.eye(3)
R[1,1] = np.cos(theta)
R[1,2] = -np.sin(theta)
R[2,1] = np.sin(theta)
@mpilosov
mpilosov / circle_draw.py
Last active May 31, 2018
One way to draw an ellipse in python (with two functions)
View circle_draw.py
import numpy as np
from matplotlib import pyplot as plt
def drawellipse(center = [0,0], radius = 1, k=1, h=1, N=50):
assert len(center) == 2 # good practice to do things like this.
x0, y0 = center
x = np.linspace(x0-h*radius , x0+h*radius, N)
y = np.sqrt(radius**2 - ((x-x0)/h)**2 )*k # from the eq for an ellipse
plt.plot(x, -y+y0, c='blue')
plt.plot(x, y+y0, c='red')
@mpilosov
mpilosov / pystrings.py
Created May 25, 2018
Favorite Python String Tricks
View pystrings.py
a = 'trip distance'
b = ' '.join([s.capitalize() for s in a.split(' ')])
print(b)
View apache.md

(as root)

mkdir /var/www/website.com
chown $SAFEUSER:$SAFEUSER /var/www/website.com
export SAFEUSER=yourname (if $SAFEUSER is not set)

This is where you keep the contents of your website. Inside here should exist a public_html directory that will be what apache searches for.

tell apache this site is available by copying a skeleton file over with an appropriate new name

@mpilosov
mpilosov / gutenberg.md
Created Feb 18, 2018 — forked from mbforbes/gutenberg.md
How to scrape English Project Gutenberg and get the raw text out of it
View gutenberg.md
@mpilosov
mpilosov / readdict.py
Last active Feb 15, 2018
Read in a dictionary-based file (like a JS output) that is saved as plaintext.
View readdict.py
myfile = 'pred.js'
with open(myfile,'r') as inf:
dict_from_file = eval(inf.read())
# each entry will be a dictionary, parse them as you wish.
print('keys', dict_from_file[0].keys()) # will list available key-value pairs.
# I'm going to extract the data that I personally care about. Class labels.
# playing with these lines allowed me to find the numbers representing the class labels
print(dict_from_file[0]['predicted'][3])
@mpilosov
mpilosov / plot_nonfun.py
Last active Feb 12, 2018
plotting non-functions
View plot_nonfun.py
# something that doesn't pass the vertical line test, comes to us unordered.... we want to piecewise-interpolate.
import numpy as np
# partition our data so that each segment DOES pass the vertical line test.
c = np.where(a[:,1] >= 0.5)[0]
d = np.where(a[:,1] < 0.5)[0]
above = a[c,:] # copies of a
below = a[d,:]
@mpilosov
mpilosov / piecewise.py
Created Feb 11, 2018
piecewise function in python
View piecewise.py
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
def q1(lam):
L1 = lam[:,0] # local column-vectors.
L2 = lam[:,1]
@mpilosov
mpilosov / subplots.py
Created Feb 2, 2018 — forked from dyerrington/subplots.py
Plotting multiple figures with seaborn and matplotlib using subplots.
View subplots.py
##
# Create a figure space matrix consisting of 3 columns and 2 rows
#
# Here is a useful template to use for working with subplots.
#
##################################################################
fig, ax = plt.subplots(figsize=(10,5), ncols=3, nrows=2)
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
You can’t perform that action at this time.